Jump to content

mysql_num_rows


karimali831

Recommended Posts

Hi,

 

Got a problem.

 

For the first one, it will die if no rows.

$registered=safe_query("'");
if(!mysql_num_rows($registered)) die();
while($dd=mysql_fetch_array($registered)) {
...
}

 

For this one, it does not die if there is no rows and I'm not sure why?

When it is under fetch it does not understand or something?

 

$registered=safe_query("'");
while($dd=mysql_fetch_array($registered)) {
if(!mysql_num_rows($registered)) die();
...
}

 

I need it under for reasons.

what can I do or is there something else I can use so that it will work in the loop?

 

Thank you for help.

Link to comment
https://forums.phpfreaks.com/topic/203556-mysql_num_rows/
Share on other sites

There maybe rows and there maybe no rows, rows is checked when the user is logged in.

 

$registered=safe_query("SELECT * FROM ".PREFIX."cup_clans WHERE clanID='".$te['clanID']."' && 1on1='0' && cupID='$cupID'");

 

But as you say loop won't run if these is no rows then I can't use mysql_num_rows under it?

Link to comment
https://forums.phpfreaks.com/topic/203556-mysql_num_rows/#findComment-1066323
Share on other sites

If the loop doesn't run, then neither does any code inside the loop.  Although, in theory you could do.

 

$registered=safe_query("'");
$num = mysql_num_rows($registered);
while($dd=mysql_fetch_array($registered)) {
if($num == 0) die();
...
}

Although, I don't know why you would want to.

Link to comment
https://forums.phpfreaks.com/topic/203556-mysql_num_rows/#findComment-1066332
Share on other sites

Unrelated but always put variables like:

$te['clanID']

as:

{$te['clanID']} inside strings.

 

The reason the second doesn't die is because the while is never met.

 

if you type in:

while(false) {echo "do something";} 

the code will never execute.

 

You can't fetch from 0 rows.

Link to comment
https://forums.phpfreaks.com/topic/203556-mysql_num_rows/#findComment-1067037
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.