Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi i am using this code for searching by name and getting some errors.

<html>

 

<head>

 

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 

<title>Search Contacts</title>

 

</head>

 

<p><body>

 

<h3>Search Contacts Details</h3>

 

<p>You may search either by first or last name</p>

 

<form method="post" action="search.php?go" id="searchform">

 

<input type="text" name="name">

 

<input type="submit" name="submit" value="Search">

 

</form>

 

</body>

 

</html>

 

</p>

<style type="text/css" media="screen">

 

ul li{

 

list-style-type:none;

 

}

 

</style>

</form>

 

<p><a href="?by=A">A</a> | <a href="?by=B">B</a> | <a href="?by=K">K</a></p>

 

<?php

//end of search form script

 

if(isset($_GET['by'])){

 

$letter=$_GET['by'];

 

//connect to the database

require_once ('../mysqli_connect.php');

 

//-query the database table

 

$sql="SELECT designer_id, first_name, last_name FROM designers WHERE first_name LIKE '%" . $letter . "%' OR last_name LIKE '%" . $letter ."%'";

 

//-run the query against the mysql query function

 

$result=mysql_query($sql);

 

//-count results

 

$numrows=mysql_num_rows($result);

 

echo "<p>" .$numrows . " results found for " . $letter . "</p>";

 

//-create while loop and loop through result set

 

while($row=mysql_fetch_array($result)){

 

$first_name =$row['first_name'];

 

$last_name=$row['last_name'];

 

$designer_id=$row['designer_id'];

 

//-display the result of the array

 

echo "<ul>\n";

 

echo "<li>" . "<a href=\"search.php?id=$designer_id\">" .$first_name . " " . $last_name . "</a></li>\n";

 

echo "</ul>";

 

}

 

}

?>

 

errors:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 65

 

results found for A

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 71

 

can anyone help me plz?

Link to comment
Share on other sites

lalarukh12, you gotta stop phrasing your questions like this and start listening more to what we say.

Already, we've given you lots of advice to help, none of which you seem to be following. For example:

- Please put your code within code tags in your posts so it's easier for us to read.

- Please change your tone so it doesn't sound like you're demanding us to help you with your "very important project". Remember, we're all helping you for free here, and with no benefit to us.

- Please do things like echo various values to the screen at various points to try and debug the problem yourself.

 

Anyway, in this case, it's probably a DB connection issue, so I'd start with that.

Good luck.

Link to comment
Share on other sites

thankyou so much sir for your answer...greatly pleased !

when i run this query in mysql without $letter , it returns results and displays the data in first_name and last_name columns . and when i run this query with $letter it returns an empty set.

Link to comment
Share on other sites

 Share

×
×
  • Create New...