Help Mysql query link

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dynastym3
Forum Newbie
Posts: 13
Joined: Sun Apr 05, 2009 2:12 am

Help Mysql query link

Post by dynastym3 »

Im trying to show a list of names or data the matches my mysql query as links and when I click on the name it will show the name of the rows info.

Example
On facebook, when you search for somebodies name it queries the databases for all names that matches the name and list them as links, then when you click on one of the names (which are links) their profile info will show up.
heres my code so far but it will only show the last person info...

$query = "SELECT * FROM $usertable WHERE status = '1'";
$result = mysql_query($query) or die (mysql_error()) ;
$num = mysql_num_rows($result);

<?php echo"You have $num new entrees! <br/>";//shows # of new entrees

while($row = mysql_fetch_array($result))
{
$fname = $row['fname']; $username = $row['username']; $lname = $row['lname']; $email = $row['email']; $number = $row['number']; $street = $row['street']; $city= $row['city'];$zip = $row['zip'];$school = $row['school'];$major = $row['major'] ;

echo "<a href = 'entreeprofile.php'> $fname <br/></a>";

}

$_SESSION['fname'] = $fname;
$_SESSION['lname']= $lname;
$_SESSION['email'] = $email;
$_SESSION['number'] = $number;
$_SESSION['street']= $street;
$_SESSION['city']= $city;
$_SESSION['zip']= $zip;
$_SESSION['school']= $school;
$_SESSION['major']= $major;

///////////////////////////////////////////
mike
randy
charles

when I click on mike and randy info charles info will only show up.
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Help Mysql query link

Post by tech603 »

The problem is that you are only hyper linking the name, but you are not passing any values to the page to query the database.

Code: Select all

echo "<a href = 'entreeprofile.php'> $fname <br/></a>";
You would want to add a value such as the user name to the url query.

Code: Select all

echo "<a href = 'entreeprofile.php?firstname=" . $fname . "'> $fname <br/></a>";
Then on your page you would want to grab that value to query.

Code: Select all

 
if(isset($_GET['firstname'])){
$searchName = $_GET['firstname'];
}
 
// do your mysql query and echo the results based on the value passed to the page
 
Hope that helps
dynastym3
Forum Newbie
Posts: 13
Joined: Sun Apr 05, 2009 2:12 am

Re: Help Mysql query link

Post by dynastym3 »

Thank you so much, you really helped me out on my project...God I love the Internet & blogging!!!
tanja
Forum Commoner
Posts: 35
Joined: Fri Mar 27, 2009 4:49 am

Re: Help Mysql query link

Post by tanja »

I have the same problem! Thanks fopr sharing the information
Post Reply