The link is currently set as:
echo "<p><a href=\"getcat2.php?page=books\">";
so that it looks for the 'books' inside the swtch statement.
now ive added:
$test= $_GET['page'];
and then the switch statement you see above... and nothing happens.
The link is currently set as:
echo "<p><a href=\"getcat2.php?page=books\">";
so that it looks for the 'books' inside the swtch statement.
now ive added:
$test= $_GET['page'];
and then the switch statement you see above... and nothing happens.
Well if it looks for books it won't find it, as your case statement is looking for Books, same if you look for dvds you won't find it as your case is DVDs.
As Plasma said change your values to lowercase.
Or at least make sure they are the same case.
rincewind456 wrote:Well if it looks for books it won't find it, as your case statement is looking for Books, same if you look for dvds you won't find it as your case is DVDs.
As Plasma said change your values to lowercase.
Or at least make sure they are the same case.
Ive actually done that now, all case statements are in lower case.
I think the problem might be that ive not specified how to display the results.
The full code currently stands as:
<html>
<head>
<title>DatabaseCatList2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
//Select the product database
if (!@mysql_select_db('customerdirectory')) {
exit('<p>Unable to locate the product '.
'database server at this time.</p>');
}
switch ($_GET['page']) {
case "books":
//Select statement
$query1 = "SELECT *
FROM products
WHERE product_cat = 'books'";
$results1 = mysql_query($query1)
or die(mysql_error());
while ($row = mysql_fetch_array($results1)) {
echo "<p>$product_title";
echo "<br> $product_price";
}
break;
case "clothing":
//Select statement
$query2 = "SELECT *
FROM products
WHERE product_cat = 'clothing'";
break;
default:
//Select Statement
$query3 = "SELECT *
FROM products
WHERE product_cat = 'clothing'";
break;
}
?>[/COLOR]
</body>
</html>
Yet it doesnt diplay anything... only a blank page
Changing your code to
while ($row = mysql_fetch_array($results)) {
echo "<p><a href=\"getcat.php?prodcat=".$product_cat."\">";
echo $product_cat."</a></p><br />";
}
WOuld give you a list of hyperlinks.
Try
<html>
<head>
<title>DatabaseCatList2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
//Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
//Select the product database
if (!@mysql_select_db('customerdirectory')) {
exit('<p>Unable to locate the product '.
'database server at this time.</p>');
}
switch ($_GET['page']) {
case "books":
//Select statement
$query = "SELECT *
FROM products
WHERE product_cat = 'books'";
break;
case "clothing":
//Select statement
$query = "SELECT *
FROM products
WHERE product_cat = 'clothing'";
break;
default:
//Select Statement
$query = "SELECT *
FROM products
WHERE product_cat = 'clothing'";
break;
}
$results = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
echo "<p>$row['product_title']";
echo "<br> $row['product_price']"."</p>";
}
?>
</body>
</html>
Its STILL displaying a blank page??
Theres absoluetly nothing there.
Like i said i think the problem might actually be that i havent specified how to display the results.
Are you sure that the select statements work, is there anything in the db. and are the field names in the db product_title and product_price if so then the code I just posted should work.
It throws an error:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\wamp\www\getcat2.php on line 68
it doesnt like the line:
echo "<p>$row['product_title']";
Change
$results = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
echo "<p>$row['product_title']";
echo "<br> $row['product_price']"."</p>";
}
to
$results = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
echo "<p>".$row['product_title'];
echo "<br>". $row['product_price']."</p>";
}
The categories certainly exist and they're not empty.
ive checked and its def 'product_title' and 'product_price'
But i have no idea what that error means... never come across this particular one.
The error code was because my code was wrong the replacement code is correct. And should work.
aha!!
That seems to have worked!!
Its now listing all the books without repeatition!!
cool, thnx guys!!