» 
Query from MySQL 2 web page by using PHP
Help, I cant get all data I query from MySQL to my web page by using PHP
MySQL Database created like this.
CREATE TABLE hw ( id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, mfr varchar(20), product varchar(20), description varchar(255), price varchar(10), PRIMARY KEY (id), UNIQUE id (id));
// 1 ST Record
INSERT INTO hw VALUES (1,'Maxtor','Harddrive','20GB 5400RPM','68');
//2 ND RECORD
INSERT INTO hw VALUES (2,'Samsung','Harddrive','20GB 5400RPM','68');
//3 RD RECORD
INSERT INTO hw VALUES (3,'WesternDigital','Harddrive','20GB 5400RPM','68');
The product field is where I want to be able to embed a value in the url like this mywebsite.com/hardware.php?product=harddrives or mywebsite.com/hardware.php?product=cpus
No product name will have a space.
What I did didn’t work and need help
- First I opened my template I used to create my web page in notepad
- Second I saved the file naming it hardware.php
- Third I made a hyperlink from my harddrives image map to point to mywebsite.com/hardware.php?product=harddrives so when you click it, it places it in the url
- Fourth- he is the php code I used to get to mysql database and display the above information
<?php
$db = mysql_connect("localhost", "root", "mypassword");
$conn = mysql_select_db("hw",$db);
$result = mysql_query("SELECT * FROM hw",$db);
while ($row = mysql_fetch_array($result))
{
?>
Manufacturer: <br><? echo $row["mfr"]; ?><br>
Product: <br><? echo $row["product"]; ?><br>
Description: <br><? echo $row["description]; ?><br>
Price: <br><? echo $row['price']; ?><br><br>
<?
}
?>
What I get is a blank page. Please Help, I understand mysql but am not good with php
So I tried another way, When I use the code below, it only returns the 1 ST RECORD
<?php
$db = mysql_connect("localhost", "root", "mypassword");
mysql_select_db("hw",$db);
$result = mysql_query("SELECT * FROM hw",$db);
printf("Manufacturer: %s<br>\n", mysql_result($result,0,"mfr"));
printf("Product: %s<br>\n", mysql_result($result,0,"product"));
printf("Description: %s<br>\n", mysql_result($result,0,"description"));
printf("Price: %s<br>\n", mysql_result($result,0,"price"));
?>
Please Help, thanks in advance
|