GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Oct-2004, 08:24
Dave Gale Dave Gale is offline
New Member
 
Join Date: Aug 2004
Posts: 3
Dave Gale is on a distinguished road

Creating dynamic links on a multi column


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 Code:

<?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:

PHP Code:

?> 
<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:
PHP Code:

$data[] = $row['name']; 


Can anyone show me the way, or give some pointers? Many thanks.
  #2  
Old 01-Oct-2004, 18:37
JasonMichael's Avatar
JasonMichael JasonMichael is offline
Awaiting Email Confirmation
 
Join Date: Jul 2004
Posts: 135
JasonMichael has a spectacular aura about
I assume that when you say you want to display another page with all the fields, you meant to say all the fields of a particular record, eh?

Using what you have already, I see a pretty simple solution.

In first example of your code, make the following changes:
PHP Code:

$id=$_GET['id'];
$where = " AND 1 ";
if ($id!="") {
     $where=" AND ID='$id' ";
}
// generate and execute query 
$query = "SELECT id, name, street, description FROM clubs ORDER BY name ASC ".$where; 
$result = mysql_query($query) or die ("Error in query: $query. " . 
mysql_error()); 



Just have your URL point to the same PHP script again with the above changes.

Does this look like a reasonable solution? Otherwise, if you don't want to run the EXACT script, you could simply make another copy of the necessary code you had with my changes added, and just have your URL point to that.

I hope this helps.
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SORT / ORDER BY multi columns in MySQL misunderstood MySQL / PHP Forum 3 01-Oct-2003 09:01
Building a dynamic website help... madcat MySQL / PHP Forum 4 16-May-2003 15:21

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:39.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.