Jump to content

[SOLVED] SELECT statement


thomashw

Recommended Posts

Can someone tell me what's wrong with this? I am getting an error saying there is something wrong with the SQL syntax.

 

$result = mysql_query("SELECT * 
FROM product, product_attributes, product_options 
WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id, 
product_options.product_options_id=product_options_values_to_product_options.product_options_id, 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/85084-solved-select-statement/
Share on other sites

You should be using AND, not a comma to separate the different conditions of the WHERE clause:

 

<?php
$result = mysql_query("SELECT * FROM product, product_attributes, product_options WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id AND  
product_options.product_options_id=product_options_values_to_product_options.product_options_id AND 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());
?>

I might as well post the whole code. If you see any problems with it please let me know!

 

<?
$result = mysql_query("SELECT * 
FROM product, product_attributes, product_options 
WHERE product.product_id={$id} 
AND product_attributes.options_id=product_options.product_options_id, 
product_options.product_options_id=product_options_values_to_product_options.product_options_id, 
product_options_values_to_product_options.product_options_values_id=product_options_values.product_options_values_name") or die(mysql_error());
$count = 0;
while($name = mysql_fetch_assoc($result)) {
if(mysql_num_rows($name) > 0) {
if($count==0) {
echo "<tr>\n<td>\n<label>\n<span>";
echo $name["product_options_name"];
echo "</label></span></td>";
++$count;
}}}
echo "<tr>\n<td>";
echo "<td align=\"left\" class=\"productdrop\">";
echo "<select name=\"cat1\">";
$count = 0;
while($form = mysql_fetch_assoc($result)) {
if(mysql_num_rows($result) > 0) {
if($count==0) {
echo "<option value=\"Quantity&#58; 16\">$form[product_options_values_name]</option>";
}}}
?>

Archived

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

×
×
  • 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.