Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

php help-select


zpupster

Recommended Posts

hello,

 

trying to write a report out and display it as a php page.

 

i am getting this error--somthing is wrong with my sql statement. i do not know i am trying everthing that i know. ID Name Quantity Weight Price

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/website/public_html/testsql.php on line 31

 

 

 

 

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
// Get all the data from the tables
$result = "SELECT products.products_id AS id,
products_description.products_name AS name,
products.products_quantity AS quantity,
products.products_weight AS weight,
products.products_price AS price FROM products, WHERE products.products_id=products_description.products_id;"
or die(mysql_error());  
echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Name</th> <th>Quantity</th> <th>Weight</th> <th>Price</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['id'];
echo "</td><td>";
echo $row['name'];
echo "</td></tr>";
echo $row['quantity'];
echo "</td></tr>";
echo $row['weight'];
echo "</td></tr>";
echo $row['price'];
echo "</td></tr>";
} 



echo "</table>";
?>

 

thanks, craig

Link to comment
Share on other sites

$result = mysql_query( "SELECT products.products_id AS id, products_description.products_name AS name,

products.products_quantity AS quantity, products.products_weight AS weight, products.products_price AS price

FROM products, WHERE products.products_id=products_description.products_id;" ) or die(mysql_error());

Link to comment
Share on other sites

thanks Mr.Phil,

 

it works perfect until i put the products_description.products_name AS name, and the WHERE products.products_id=products_description.products_id;"

when i add that part i get this error.

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE products.products_id=products_description.products_id' at line 3

 

thanks,

craig

Link to comment
Share on other sites

here is the entire code:

 

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());

// Get all the data from the "example" table
$result = mysql_query( "SELECT products.products_id AS id, products_description.products_name AS name,
products.products_quantity AS quantity, products.products_weight AS weight, products.products_price AS price
FROM products, WHERE products.products_id=products_description.products_id;") or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Name</th> <th>Quantity</th> <th>Weight</th> <th>Price</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['id'];
echo "</td><td>"; 
echo $row['name'];
echo "</td><td>";
echo $row['quantity'];
echo "</td><td>";
echo $row['weight'];
echo "</td><td>";
echo $row['price'];
echo "</td></tr>";
} 

echo "</table>";
?>

Link to comment
Share on other sites

$result = "SELECT p.products_id AS id,

pd.products_name AS name,

p.products_quantity AS quantity,

p.products_weight AS weight,

p.products_price AS price FROM products p,products_description pd WHERE p.products_id=pd.products_id;"

 

would probably work better, have a look at http://www.w3schools.com/sql/sql_select.asp

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...