listing based on name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

listing based on name

Post 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();
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

are you expecting multiple people to have the same last name?
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you added a loop that calls a fetch function, you will move toward handling multiple records being returned.
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

So I shouldn't be concerned that it's not even pulling a single record?

Thanks for your help.
Post Reply