Jump to content

New: Search results


anevins

Recommended Posts

What I expect:

- The function to loop output all of the rows which match the search results.

 

The problems:

- Only 1 row is matched.

- Notice: Undefined index: id in G:\xampp\htdocs\xampp\dsa\search_func.php on line 57

- The image is not showing

 

Line 57:

$id = $_REQUEST['id'];

 

Entire Code:

<?php
/*  return the details of an employee
     parameter 
         empno - employee number
         
     eg empHTML.php?empno=7521
    This is  very basic  e.g no error checking      
*/

function search($dbc, $id) { 


if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) {

$terms = $_GET['terms'];
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server');

    $query = "SELECT * FROM stick, location, identification WHERE make LIKE '%$terms%' AND stick.sid = location.lid AND identification.stickID = stick.sid
AND identification.stickID = $id";
   
$result=mysqli_query($dbc,$query);	

   	$num_rows = mysqli_num_rows($result);

$output = Array();
   
    $image = mysqli_fetch_object($result);

if ($num_rows > 0){ 
			if($result=mysqli_query($dbc,$query)){

				$output[] = '<ul>';
				$output[] = '<li> Type: '.$image->make .'<br />Size: '.$image->size .$image->type .'<br />Colour: '.$image->colour .
				'<br /> Street Missing in: ' .$image->street.'<br />Town missing in: '.$image->town .'<br />City missing in: '.$image->city.'</li>';
				$output[] = '</ul>';

			}

return join('',$output);
}
else {
	echo "<h3>Sorry,</h3>";
	echo "<p>your search: "" .$terms. "" returned zero results</p>";
}


}
	else { 
	// Tell them to use the search form.
	echo '<p class="error">Please use the search form at the top of the window to search this site.</p>';
}
}
// connect
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

// get the id from the URL
$id = $_REQUEST['id'];

print search($dbc, $id);
print "<img src='getPhoto.php?id=$id'/>";

// close the database
mysqli_close($dbc);			

Link to comment
https://forums.phpfreaks.com/topic/231180-new-search-results/
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.