Jump to content


Photo

Multi Column Display /Link to details


  • Please log in to reply
2 replies to this topic

#1 ramblas

ramblas
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 05 May 2006 - 11:01 AM

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";
}

?>

#2 onepixel

onepixel
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 05 May 2006 - 05:10 PM

You can use the FIRST CODE to display clickable categories by replacing the line:

echo"<td>".$row1["category"]."</td>";$i++;

by

echo"<td>".
"<a href=details.php?id=" . $a_result1["category"] . ">" . $a_row1["category"] . "</a>".
"</td>"; $i++;
<a href="http://www.saheltech.com">PHP Programming - WordPress Blog Customization</a>

#3 ramblas

ramblas
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 May 2006 - 07:02 AM

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)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users