Reputation: 560
I created a table that contains Names
About
Friend
ID
, and I want to get the following
$query = mysql_query("SELECT * FROM `table` WHERE `Friend` = '$me' AND `ID` = 'Any Number'");
while($arr = mysql_fetch_array($query)){
$Names = $arr["Names"];
echo $Names;
echo "</br>";
}
So I want to select where ID equal to any number.
Upvotes: 2
Views: 1199
Reputation: 456
remove the id part from your query or you can write this
$query = mysql_query("SELECT * FROM `table` WHERE `Friend` = '$me' AND ID >0");
it can also work well in future if you want to add any condition on id you can edit it.
Upvotes: 0
Reputation: 591
Use IS NOT NULL
$query = mysql_query("SELECT * FROM `table` WHERE `Friend` = '$me' AND `ID` IS NOT NULL);
It will return any number including 0 but it will not return the ones with empty values.
I hope this helps.
Upvotes: 1
Reputation: 21
If you want to test if ID is numeric you can do something like this:
SELECT * FROM `table` WHERE `Friend` = '$me' AND `ID` REGEXP ('[0-9]')
Upvotes: 2
Reputation: 20286
If you mean Equal to any as you stated then you should remove condition
AND `ID` = 'Any Number'
Morover I would suggest to use PDO or Mysqli because mysql_* functions are depracated and will be removed in future relases.
Upvotes: 3
Reputation: 33511
Remove the ID
part:
$query = mysql_query("SELECT * FROM `table` WHERE `Friend` = '$me'");
also, don't use mysql_*
, they are deprecated. Use mysqli or PDO instead.
Upvotes: 3