Re: REPOST: DB logic help...

From: Date: Thu, 02 Aug 2001 04:00:01 +0000
Subject: Re: REPOST: DB logic help...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-60810@lists.php.net to get a copy of this message
> $conn = db_connect("fplg"); ... or die("Could not connect"); > > $bandquery = "SELECT linkid,title FROM links WHERE cat='band'"; > $sitequery = "SELECT linkid,title FROM links WHERE cat='site'"; > $miscquery = "SELECT linkid,title FROM links WHERE cat='misc'"; > > $bandresult = mysql_query($bandquery,$conn); ... or die(mysql_error()); > $siteresult = mysql_query($sitequery,$conn); ... or die(mysql_error()); > $miscresult = mysql_query($miscquery,$conn); ... or die(mysql_error()); > > header_start("FPLG:Links"); > ?> > > <table width="692" cellspacing="0" cellpadding="0"> > <tr align="center"> > <td width="230" bgcolor="#ff6600" align="center"> > <font face="verdana,arial" size="2" > color="#ffffff">Bands</font> > </td> > <td width="230" bgcolor="#ff6600" align="center"> > <font face="verdana,arial" size="2" > color="#ffffff">Sites</font> > </td> > <td width="230" bgcolor="#ff6600" align="center"> > <font face="verdana,arial" size="2" > color="#ffffff">Other</font> > </td> > </tr> > <tr align="center"> > <td width="230" bgcolor="#a9a9a9" align="center"> > <?php > while($band_data = mysql_fetch_array($bandresult)); > { > ?> > <a href="/jump.php?linkid=<?php echo > $band_data["linkid"];?>" > class="hov1" target="_new"><font size="2" > face="verdana,arial" > color="WHITE"><?php echo > $band_data["title"];?></font></a> > <br><br> > <?php > } > ?> > </td> > <td width="230" bgcolor="#a9a9a9" align="center"> > <?php > while($site_data = mysql_fetch_array($siteresult)); > { > ?> > <a href=/jump.php?linkid=<?php echo $site_data["linkid"];?>" > class="hov1" target="_new"><font size="2" > face="verdana,arial" > color="WHITE"><?php echo > $site_data["title"];?></font></a> > <br><br> > <?php > } > ?> > </td> > <td width="230" bgcolor="#a9a9a9" align="center"> > <?php > while($misc_data = mysql_fetch_array($miscresult)); > { > ?> > <a href="/jump.php?linkid=<?php echo > $misc_data["linkid"];?>" > class="hov1" target="_new"><font size="2" > face="verdana,arial" > color="WHITE"><?php echo > $misc_data["title"];?></font></a> > <br><br> > <?php > } > ?> > </td> > <td width="230" bgcolor="#a9a9a9" align="center"> > </tr> > </table> > </body> > </html> > > this is supposed to display link information from my db in three columns, > one for bands, one for sites, and one for misc. only problem is that it's > not displaying correctly, as you can see: www.fplg.net/links.php > > any ideas on what the problem is? > > chris > > ----- Original Message ----- > From: Jon Haworth <jhaworth@witanjardine.co.uk> > To: 'Chris Cocuzzo' <cuzo@mediaone.net>; <php-general@lists.php.net> > Sent: Tuesday, July 31, 2001 11:57 AM > Subject: RE: [PHP]REPOST: DB logic help... > > > > What about something like: > > > > <?php > > > > $sql_bands = "SELECT Link FROM Table WHERE Category='band'"; > > $sql_sites = "SELECT Link FROM Table WHERE Category='site'"; > > $sql_other = "SELECT Link FROM Table WHERE Category='other'"; > > > > $query_bands = mysql_query($sql_bands); > > $query_sites = mysql_query($sql_sites); > > $query_other = mysql_query($sql_other); > > > > echo "<table>"; > > echo > > "<tr><td>Bands</td><td>Sites</td><td>Other</td></tr>"; > > > > do { > > $data = false; > > echo "<tr>"; > > if ($row_bands = mysql_fetch_array($query_bands)) { > > echo "<td>". $row_bands["Link"]. "</td>"; > > $data = true; > > } else { > > echo "<td>&nbsp;</td>"; > > } > > if ($row_sites = mysql_fetch_array($query_sites)) { > > echo "<td>". $row_sites["Link"]. "</td>"; > > $data = true; > > } else { > > echo "<td>&nbsp;</td>"; > > } > > if ($row_other = mysql_fetch_array($query_other)) { > > echo "<td>". $row_other["Link"]. "</td>"; > > $data = true; > > } else { > > echo "<td>&nbsp;</td>"; > > } > > echo "</tr>"; > > } while ($data == true); > > > > echo "</table>"; > > > > ?> > > > > It's untested, and fairly inelegant in that you get an empty row at the > > bottom, so you could count the rows for each set beforehand as part of the > > SQL instead of using $data as I have - but it may be a good starting > point. > > > > HTH > > Jon > > > > > > -----Original Message----- > > From: Chris Cocuzzo [mailto:cuzo@mediaone.net] > > Sent: 31 July 2001 16:36 > > To: php-general@lists.php.net > > Subject: [PHP]REPOST: DB logic help... > > > > > > hey- > > > > I have a few pages on my website which need to be divided up into > different > > columns and rows based on a category in a table. for example, on a links > > page, I have three different columns, one for bands, one for sites, and > one > > for other things. I'm storing those things in the table with a category > > field, so that when I output the data, it goes to the right place. However > > I'm a little unsure of the actual code to do this... > > > > can someone lend me an example or give me some ideas? > > > > thanks > > chris > > > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.general (#60810) next »