anaisamy Posted April 22, 2006 Share Posted April 22, 2006 Hi, I am pretty new at PHP and need some help. I've been searching on Google for a while now and came across this site a few times in the results, but I couldn't find the exact answer I was looking for - so I decided to register and post the question directly here.Here goes: I have two tables: resourceLib and resourceLibLinksIn resourceLib, the columns are CAT, CATDESCRIPT, GENDESCRIPT and ORDERROWIn resourceLibLinks, the columns are CAT, LINK, ORDERROWWhat I want to display to the end user are results like this:[u]CATDESCRIPT for CAT1[/u][i]GENDESCRIPT for CAT1[/i]LINK1 for CAT1LINK2 for CAT1LINK3 for CAT1LINK4 for CAT1[u]CATDESCRIPT for CAT2[/u][i]GENDESCRIPT for CAT2[/i]LINK1 for CAT2LINK2 for CAT2LINK3 for CAT2LINK4 for CAT2Here is the code I have so far:[code]$query = "SELECT * FROM resourceLib INNER JOIN resourceLibLinks WHERE resourceLib.CAT=resourceLibLinks.CAT ORDER BY resourceLib.ORDERROW";$result = mysql_query($query) or die(mysql_error());[/code]And then I have this to display the results, which is obviously not working and where I need your help![code]<?while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<span class=\"headerTextUL2\">" . "{$row['CATDESC']}</span>" . "<p class=\"contentText\">" . "{$row['DESCRIPT']}<br>" . "</p>"; } ?> [/code]I think what I need to do is something like this:For each CAT If new CAT Print CAT name Else For each LINK Print LINK Next LINKNext CATBut, I'm not real sure if that is correct and if it is, I'm not sure of the syntax.I hope I've explained this well enough. I appreciate any of your help! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 22, 2006 Share Posted April 22, 2006 see [a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=91766&view=findpost&p=367515\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=367515[/a] Quote Link to comment Share on other sites More sharing options...
anaisamy Posted April 22, 2006 Author Share Posted April 22, 2006 [!--quoteo(post=367518:date=Apr 22 2006, 04:38 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 22 2006, 04:38 PM) [snapback]367518[/snapback][/div][div class=\'quotemain\'][!--quotec--]see [a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=91766&view=findpost&p=367515\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=367515[/a][/quote]Thanks for the reply.I truly am a newbie, though, and I'm having a lot of trouble with the syntax. I think I understand the pseudo code you posted, but I'm having a hard time making it work. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 22, 2006 Share Posted April 22, 2006 Something like[code]$sql = "SELECT a.catdescript, a.gendescript, b.link FROM resourceLib a INNER JOIN resourceLibLinks b ON a.cat = b.cat ORDER BY a.cadtescript, b.cat";$res = mysql_query($sql) or die (mysql_error());$lastcat = '';while (list($catdesc, $gendesc, $link) = mysql_fetch_row($res)) { if ($catdesc != lastcat) { echo "<H3>$catdesc</H3> <H4>$gendesc</H4>\n"; $lastcat = $catdesc; } echo "$link<br>\n";}[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.