News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

What is the condition for there are no results in the db?

Started by Jotade29, November 08, 2022, 06:24:51 PM

Previous topic - Next topic

Jotade29

Hi!!

My version is 2.0.19. Imagine that in the sources I have a file with a query (select name, description from files where id_member = {current_member}array...) I want to use this query in a context in a template, and I go through it with foreach

foreach ($context['query'] as $z)
here I would put the condition that if the member that queries this has no records, I get an error like: echo 'no records'... and in the else I would put all the records of that user.

What interests me is the if condition, I can think of putting 'if($z == "") or if(empty($z))... But it never shows me the echo of without records... But the else with the users who have records shows me fine. That makes me think that I am not hitting the condition so that I get that error when that user has no records. What would be the condition to put?

Thanks!!
Quote from: Diego Andrés on August 12, 2023, 02:20:18 AMI'm afraid convincing Jotade to upgrade to SMF 2.1 will require bigger effort than your work sanitizing Unicode characters  :laugh:

Kindred

well....  if you are loading SMF files/data --  the variable $context is already used and filled with specific data.  Try using a different variable name.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

live627

$request = $smcFunc['db_query']('', 'sql query here');

if ($smcFunc['db_num_rows']($request) == 0)
echo 'No results...'

Please provide your code as it will be easier for us to help you.

Advertisement: