Jump to content

Error when displaying all products which have the same brand ID


thientanchuong

Recommended Posts

I am doing the project called yoongda.com. from a page called testdetails.php, I click on brand ID to know what products relate to the brand name. However, I have a error here.

 

the layout of testdetails.php

 

cart1.jpg

 

my code for testdetails.php

 

<?php
   include'connection/connection.php';
   $pID = $_REQUEST["pID"];
   $pID = isset($_GET['pID']) ? $_GET['pID']:'';
      
      $query = 'SELECT * FROM product
            WHERE pID="'.mysql_real_escape_string($pID, $conn).'"';
      
      $result = mysql_query($query,$conn) or die (mysql_error($conn));
      
      if(mysql_num_rows($result) != 1)
      {
         header('Location: testdetails.php');
         mysql_free_result($result);
         mysql_close($conn);
         exit();
      }
      $row = mysql_fetch_assoc($result);
      extract($row);
   ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
echo'      <table width="100%" border="0">';
echo '    <tr>';
echo'       <td width="25%" rowspan="5"><img src="images/product/'.$pImage.'" alt="'.$pImage.'" height="200" width="150"/></a> </td>';
echo '       <td width="25%">Product ID:</td>';
echo '      <td width="50%"> <font face="Verdana" size="3">'.$pID.'</font></td>';
echo '     <tr>';
echo '      <td colspan="2"> <font face="Verdana" size="3"><b>'.$pName.'</b></font></td>';
echo '      </tr>';
echo '    <tr>';
echo '       <td colspan="2"> <font face="Verdana" size="2">'.$pDes.'</font></td>';
echo '      </tr>';
echo '    <tr>';
echo '       <td>Brand:</td>';
echo  '     <td> <font face="Verdana" size="3"><a href="brand.php?bID='.$bID.'">'.$bID.'</a></font></td>';
echo '    </tr>';
echo '    <tr>';
echo '      <td>Price:</td>';
echo '      <td> <font face="Verdana" size="3">£ '.$pPrice.'</font></td>';
echo '     </tr>';
echo '     </table>';
   ?>
<?php
echo '<form action="testupdateCart.php" method="post">';
echo '<table width="100%" border="0" align="center">';
echo   '<tr>';
echo  '   <td width="25%"> <input type="hidden" name="pID" value="'.$pID.'" /><label for="qty">Quantity: </label>';
echo '<input type="hidden" name="redirect" value="testdetails.php?'.'pID='.$pID.'" /> ';
$session = session_id;
$query = 'SELECT qty FROM ecomm_temp_cart
      WHERE session="'.$session.'" AND pID="'.$pID.'"';
$result = mysql_query($query,$conn) or die(mysql_error($conn));
if (mysql_num_rows($result) >0)
{
   $row = mysql_fetch_assoc($result);
   extract($row);
}else{
   $qty = 0;   
}
mysql_free_result($result);
echo '<input type="text" name="qty" id="qty" size="2" maxlength="2" value="'.$qty.'" />';
if ($qty > 0)
{
   echo ' <td style="padding-right:1px"><input type="image" id="cbi_cbmenu_5" src="menu_files/ebbtcbmenu5_0.gif" name="ebbcbmenu_5" width="103" height="26" border="0" alt="Update Quantity" value="Update Quantity" /></td>';
//   echo'<td><input type="submit" name="submit" value="Update Quantity" /></td>';
}else{
   echo '<td style="padding-right:1px"><input type="image" id="cbi_cbmenu_1" src="menu_files/ebbtcbmenu1_0.gif" name="ebbcbmenu_1" width="93" height="26" border="0" alt="Add To Basket" value="Add to Cart"/></td>';   
//   echo'<td><input type="submit" name="submit" value="Add to Cart" /></td>';
}
echo'</td>';
echo'<td><a href="product.php"><img id="cbi_cbmenu_2" src="menu_files/ebbtcbmenu2_0.gif" name="ebbcbmenu_2" width="94" height="26" border="0" alt="More Shopping" /></a> </td>';
echo  '    </tr>';
echo '   </table>';
echo '</form>';

?>
</body>
</html>

 

And the error occurs after we click on brand ID:

 

Column 'bID' in where clause is ambiguous

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/v/h/p/vhp0003/html/testbrand.php on line 37

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 '$eu, $limit' at line 3

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/v/h/p/vhp0003/html/testbrand.php on line 48

 

 

$nume=mysql_num_rows($result2); // error on line 37

 

and

 

while($noticia = mysql_fetch_array($result)) // error on line 48

 

How can I resolve this ? please help me

 

Link to comment
Share on other sites

ah sorry, I forgot to do.

this is testbrand.php code:

 

<?php
include'connection/connection.php';
$bID = $_REQUEST["bID"];
$bID = isset($_GET['bID']) ? $_GET['bID']:'';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php      

$page_name="testbrand.php"; //  If you use this code with a different page ( or file ) name then change this 
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start)){
echo "Data Error";
exit;
}


$eu = ($start - 0); 
$limit = 4;                                 // Number of records to be shown per page.
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 


/////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
$query2=' SELECT brand.bID, bName, product.pID, pName, pImage, pPrice FROM product, brand
			WHERE brand.bID = product.bID AND
			bID="'.mysql_real_escape_string($bID, $conn).'"';
$result2=mysql_query($query2);
echo mysql_error();
$nume=mysql_num_rows($result2);
/////// The variable nume above will store the total number of records in the table////
   
////////////// Now let us start executing the query with variables $eu and $limit  set at the top of the page///////////
$query=' SELECT brand.bID, bName, product.pID, pName, pImage, pPrice FROM product, brand
			WHERE brand.bID = product.bID 
				limit $eu, $limit ';
$result=mysql_query($query);
echo mysql_error();

//////////////// Now we will display the returned records in side the rows of the table/////////
while($noticia = mysql_fetch_array($result))
{
echo "<TABLE width=100% align=center  cellpadding=0 cellspacing=0> ";
echo "		<tr>";
echo '<td align=left rowspan="5"><a href="'.'details.php?pID='.$noticia[pID].'"><img src="images/product/'.$noticia[pImage].'" alt="'.$pImage.'" height="70" width="66"/></a></td>'; 
echo "           <td width =25%>ID:</td>";
echo "<td align=left > <font face='Verdana' size='2'>$noticia[pID]</font></td>";
echo "          </tr>";
echo "          <tr>";
echo "            <td width =25%>Product Name:</td>";
echo "<td align=left width =50%> <font face='Verdana' size='2'>$noticia[pName]</font></td>";
echo "         </tr>";
echo "         <tr>";
echo "           <td width =25%>Brand:</td>";
echo "<td align=left > <font face='Verdana' size='2'>$noticia[bID]</font></td>"; 
echo "         </tr>";
echo "         <tr>";
echo "           <td width =25%>Price:</td>";
echo "<td align=left > <font face='Verdana' size='2'>£$noticia[pPrice]</font></td>"; 
echo "        </tr>";
echo "         <tr>";
echo '          <td colspan="2" align="right"><a href="testdetails.php?'.'pID='.$noticia[pID].'">More Details</a></td>';
echo "           </tr>";
echo "      </table>";
}
////////////////////////////// End of displaying the table with records ////////////////////////

/////////////////////////////// 
if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging

/////////////// Start the bottom links with Prev and next link with page numbers /////////////////
echo "<table align = 'center' width='100%'><tr><td  align='left' width='30%'>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
if($back >=0) { 
print "<a href='$page_name?start=$back'><font face='Verdana' size='2'>PREV</font></a>"; 
} 
//////////////// Let us display the page links at  center. We will not display the current page as a link ///////////
echo "</td><td align=center width='30%'>";
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit){
if($i <> $eu){
echo " <a href='$page_name?start=$i'><font face='Verdana' size='2'>$l</font></a> ";
}
else { echo "<font face='Verdana' size='4' color=red>$l</font>";}        /// Current page is not displayed as link and given font color red
$l=$l+1;
}


echo "</td><td  align='right' width='30%'>";
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) { 
print "<a href='$page_name?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";} 
echo "</td></tr></table>";

}// end of if checking sufficient records are there to display bottom navigational link. 
?>
</body>
</html>

Link to comment
Share on other sites

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.