Jump to content

Displaying Content From A Second Table In Repeating Region


cdoggg94

Recommended Posts

This is a little hard to explain, but I am going to try my best.

 

I have a table that repeats a <td> for all the records in a query.

 

mysql_select_db($database_myConnect, $myConnect);
$query_Jackson = "SELECT * FROM Sheet1 WHERE pro_name LIKE  '%Jackson%' ORDER BY pro_name ASC";
$Jackson = mysql_query($query_Jackson, $myConnect) or die(mysql_error());
$row_Jackson = mysql_fetch_assoc($Jackson);
$totalRows_Jackson = mysql_num_rows($Jackson);

 

 

The table that displays it has a form to change the QTY.

 

The table code is here:

 

 <table width="770" border="0">
 <tr></tr>
 <tr>
   <th colspan="9" class="titlesList" style="background-color:#333333">Jackson</th>
 </tr>
<tr align="center">
	 <th width="60" align="left">LCBO #</th>
	  <th width="250" align="left">Product</th>
	    <th width="40">Size</th>
	    <th width="50">Btl/cs</th>
	    <th width="54">LTO</th>
	  <th width="79">Price</th>
	    <th width="103">Qty</th>
	    <th width="50">Current</th>
	    <th width="91">


	    </th>
   </tr>


<?php  do { ?>
    <form action="NewOrder.php?Details=<?php echo $detnum ;?>" id="form" name="form" method="POST">
 <tr>

   <td><?php echo $row_Jackson['lcbo_num'] ;?></td>
   <td>
   <a href="#" onclick="MyWindow=window.open('<?php echo "product5.php?Product=".$row_Jackson['pro_id']."&Client=".$detnum;?>','MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=800,height=886'); return false;"><?php echo $row_Jackson['pro_name'];?></a>
   </td>
   <td align="center"><?php echo $row_Jackson['pro_size']."mL" ;?></td>
   <td align="center"><?php echo $row_JacksonTriggs['pro_btl'] ;?></td>
   <td align="center">
   <span class="LTOlist">
 <?php
  if($row_Jackson['F7']=="LTO"){
   echo "LTO";
  }else{
   echo "";
  }
 ?>
   </span>
   </td>
   <td align="center">
<?php
if($row_Jackson['F7']=="LTO"){
echo "<span class='LTOlist'>$".number_format($row_Jackson['F10'], 2)."</span>";
}else{
 echo "$".number_format($row_Jackson['pro_price'], 2);
}
?>
   </td>

   <td align="center"><input name="qty" id="qty" type="text" size="5" /></td>
   <td align="center">
 <?php
 if($myQty['wish_case'] >= 1){
  echo $myQty['wish_case'];
 }else{
  echo "0";
 }
 ?>
   </td>
   <td align="right">
 <input type="hidden" name="date" id="date" value="<?php echo $mymessage ;?>" />
 <input type="hidden" name="product" id="product" value="<?php echo $row_Jackson['pro_name'] ;?>" />
 <input type="hidden" name="client" id="client" value="<?php echo $detnum ;?>" />
 <input type="hidden" name="id" id="id" value="" />
 <input type="hidden" name="normal" id="normal" value="<?php echo $row_Jackson['pro_price'] ;?>" />
 <input type="hidden" name="normalCase" id="normalCase" value="<?php echo "" ;?>" />
 <input type="hidden" name="LTO" id="LTO" value="<?php echo $row_Jackson['lcbo_num'] ;?>" />
 <input type="hidden" name="LTOCase" id="LTOCase" value="<?php echo $row_Jackson['pro_size'] ;?>" />
   <input name="submit" type="submit" value="Add" /></form></td>
 </tr>
 <?php } while ($row_Jackson = mysql_fetch_assoc($Jackson)); ?>
 <tr>
	 <td colspan="8" align="right"> </td>
    </tr>
 </table>

 

This is all fine.

 

My issue is that I want to display (if there is one) the QTY a person has ordered already for each <td>

 

So..

 

I have made this query:

 

$qtyinfo = mysql_query("SELECT* FROM wish_list WHERE wish_bottle_LTO=".$row_Jackson['lcbo_num']);
$myQty = mysql_fetch_array($qtyinfo);

 

wish_bottle_LTO AND $row_Jackson['lcbo_num'] both display the same product numbers.

 

when a number is entered into the form above and saved the product number from $row_jackson's table, along with the QTY entered go into the wish_ table.

 

that being said,

 

i put this in the table above to display the QTY:

 

 <?php
 if($myQty['wish_case'] >= 1){
  echo $myQty['wish_case'];
 }else{
  echo "0";
 }
 ?>

 

It DOES display content, but the problem is that its only displaying it for the first record in the Jackson query and not for each of them separate..

 

Any ideas?

 

Am I way off ?

Link to comment
Share on other sites

So basically I put this into my table:

 

<td>
 <?php



$myQTY = "SELECT*".
"FROM Sheet1, wish_list ".
"WHERE ".$row_Jackson['lcbo_num']." = wish_list.wish_bottle_LTO ORDER BY wish_bottle_LTO DESC";

$resultQTY = mysql_query($myQTY) or die(mysql_error());


while($row = mysql_fetch_array($resultQTY)){

echo $row['wish_case'];


}
 ?>
</td>

 

1) It IS printing the the correct information, but it seems to repeat over and over when I want it to display one time.

 

2) In one case right now, there is an instance where there are 2 records that have the same product number (they are the same product) but one has a QTY of 10, and the other 1. so it displays it like this:

 

101101101101101101101101101101101...etc...

 

Is there a way to add them to together AND only display it one time ?

Link to comment
Share on other sites

I tried to combine the JOIN and SUM together like this:

 

<?php

$myQTY = "SELECT SUM(wish_bottle_LTO)"." AS summed_wish_bottle_LTO "."FROM Sheet1, wish_list "." WHERE ".$row_JacksonTriggs['lcbo_num']." = wish_list.wish_bottle_LTO ORDER BY wish_bottle_LTO DESC";


$resultQTY = mysql_query($myQTY) or die(mysql_error());

while($row = mysql_fetch_array($resultQTY)){
 echo mysql_result($row['wish_case'], 0);

?>

 

First of all I don't really know if the CAN be done together.

 

Can you let me know if I am on the right track ?

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.