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
https://forums.phpfreaks.com/topic/78009-help-with-php-mysql-in-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.