Forum Moderators: coopster

Message Too Old, No Replies

Simple Problem - Dynamic Page

Easy for you, hard for me...

         

riverstyx

9:57 pm on Jul 9, 2005 (gmt 0)

10+ Year Member



I just can't get this right, and I can't find an example anywhere. Please help me out.

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

jatar_k

4:22 am on Jul 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if your directory name is the same aas the value in the db then you could use the dirname in your query to pull all results for that category

mogenshoj

10:01 am on Jul 10, 2005 (gmt 0)

10+ Year Member



If you do it like this you must create every directory yourself.

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.