Let’s say we have a web page about shopping. Since shopping is a very broad topic, within it you’d have a)clothes b)shoes c)hats, etc.
Currently, in order to retrieve shoe data, I have a file ‘shopping_shoes.php’ – ‘shopping_hats.php’ for hats, etc.
shopping_shoes.php
( “SELECT * FROM shopping WHERE [COLOR=”Red”]type=’shoes’
shopping_hats.php
( “SELECT * FROM shopping WHERE [COLOR=”Red”]type=’hats’
I really don’t want a million .php urls. Is there an easier way to retrieve this data?
Ideally, I’d like to have ‘shopping.php’ with a sub menu (clothes | shoes | hats) that re-queries within the same ‘shopping.php’ page.
Please help. TIA.
[CODE]
<?php
//Contents of shopping.php
$db="shopping";
$link = mysql_connect("#","#","#");
if (!$link)
die("Couldn't connect to MySQL");
mysql_select_db($db, $link)
or die("Couldn't open $db: ".mysql_error());
if(isset($_GET['type']))
{
$type = $_GET['type']; // hats or shoes or clothes
$result = mysql_query( "SELECT * FROM shopping WHERE type='$type' ORDER BY name" );
}
else
echo "Please select a valid product type"
while($row = mysql_fetch_assoc($result))
{
?>
LINKS
<a href="shopping.php?type=hats>hats</a>
<a href="shopping.php?type=shoes>shoes</a>
[/CODE]
[code=php]$pretype = array();
$pretype[] = 'shoes';
$pretype[] = 'hats';
$pretype[] = 'clothes';
$pretype[] = 'chocolates';
$type = $_GET['type'];[/code]
[code=php]if(!in_array($type,$pretype)){
die('Wrong Type.'); return;}[/code]
[code=php]<?php
//Contents of shopping.php
$db="shopping";
$link = mysql_connect("#","#","#");
if (!$link)
die("Couldn't connect to MySQL");
mysql_select_db($db, $link)
or die("Couldn't open $db: ".mysql_error());
$pretype = array();
$pretype[] = 'shoes';
$pretype[] = 'hats';
$pretype[] = 'clothes';
$pretype[] = 'chocolates';
if(isset($_GET['type']))
$type = $_GET['type']; // hats or shoes or clothes
if(in_array($type,$pretype))
$result = mysql_query( "SELECT * FROM shopping WHERE type='$type' ORDER BY name" );
else
die('Please select a valid product type');
while($row = mysql_fetch_assoc($result))
{
?>
<a href="shopping.php?type=hats">hats</a>
<a href="shopping.php?type=shoes">shoes</a>[/code]
0.1.9 — BETA 5.6