467,076 Members | 1,018 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,076 developers. It's quick & easy.

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


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.
Mar 22 '09 #1
  • viewed: 1658
1 Reply
Expert 4TB
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.

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT * FROM `tbl1` WHERE 1";
  2. $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'.
Mar 22 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Evan Smith | last post: by
reply views Thread by Peter Wang | last post: by
3 posts views Thread by Mike Charney | last post: by
4 posts views Thread by arnuld | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.