I have a mySQL db which has the fields id, name, street, and description in it. On my website i have a table which dynamically lists all of the "name" entries found in the db, one after the other in Ascending order across multiple columns. This acts as a menu "landing" page.
Here is the code for this:
<?php
$columns = 3;
// includes
include("config.php");
include("functions.php");
// open database connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT id, name, street, description FROM clubs ORDER BY name ASC";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$num_rows = mysql_num_rows($result);
//we are going to set a new variables called $rows
$rows = ceil($num_rows / $columns);
//to do this display, we will need to run another loop
//this loop will populate an array with all our values
while($row = mysql_fetch_array($result)) {
$data[] = $row['name'];
}
echo "<TABLE BORDER=\"0\">\n";
//here we changed the condition to $i < $rows
for($i = 0; $i < $rows; $i++) {
echo "<TR>\n";
//here will run another loop for the amount of columns
for($j = 0; $j < $columns; $j++) {
if(isset($data[$i + ($j * $rows)])) {
echo "<TD>" . $data[$i + ($j * $rows)] . "</TD>\n";
}
}
echo "</TR>\n";
}
echo "</TABLE>\n";
?>
What I would like to happen is when the user clicks on one of the names listed, it generates a new page which displays all of the fields e.g. name, description, image.
In a more simplistic code where i've just had the 1 column listing down the page the code for this was:
?>
<strong><a href="clubs.php?id=<? echo $row['id']; ?>" class="nav1"><? echo $row['name']; ?></a></strong></font>
<?
I dont know how to incorporate this into the above code. I'm sure it involves editing the code:
$data[] = $row['name'];
Can anyone show me the way, or give some pointers? Many thanks.