Help...Mysql query link

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
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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Help...Mysql query link

Post by Mark Baker »

Don't know what entreeprofile.php does, but how can it know which profile it should be showing when your link looks like:

Code: Select all

 
echo "<a href = 'entreeprofile.php'> $fname <br/></a>";
You need something to tell entreeprofile.php which profile to displaylike

Code: Select all

echo "<a href = 'entreeprofile.php?profileID=$username'> $fname <br/></a>";
dynastym3
Forum Newbie
Posts: 13
Joined: Sun Apr 05, 2009 2:12 am

Re: Help...Mysql query link

Post by dynastym3 »

entreeprofile is the link that displays the persons info basically
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Help...Mysql query link

Post by Mark Baker »

dynastym3 wrote:entreeprofile is the link that displays the persons info basically
That's my point... how does entreeprofile.php know which person to display?
dynastym3
Forum Newbie
Posts: 13
Joined: Sun Apr 05, 2009 2:12 am

Re: Help...Mysql query link

Post by dynastym3 »

The while loop in newentrees.php will store the variables into sessions that I posted here is the entreeprofile.php code...

The sessions starts and if there is no session for fname then there is no access, then it store all the sessions into variables for me to post. Thats how I think its supposed to work but I guess I am wrong or I'm missing something. :=\

session_start();

if (!isset($_SESSION['fname']))
{
die ("Access Denied");
}
?>

<?php }
$fname= $_SESSION['fname'];
$username = $_SESSION['user'];
$fname= $_SESSION['fname'];
$lname= $_SESSION['lname'];
$email = $_SESSION['email'];
$number = $_SESSION['number'];
$street =$_SESSION['street'];
$city=$_SESSION['city'] ;
$zip= $_SESSION['zip'];
$school=$_SESSION['school'];
$major= $_SESSION['major'];
Post Reply