i have a problem with my coding. when i put 'where' in my query, it does not show anything. but when i do not put 'where' it display all the records. all i want is that, it will display the records of the current user that logged in..
please help me with this.
what will be the code for these?
anyone? :(
it will be a big help. thanks..
This is my query..
$query="SE开发者_运维百科LECT * FROM members where username = '$username'";
$result=mysql_query($query);
$num=mysql_numrows($result);
whenever i put WHERE , it doesn't display anything.
Start by echoing out your $query just before the mysql_query statement, so you can check that it's what you expect. Then put some error handling in your code to identify if there's a database error being returned:
$query="SELECT * FROM members where username = '$username'";
echo $query.'<br />';
$result=mysql_query($query);
if (!$result) {
die('Error executing query: ' . mysql_errno().' '.mysql_error());
}
$num=mysql_numrows($result);
These are absolute basics that you should always be doing before asking for help.
Also, try escaping $username before using it in your query
You'd better learn how to use WHERE
correctly. You will need it in the future.
Could you please show us the query that gives all records, the first few lines from that, and the query with WHERE
that fails?
It should be something like SELECT * from users WHERE loginname="Smith"
Of course, you would need to use WHERE
on a column from the table. So, when you create the table, you should have added a loginname
column, and whenever you INSERT
a row, you should set the loginname
value. If you don't store the loginname, you can't filter on it later. It's not magically remembered.
精彩评论