melefire Posted November 20, 2007 Share Posted November 20, 2007 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! Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 20, 2007 Share Posted November 20, 2007 try replacing this: while($row = mysql_fetch_row($result)) with this: while($row = mysql_fetch_array($result)) Quote Link to comment Share on other sites More sharing options...
melefire Posted November 20, 2007 Author Share Posted November 20, 2007 causes table to be really messed up, and does not solve problem Quote Link to comment Share on other sites More sharing options...
shedokan Posted November 20, 2007 Share Posted November 20, 2007 can you show me what is your table looks like? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.