Jump to content

Recommended Posts

PHP Code:

 

	if($revision_p=="317")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='317'");
	}
	elseif($revision_p=="474")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='474'");
	}
	elseif($revision_p=="508")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='508'");
	}
	elseif($revision_p=="525")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='525'");
	}
	elseif($revision_p=="530")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='530'");
	}
	elseif($revision_p=="562")
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' WHERE `revision`='562'");
	}
	else
	{
	$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%'");
	}

	if(mysql_num_rows($search_query) > 0)
	{
		$amount = mysql_num_rows($search_query);
		echo "A total of ". $amount ." results have been found: <br/><br/>";
		while($row = mysql_fetch_assoc($search_query))
		{
			echo "<b><span style='color:red'>[". $row['revision'] ."]</span></b> Title: <b>". $row['title'] ."</b> Date: <b>". $row['date'] ."</b> <a href='view.php?id=". $row['id'] ."'><b>View</b></a><br/><br/>";
		}
	}

 

Error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a9796960/public_html/snippets.php on line 100

 

I've already checked for reserved words.

Link to comment
https://forums.phpfreaks.com/topic/208953-mysql-error/
Share on other sites

Also, why are you writing out all of that repetitious code where only the value is different and you have to write out more code to add another value? Just use an array -

$revisions = array();
$revisions[] = "317";
$revisions[] = "474";
$revisions[] = "508";
$revisions[] = "525";
$revisions[] = "530";
$revisions[] = "562";

if(in_array($revision_p,$revisions)){
$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%' AND `revision`='$revision_p'");
} else {
$search_query = mysql_query("SELECT * FROM snippets WHERE title LIKE '%$contents%'");
}

Link to comment
https://forums.phpfreaks.com/topic/208953-mysql-error/#findComment-1091427
Share on other sites

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.