Jump to content

Recommended Posts

Hi All,

 

Can someone please help me, I think i've gone mad.  On my site I run a simple query:

 

$result = mysql_query("SELECT* from tble where id = 1");

if(mysql_num_rows($result) > 0)
{
	$row = mysql_fetch_array($result);
        echo '<h1 class="fr">'.$row['name'].'</h1>
        <div style="clear:right"></div>';	
} else {
	echo '';
}

 

Now if the criteria is matches in the database I get the details returned, but if there are no reulys found I get the message:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource 

 

But surely my } else { should stop this happening?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/159674-solved-query-help-no-results-founds/
Share on other sites

You have an error in your query hence no database resource being returned. I can see it straight away:

Bad

$result = mysql_query("SELECT* from tble where id = 1");

Good

$result = mysql_query("SELECT * FROM tble WHERE id = '1'");

 

You should also catch query errors i.e.

if(!$result = mysql_query("SELECT * FROM tble WHERE id = '1'")) {
die(mysql_error());
}

Actually the space between the star and SELECT shouldn't cause a problem - or at least it doesn't on my version of MySQL (5.0.45) and being as 1 is an integer that shouldn't case a problem either - although  it could be possible with different data types.

 

Try the mysql_error() method shown and see what problems there are for you. Also is that all the code or is it possible there's a query later causing the error?

 

 

Hi All,

 

I've tidied up my query, but am still having problems:

 

	

        $query_one = "SELECT strapline from cfm_seo WHERE site_id = ".SITEID." AND section_id = ".$subSecID.""; 
        $result = mysql_query($query_one)  OR die(mysql_error()); 

        while ($row = mysql_fetch_array($result)) { 
        $strapline = $row['strapline'];

        echo '<h1 class="fr">'.$strapline.'</h1>
        <div style="clear:right"></div>';	
}

 

I get this message

 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

 

When I simply want nothing to show if it does not return any results?

 

Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.