0

I was following a tutorial and i copied word by word i don't know why i get the error.
Error >> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/download/url/search.php on line 36

<?php
		
		 $results = $_GET['results'];
		 $terms = explode(" ", $results);
		 $query = "SELECT * FROM search WHERE keywords='$term1'";
		 
		 foreach ($terms as $each) {
				$i++;
				if ($i == 1)
					$query .= "keywords LIKE '%$each%' ";
				else 
					$query .= "OR keywords LIKE '%$each%' ";
			}
			
			// connect
			mysql_connect("localhost", "irnm_tutadmin", "731995");
			mysql_select_db("irnm_tutorials");
			
			$query = mysql_query($query);
			$numrows = mysql_num_rows($query);
			if ($numrows > 0) {
			
				while ($row = mysql_fetch_assoc($query)){
					$id = $row['id'];
					$title = $row['title'];
					$description = $row['description'];
					$keywords = $row['keywords'];
					$link = $row['link'];
					
					echo "<h2><a href='$link'>$title</a></h2>
					$description<br /><br />";
				}
			}
			else
				echo "No results found for \"<b>$results</b>\"";
			
			
			// disconnect
			mysql_close();
	
	?>
5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by dhruv_arora
0

Replace your line no 5

$query = "SELECT * FROM search WHERE keywords='$term1'";

with

$query = "SELECT * FROM search WHERE ";
0

You're putting the result in $query on line 19, which is a bit strange to me. It shouldn't break things, but it's more clear if you rename that variable to $result.

0

Also always try to habit of mysql_error so once there is something wrong with query your code wont execute further.

$rs=mysql_query($sql) or die( '<br /><strong>Your Query: </strong>'.$sql.'<br /><br /><strong>Error: </strong>'.mysql_error());
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.