two tables one problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

two tables one problem.

Post 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']; ?>
 
Attachments
help.jpg
help.jpg (198.24 KiB) Viewed 342 times
Last edited by Benjamin on Tue May 19, 2009 2:12 pm, edited 1 time in total.
Reason: Changed code type from text to php.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: two tables one problem.

Post by divito »

First thing I notice is that you're missing your opening and closing curly brackets for your while loops.
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

Re: two tables one problem.

Post 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 ?>
Last edited by Benjamin on Tue May 19, 2009 2:13 pm, edited 1 time in total.
Reason: Changed code type from text to php.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: two tables one problem.

Post 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.
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

Re: two tables one problem.

Post by randall »

Thx, figured it out with your help.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: two tables one problem.

Post by Benjamin »

randall, Please use

Code: Select all

tags when posting code.  Also, please do not use abbreviations such as plz and ty.
randall
Forum Newbie
Posts: 16
Joined: Fri May 08, 2009 9:01 pm

Re: two tables one problem.

Post by randall »

Noted, thank you.
Post Reply