AFB
AFB

Reputation: 560

How to select from table where query equal to any number

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

Answers (5)

Php developer
Php developer

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

Nes
Nes

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

user2590834
user2590834

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

Robert
Robert

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

Bart Friederichs
Bart Friederichs

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

Related Questions