not able to compare & fetch data from table using where clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahullko05
    New Member
    • Oct 2008
    • 34

    not able to compare & fetch data from table using where clause

    Hi,

    i am building a small forum site as my final year project & stuck in a very trivial problem.

    I have a table which are varchar type of data & i am trying to fetch data from table based on some condition.

    $query = 'select reply_Id, post_Id, replied_by, reply, date_of_reply from reply_info where reply_info.post _Id ='. $x;

    as $x='pi_1';

    here $x has string value & post_Id in table has varchar value & has the same value (for that column in table) as given to $x, but still this query execution is failing. it returns false for result.

    Now if i dont give any where clause query fetches all the rows of table. I tried this to confirm if connection to data base is working fine.

    this is really urgent..i have already wasted an hour in this :-(

    thanks in advance.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    There's nothing that sticks out at me, other than that IDs are generally stored as integers. Are you positive it's a VARCHAR?

    When you're developing something, you should be debugging it. So, use mysql_error() if a query fails, to see why it failed.

    Code:
    $query = "SELECT * FROM `tbl1` WHERE 1";
    $query_result = mysql_query( $query ) or die ( mysql_error() );
    As soon as the query is stored in $query_result, if there's an error, your page will die with the cause of the error displayed, e.g. 'tbl1 doesn't exist'.

    Comment

    Working...