Avatar of Ricky Nguyen
Ricky NguyenFlag for Australia

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:

<?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>

Open in new window


I'm trying to get my code to display the following.

Product Code  |  Name   |   Price
HT400DVA         Bike           $50

Thanks in advance,

Rick
PHP

Avatar of undefined
Last Comment
Ricky Nguyen
Avatar of Francisco Igor
Francisco Igor
Flag of Canada image

Do you want a structured table or simple lines?
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 />";
  }
you code seams ok, what error do you get?
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ricky Nguyen
Ricky Nguyen
Flag of Australia image

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.
You have $conn instead of $con in your mysql_close. Don't give me points for this.
Avatar of Ricky Nguyen
Ricky Nguyen
Flag of Australia image

ASKER

Thanks for the help and Thanks for the correction :)
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo