jack jack - 2 months ago 9
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

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...
   }