Forum Moderators: coopster
I have widgets.html which lists all the main categories of widgets:
------------
<html>
<head>
<title>Widgets</title>
</head>
<body>
<h1>Widget Categories:</h1>
<?php
include( "includes/config.inc.php" );
$conn = mysql_connect("localhost", $db_user, $db_pass )
or die ("Could not connect");
$rs = mysql_select_db("products_db", $conn)
or die ("Could not select database");
$sql = 'SELECT * FROM widget_table ORDER BY main_category LIMIT 0, 100'
or die( "Could not select from table");
$rs = mysql_query($sql, $conn);
while( $row = mysql_fetch_array($rs)) {
echo( "<p><a href=\" " . $_SERVER['PHP_SELF'] . "\"> . $row["main_category"] . "</a></p>\n");
}
}
mysql_close($conn);
?>
</body>
</html>
----------------------------------
This gives us:
<p><a href="/Blue_Widgets/">Blue Widgets</a></p>
<p><a href="/Red_Widgets/">Red Widgets</a></p>
<p><a href="/Green_Widgets/">Green Widgets</a></p>
which is all good. But when I click on Blue Widgets I want to query the database to select all where main_category = Blue Widgets and echo out the results by name, description and image on the same page. Do I need to create a separate template? Do I need to use a 'get' function of some kind? This is supposed to be the easiest thing but I'm stuck on it. Any help appreciated.
RS
If you did this you can put this in your index file in every directory:
$main_category = $_SERVER[PHP_SELF];
$main_category = str_replace("/","",$main_category);
$main_category = str_replace("_"," ",$main_category);
// some sql things here
$sql = 'SELECT * FROM widget_table where main_category='$main_category'
// the rest of the sql here
----
Not tested, put i think it would work.