1
$getPrd = mysql_query("SELECT * FROM products
LEFT OUTER JOIN productscontent ON productscontent.productsID = products.id
WHERE productscontent.title LIKE '%".$search."%' OR productscontent.alltext LIKE '%".$search."%'
ORDER BY products.sortnr");

$num = mysql_num_rows($getPrd);

And the $getPrd returns values as needed, but the $num returns 0 - why is that?

Xeen
  • 6,955
  • 16
  • 60
  • 111
  • According to the PHP documentation, `mysql_num_rows` is deprecated as of PHP 5.5.0 and `mysqli_num_rows` should be used instead. – Tim Biegeleisen Mar 15 '15 at 13:58
  • @TimBiegeleisen Yes, but this is for an old project and it has 5.3 – Xeen Mar 15 '15 at 13:59
  • does your query return results? what do you mean by SQL returns normal values? you've to be more specific – Nishanth Matha Mar 15 '15 at 14:00
  • mysqli should be used for both the query and the information function. Just because they only deprecated it in 5.5 does not mean that you do not use mysqli in earleir version. Indeed they had a notice to that effect in the manual since 2007. – David Soussan Mar 15 '15 at 14:01
  • @NishanthMatha yes, my query returns results. That's what I ment by normal values. – Xeen Mar 15 '15 at 14:03
  • 2
    @DavidSoussan that's not really important right now, i have the same source elsewhere and it works so I really need advice that could actually help fix the issue. Thanks! – Xeen Mar 15 '15 at 14:03
  • Can you verify that your connection isn't being closed right after the query is finished? This might explain why you are getting results but no row count. Can you explicitly give a connection parameter which you know will be valid before and after the query? – Tim Biegeleisen Mar 15 '15 at 14:07
  • @TimBiegeleisen Not really sure how to do what you're suggesting, can you please be more specific with this part: "Can you explicitly give a connection parameter which you know will be valid before and after the query?" ? – Xeen Mar 15 '15 at 14:18
  • This will render as an INNER JOIN – Strawberry Mar 15 '15 at 14:23
  • @Xeen, so how many rows do you actually get when you fetch them? Fetch them and count them please. – David Soussan Mar 15 '15 at 14:44
  • I was just thinking that the DB connection was getting closed before you could get a row count. Also please try using `mysql_i` as David Soussan mentioned. The code you are using has been deprecated and there may be bugs. – Tim Biegeleisen Mar 15 '15 at 14:44
  • @DavidSoussan since it's a search mechanism, the number of rows is dynamic, but example would be I get `7` rows and the `mysql_num_rows` returns `0` – Xeen Mar 15 '15 at 14:45
  • try passing `$database` as first parameter in query! $getPrd = `mysql_query($database,"SELECT * FROM products LEFT...");` where $database is connection to your database like `$database = mysqli_connect("localhost", "your_user", "your_password", "world");` – Nishanth Matha Mar 15 '15 at 15:21
  • What happens if you change `LIKE '%".$search."%'` to `LIKE '%$search%'`? – Michael Doye Mar 15 '15 at 16:21
  • @MichaelDoye then the whole thing stops working :) – Xeen Mar 15 '15 at 17:33

0 Answers0