Jump to content

Recommended Posts

I have created a database called '[b]products[/b]'.

A guide adviced to use following script:
[code]INSERT INTO products VALUES(001,"Milk",4.00);
INSERT INTO products VALUES(002,"Chili",5.00);
INSERT INTO products VALUES(003,"Orange",10.00);[/code]

I typed the products ([i]product code, product and price[/i]) using [b]phpAdmin[/b] which my webhost offers.

Then the guide advices me to create producttest.php and add following script into, to print out the info:
[code]<html>
<head>
<title>product test</title>
</head>
<body>

<?php

mysql_connect("localhost","login","password");

mysql_selectdb("shop");

$query = "SELECT code,name,price FROM products ORDER BY code";

$result = mysql_query($query);

?>
<table cellspacing=0 cellpadding=4 border=1>
<tr>
<th>product code</th>
<th>name </th>
<th>price</th>
</tr>
<?
for($count = 0; $count < mysql_numrows($result); $count++) {
?><tr>
<td><?echo mysql_result($result,$count,"code")?></td>
<td><?echo mysql_result($result,$count,"name")?></td>
<td><?echo mysql_result($result,$count,"price")?> USD</td>
</tr>
<?
}
?>
</table>
<?

mysql_close();

?>

</body>
</html>

[/code]

[code]mysql_connect("localhost","login","password");[/code]
I have changed "login" and "password" to my own login and pass. No effect. Then I changed janhost.com as my 'localhost'. No effect.

The results should look like this:
[a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img288.imageshack.us/img288/8918/products6jc.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]
but i'm seeing this:
[a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img74.imageshack.us/img74/973/products29os.jpg\" border=\"0\" alt=\"IPB Image\" /][/a]

Please help me if you can. i've been dealing with this for 3 days...
i've also tried other php codes which should print some info out of MySQL... i can not get them working. Any help will be greatly appreciated!
Change the below code:
[code]<?
for($count = 0; $count < mysql_numrows($result); $count++) {
?><tr>
<td><?echo mysql_result($result,$count,"code")?></td>
<td><?echo mysql_result($result,$count,"name")?></td>
<td><?echo mysql_result($result,$count,"price")?> USD</td>
</tr>
<?
}
?>[/code]
To the following:
[code]<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['code']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>$<?php echo $row['price']; ?> USD</td>
</tr>
<?php } ?>[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.