»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 10-21-2003, 08:42 PM   #1 (permalink)
Registered User
 
Join Date: Oct 2003
Posts: 4
laowensjr is on a distinguished road
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

laowensjr is offline   Reply With Quote
Old 10-22-2003, 06:52 AM   #2 (permalink)
Registered User
 
drizzle's Avatar
 
Join Date: Oct 2001
Location: Louisiana, USA
Posts: 170
drizzle is on a distinguished road
Send a message via ICQ to drizzle Send a message via Yahoo to drizzle
Assuming it was being called with hardware.php?product=xxxxx

See if this does anything for you.

PHP Code:
<?php

$dbconn 
= @mysql_connect('localhost','root','mypassword');

if (!
$dbconn){
     die(
'Unable to connect to the database server.');
}

if (!@
mysql_select_db('hw')){
     die(
'Unable to locate the database.');
}

$result mysql_query("SELECT * FROM hw WHERE product = $_GET[$product]");

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

?>
drizzle is offline   Reply With Quote
Old 10-22-2003, 07:55 AM   #3 (permalink)
Registered User
 
Praetorian's Avatar
 
Join Date: Oct 2001
Location: Yuma, AZ
Posts: 2,484
Praetorian is on a distinguished road
Send a message via ICQ to Praetorian Send a message via AIM to Praetorian Send a message via Yahoo to Praetorian
Create table like this:
PHP Code:
CREATE TABLE hw(id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEYmfr VARCHAR(20), product VARCHAR(20), description LONGTEXTprice VARCHAR(10)); 
Add records like this:
PHP Code:
INSERT INTO hw(mfrproductdescriptionpriceVALUES ('Maxtor','Harddrive','20GB 5400RPM','68'); 
Create query like this:
PHP Code:
<?
$db 
mysql_connect("localhost""root""mypassword");
mysql_select_db("hw",$db);

$result mysql_query("SELECT * FROM hw",$db);
while (
$row mysql_fetch_array($result)){ 
?> 
Manufacturer: <br><?=$row['mfr']?><br> 
Product: <br><?=$row['product']?><br> 
Description: <br><?=$row['description']?><br> 
Price: <br><?=$row['price']?><br><br> 
<? 

?>
Have fun with that....

Last edited by Praetorian; 10-22-2003 at 07:58 AM.
Praetorian is offline   Reply With Quote
Old 10-22-2003, 07:56 PM   #4 (permalink)
Registered User
 
Join Date: Oct 2003
Posts: 4
laowensjr is on a distinguished road
Thanks A Bunch You Guys

Thanks A Bunch you guys, I think I have found me a new home
Moderators can close this discussion
laowensjr is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 01:09 AM.