Jump to content

Help with PHP + MySQL in table


melefire

Recommended Posts

ok i have a table that displays the content of a mysql table but i want to have each row in the table dynamically link to a page: listandconfirm.php?id=[the id of the row]

i can get it to link, but it only links to the first one. here is my code:

<?php
###################################
# File: index.php                 #
# Project: List Confirm System    #
# By: MeleFire                    #
# Copyright 2007                  #
###################################
// Call Global Config File
include("config.php");
//Call header file
include 'header.php';
//Set some more vars
$table='event';
//Now Display the campout list
mysql_connect($dbloc, $dbuser, $dbpass);
@mysql_select_db($dbname) or die("Can't select database");

// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);
$url=mysql_result($result,$i,"ID"); 

echo "<center><h1>List Of Campouts</h1>";
echo "<table border='3'><tr>";
// printing table headers
$result2 = mysql_query("SELECT * FROM {$table}");
$url=mysql_result($result,$i,"ID"); 
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result2);
    echo "<td><b>{$field->name}</b></td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";

    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td><a href=listandconfirm.php?id=$url>$cell</a></td>";

    echo "</tr>\n</center>";
}
mysql_free_result($result);
//Call Page Footer
include 'footer.php';
?>

thanks!

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.