Page 1 of 1

two tables one problem.

Posted: Tue May 19, 2009 11:02 am
by randall
I am trying to pull the title and description from a table called items using the productID from two tables as the number to match... my code sucks and am battling with it.. anyone able to help?


Please see the attachment, "help.jpg"

Code: Select all

 
<?php
$p_code = ($_GET['pro_code']); 
$sub = ($_GET['subcat']); 
$sql_subcat = mysql_query("SELECT * FROM a_multicat where categoryID =($sub) order by productID ");
 
while ($data = mysql_fetch_array($sql_subcat))
$product = $data['productID'];
echo "$product";
$sql_subcat_txt = mysql_query("SELECT * FROM items where productID =($product) order by productID ");
while ($data2 = mysql_fetch_array($sql_subcat_txt))
{ $pro_text = $data2['itemDesc']; ?>
 

Re: two tables one problem.

Posted: Tue May 19, 2009 11:22 am
by divito
First thing I notice is that you're missing your opening and closing curly brackets for your while loops.

Re: two tables one problem.

Posted: Tue May 19, 2009 11:39 am
by randall
I left that out because it seemed a bit too long to post... here is the entire thing. A bit messy I know...

Code: Select all

<?php
$p_code = ($_GET['pro_code']); 
$sub = ($_GET['subcat']); 
$sql_subcat = mysql_query("SELECT * FROM a_multicat where categoryID =($sub) order by productID ");
 
while ($data = mysql_fetch_array($sql_subcat))
$product = $data['productID'];
echo "$product";
$sql_subcat_txt = mysql_query("SELECT * FROM items where productID =($product) order by productID ");
$pro_text = $data2['itemDesc']; 
while ($data2 = mysql_fetch_array($sql_subcat_txt))
 
{ 
echo "$pro_text";
?>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                  <tr>
<td width="27%"></td> 
                                                  <td width="2%"></td>
<td width="71%"></td>
</tr>
                                                  <tr>
<td align="left" valign="top"><a href="details.php?pro_code=<?=$data["productID"]?>"><img src="store/productimages/small/<?=$data["productID"]?>.jpg" border="0" /></a>
<br>
<a href="store/productimages/large/<?=$data["productID"]?>.jpg" target="_blank"><font color="#FF0000" size="2"><b>
<center>Enlarge Image</center></b></font></a>
 
</td> 
<td align="left" valign="top">&nbsp;</td>
<td align="left" valign="top"><?=$pro_text["itemDesc"]?> <a href="details.php?pro_code=<?=$data["productID"]?>"><font color="#FF0000" size="2"><b>More Information</b></font></a></td>
</tr>
                                                  <tr>
<td></td> 
                                                    <td></td>
<td></td>
                                                  </tr>
                                                  <tr>
<td></td> 
                                                    <td></td>
<td></td>
                                                  </tr>
                                                  
                                                  <tr align="right">
<td></td> 
                                                    <td></td>
<td> </td>
                                                  </tr>
                                                  <tr>
<td></td> 
                                                    <td></td>
<td></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
                                                  <tr>
<td align="right"></td> 
                                                    <td align="right"></td>
<td align="right"></td>
                                                  </tr>
</table>
<p>
<?
}
?>
</p>
<p><br />
</p></td>
                                        </tr>
                                            <tr> 
                                              <td colspan="2">&nbsp;</td>
                                            </tr>
                                      </table></td>
                                      </tr>
                                    </table>
                                    <?php end ?>

Re: two tables one problem.

Posted: Tue May 19, 2009 11:47 am
by divito
I still don't see the curly brackets for the first while.

Code: Select all

while ($data = mysql_fetch_array($sql_subcat))
$product = $data['productID'];
echo "$product";
Should be (spaced to be noticeable):

Code: Select all

while ($data = mysql_fetch_array($sql_subcat)) 
{
$product = $data['productID'];
echo "$product";
}
Unless you're doing a while inside of a while, but I'm not sure how MySQL can handle it as I've never attempted it. And you'd still be missing the curly brackets over the entire initial while.

Re: two tables one problem.

Posted: Tue May 19, 2009 12:53 pm
by randall
Thx, figured it out with your help.

Re: two tables one problem.

Posted: Tue May 19, 2009 2:13 pm
by Benjamin
randall, Please use

Code: Select all

tags when posting code.  Also, please do not use abbreviations such as plz and ty.

Re: two tables one problem.

Posted: Tue May 19, 2009 2:29 pm
by randall
Noted, thank you.