Ricky Nguyen
asked on
PHP - select - where statement
HI experts,
I'm having troubles getting my code to select a specific piece of information.
Here is my code:
I'm trying to get my code to display the following.
Product Code | Name | Price
HT400DVA Bike $50
Thanks in advance,
Rick
I'm having troubles getting my code to select a specific piece of information.
Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test 1</title>
</head>
<?php
$con = mysql_connect("localhost","warehouse21","tld3");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("warehouse", $con);
$result = mysql_query("SELECT * FROM product
WHERE productCode='HT400DVA'");
while($row = mysql_fetch_array($result))
{
<?php echo $row['productCode'];?>
<?php echo $row['name'];?>
<?php echo $row['price'];?>
"<br />";
}
?>
<?php }
mysql_close($conn); ?>
</table></body></html>
I'm trying to get my code to display the following.
Product Code | Name | Price
HT400DVA Bike $50
Thanks in advance,
Rick
you code seams ok, what error do you get?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the fast replies!
@Zyloch
I tried your code and its brought me one step closer I'm getting the following error:
PHP Notice: Undefined variable: conn on line 35 PHP Warning: mysql_close() expects parameter 1 to be resource, null given on line 35
The product code, name and price are showing up now, but that error shows up with them.
@Zyloch
I tried your code and its brought me one step closer I'm getting the following error:
PHP Notice: Undefined variable: conn on line 35 PHP Warning: mysql_close() expects parameter 1 to be resource, null given on line 35
The product code, name and price are showing up now, but that error shows up with them.
You have $conn instead of $con in your mysql_close. Don't give me points for this.
ASKER
Thanks for the help and Thanks for the correction :)
First, you are trying to put some php tags within another php code...
//the title line
echo "Product Code | Name | Price";
echo "<br />";
//the data lines
while($row = mysql_fetch_array($result)
{
echo $row['productCode'];
echo "|";
echo $row['name'];
echo "|";
echo $row['price'];
echo "<br />";
}