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
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Wed Apr 12, 2006 9:39 am
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();
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 12, 2006 9:45 am
are you expecting multiple people to have the same last name?
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Wed Apr 12, 2006 9:51 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 12, 2006 9:55 am
If you added a loop that calls a fetch function, you will move toward handling multiple records being returned.
psurrena
Forum Contributor
Posts: 355 Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY
Post
by psurrena » Wed Apr 12, 2006 9:59 am
So I shouldn't be concerned that it's not even pulling a single record?
Thanks for your help.