Page 1 of 1

listing based on name

Posted: Wed Apr 12, 2006 9:39 am
by psurrena
My question is, I want to display results that are attributed to someones last name. The code below works great when "lname" is replaced with "id" but I'm not looking for results for a single record but multiple.


This is the link from the homepage:

Code: Select all

<a href="comp.php?name=$lname">$company</a>

This is part of comp.php. $fname is just there just to keep it simple and see if anything is pulling.

Code: Select all

<?php	
		mysql_connect ('server', 'name', 'pass') or die ('Error connecting to mysql');
		mysql_select_db (datebase);
		
			$lname = $_GET['lname'];
					
			$query   = "SELECT * FROM job WHERE lname='$lname'";
			$result  = mysql_query($query) or die('Error : ' . mysql_error());  
			$row     = mysql_fetch_array($result, MYSQL_ASSOC); 
			
			if (mysql_errno() != 0) {
				echo 'Error: ' . mysql_error() . '<br/>';
			}

			$fname   = $row['fname'];
			
			echo $fname;
			
			mysql_close();
?>

Posted: Wed Apr 12, 2006 9:45 am
by feyd
are you expecting multiple people to have the same last name?

Posted: Wed Apr 12, 2006 9:51 am
by psurrena
No and the reason I'm using last name for the time being is because there are no spaces, periods or dashes, just one word.

Posted: Wed Apr 12, 2006 9:55 am
by feyd
If you added a loop that calls a fetch function, you will move toward handling multiple records being returned.

Posted: Wed Apr 12, 2006 9:59 am
by psurrena
So I shouldn't be concerned that it's not even pulling a single record?

Thanks for your help.