jack jack - 1 year ago 95
MySQL Question

PHP and Mysql || 'or' syntax?

In mysql I have something like:

$currentname = mysql_query("SELECT * FROM posts LIMIT $start, 5 WHERE ");

How can i do something like this below that works:

$currentname = mysql_query("SELECT * FROM posts LIMIT $start, 5 WHERE `title` LIKE '%{Hello world}%' || Where `text` LIKE '%{Hello World}%'");

Something like above that will actually work.

Answer Source

Try this:

$queryResult = mysql_query("SELECT * FROM posts WHERE `title` LIKE '%{Hello world}%' OR `text` LIKE '%{Hello World}% LIMIT $start, 5'");
$currentName = mysql_fetch_assoc($queryResult);

if you expect many results...

   while($currentName = mysql_fetch_assoc($queryResult)) {
     //your code here...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download