Jump to content

Dynamic Linking


sparz14

Recommended Posts

Hello,

 

Im a PHP newbie and im trying to create an application in my spare time.  I'm having trouble finding info on this which probably has a very easy fix!

 

Ok so i have a MySQL database with a bunch of tables in it. One table is called "driver".  It contains the information of all people who drive a collection of Taxi's.  In this instance im trying to display a list of all the names drivers and when someone clicks on them, it will display more detailed information of the driver including contact details, etc.

 

I have gotten all of the driver's names to appear using a While loop.  I'm just having trouble understanding how i can link these properly.

 

On the page with the drivers names im displaying "fname" "mname" "lname".  I would like to link them using "da"  (unique numbers for each driver).  I have a file named "checkuser.php"which displays the list of drivers. I want the individual driver details in "userdetails.php".

 

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

When you create your while loop,  have it output as a form within the loopand include a hidden input field of the drivers id (da)  once the user clicks on this, run a seperate sql query to return the driver details.

 

<?php

//has driver been selected from form?
if(isset($_POST['submit'])){
// get details for selected driver
$sql="SELECT * FROM driver  WHERE id=" . $_POST['id'];
$sql=mysql_query($sql);
$row=mysql_fetch_array($sql);

//echo all details.................
}


//get info for all drivers
$sql="SELECT * FROM driver";
$sql=mysql_query($sql);

//start form
echo'<form method="POST" action="">';

while($driver=mysql_fetch_array($sql)){

//populate each line with hidden id field
echo $driver['fname'] . " " . $driver['mname'] . " " . $driver['lname'] . '<input type="hidden" name="id" value="'$driver['id'] .'"><input type="submit" name="submit" value="Get Details">';
}

//end form
</form> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.