SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Feb 28, 2003, 07:58 #1
Help I'm new and stuck with php and mysql
Hi Guys, I've set up two tables in mySql (example nametbl and addtbl).
I have a frontpage.php which lists all the details of the nametbl as <a href>links which I want to load into a new page with all details when a user clicks the link.
The problem I have is want to load only that link (i.e
nametbl
Scott
Jane
Bob
if user clicks on 'scott' then I want to load a new page with different formats with :
nametbl addtbl
Scott my address details
I getting trouble finding out to get the php to take the id of the name and pass it to the new page then load that specific id row only.
can anyone help me.!!!!!! PLEASE!!!!!!
white_spider77
-
Feb 28, 2003, 08:10 #2
- Join Date
- Jun 2001
- Location
- Adelaide, Australia
- Posts
- 6,441
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
if you send them to another page, say "details.php"
You just need to add a query string to it, so it would become "details.php?userid=<?=$userid?>" when you print the link to the details.php page...
Inside the details.php page, use "$userid = $_GET['userid'];" and in your mySQL query add "WHERE userid=$userid"
If you're still having problems post your code
-
Feb 28, 2003, 08:17 #3
- Join Date
- Oct 2001
- Posts
- 2,686
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
Just to give you some code to start with (that coincide with what platinum posted).PHP Code:// PAGE 1
// LISTING ALL THE NAMES
$conn = mysql_connect('server', 'user', 'password') or die(mysql_error);
$db = mysql_select_db('databasename', $conn);
$sql = "SELECT nameid, name FROM nametbl";
$result = mysql_query($sql, $db) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$nameid = $row['nameid'];
$name = $row['name'];
echo "<a href=""\"details.php?nameid=$nameid\">$name</a><br>\n";
}
// PAGE 2
// LISTING ALL INFO ABOUT THE SELECTED NAME
$conn = mysql_connect('server', 'user', 'password') or die(mysql_error);
$db = mysql_select_db('databasename', $conn);
$sql = "SELECT id, address, email FROM addtbl WHERE id=" . $_GET['nameid'];
$result = mysql_query($sql, $db) or die(mysql_error());
$row = mysql_fetch_array($result)
echo 'id: ' . $row['id'] . "<br>\n";
echo 'Address: ' . $row['Address'] . "<br>\n";
echo 'Email: ' . $row['Email'] . "<br>\n";
Hope this gives you a start.
-Helge
-
Feb 28, 2003, 09:09 #4
Cheers guys.
I'll let you know on the results.
white_spider77
Bookmarks