Jump to content

Recommended Posts

Hi
I have been trying to set up a Multi Column display following the Tutorial but would like the displayed results linked to another Detail Page (similar to a Yahoo Style Category List (with Sub Cats if possible)
The Code below works fine displaying my Categories in 3 Columns and I found another script somewhere else which also does that and hyperlinks the Results but the Layout is not as nice.Been trying to combine the 2 Codes to get the desired Result but no luck.
START OF FIRST CODE (works fine but not linked to Details Page which I would Like)
Second Code which links is below
My Question is therefor :
How can the below code be modifed so that the displayed Results can be clicked on?

<?php

// set your infomation.
$dbhost='localhost';
$dbusername='****';
$dbuserpass='****';
$dbname='*****';

// connect to the mysql database server.
$link_id = mysql_connect ($dbhost, $dbusername, $dbuserpass);

// select the specific database name we want to access.
$dbname=$dbusername."_".$dbname;
if (!mysql_select_db($dbname)) die(mysql_error());

?>
<?
$query1="select * from category ";
$result1=mysql_query($query1);
$total1=mysql_num_rows($result1);
if($total1)
{
echo"<table width=800 cellpadding=2
cellspacing=2 border=1 bordercolor=1>";
$i=0;
while($row1=mysql_fetch_array($result1))
//{echo "<a href=details.php?id=" . $a_result1["category"] . ">" . $a_row1["category"] . "</a><br>\n";
//}

{
if($i%3==0)
echo"<tr>";
echo"<td>".$row1["category"]."</td>";$i++;
if($i%3==0)


echo"</tr>";
}

{
}

echo"</table>";
}
?>


START OF SECOND CODE (Works with Clicks but layout is not what I need)
<?php
//This is a working script
//Make sure to go through it and edit database table filelds that you are seraching
//This script assumes you are searching 3 fields
$hostname_logon = "localhost" ;
$database_logon = "*****" ;
$username_logon = "******" ;
$password_logon = "*****l" ;
//open database connection
$connections = mysql_connect($hostname_logon, $username_logon, $password_logon) or die ( "Unabale to connect to the database" );
//select database
mysql_select_db($database_logon) or die ( "Unable to select database!" );


$query = mysql_query("SELECT * FROM category");

while ($a_row=mysql_fetch_array($query)) {
echo "<a href=details.php?id=" . $a_row["cat_id"] . ">" . $a_row["category"] . "</a><br>\n";
}

?>
Link to comment
https://forums.phpfreaks.com/topic/9122-multi-column-display-link-to-details/
Share on other sites

HI
Thanks so much for the Answer Works very well
Complete Code (as i use it) below in case somebody else has the same Query
<?
$query1="select * from category ";
$result1=mysql_query($query1);
$total1=mysql_num_rows($result1);
if($total1)
{
echo"<table width=100% cellpadding=0
cellspacing=2 border=1 bordercolor=1>";
$i=0;
while($row1=mysql_fetch_array($result1))

{
if($i%3==0)
echo"<tr>";
echo"<td>".
"<a href=details.php?id=" . $row1["cat_id"] . ">" . $row1["category"] . "</a>".
"</td>"; $i++;
if($i%3==0)


echo"</tr>";
}

{
}

echo"</table>";
}
?>

This will show Categories from Mysql Table in a 3 Column Table

With Kind Regards
Manfred (South Africa)
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.