Jump to content

Splitting Results


unplugged_web

Recommended Posts

I'm trying to split database results up so that three appear on each line, but I don't seems to be having any luck. I've tried:

<div style="position: absolute; top: 150px; left: 473px;"><img src="images/header_top.gif" alt=""/></div></div><table border="0" align="right" cellpadding="0" cellspacing="0" width="100%" style="padding-left:0px;padding-right:0px;padding-top:0px;padding-bottom:0px;">  <tr>	<td valign="top" align="center" width="750">	<script type="text/javascript">function open(sele){var radioDiv = document.getElementById('exp'+sele);if(radioDiv.style.display == "none"){radioDiv.style.display = "";}}function close(sele){var radioDiv = document.getElementById('exp'+sele);radioDiv.style.display = "none";}</script><table width="750" border="0" cellpadding="0" cellspacing="0" style="padding-left:0px;padding-right:0px;">  <tr><td><div id="content"><br /><img src="images/sub_header.gif" alt="" /><br /></td></tr>  <?		$news_sql="select * from member where status='active' limit 0,9";		$news_result=mysql_query($news_sql);		while($news_row=mysql_fetch_array($news_result))		 {		$id= $news_row['members_id'];		$header= $news_row['header'];		$review= $news_row['review'];?><? if(($l==1)||($l==3)){echo "<tr>";}?><td width="150" valign="top" style="padding: 15px;"><a href="java script:open(<?=$id?>)"><h2><?=$header?></h2></a> <p style="margin-top: 0px; font-size: 11px; color: rgb(207, 206, 194);"><?=$news_row['date'];?></p><p><div id=exp<?=$id?>><?=$review?><BR><BR><a href="java script:close(<?=$id?>)">hide</a></p></div> <? } ?>								  </div>			</td></tr></table>

but everything just appears on the same line.Does anybody have any suggestions please?Thanks

Link to comment
Share on other sites

Use the mod operator, it returns a remainder. You may have to fine tune this a little.

$nr = 0;$items_per_row = 3;while($news_row=mysql_fetch_array($news_result)){  if ($nr % $items_per_row == 0)  {	echo '<tr>';  }?>...<?php  if ($nr % $items_per_row == $items_per_row - 1)  {	echo '</tr>';  }  $nr++;}?>

Link to comment
Share on other sites

I changed the page to:

<?		$news_sql="select * from customers where status='active' limit 0,9";		$news_result=mysql_query($news_sql);		while($news_row=mysql_fetch_array($news_result))		 {		$id= $news_row['members_id'];        $header= $news_row['header'];        $review= $news_row['review'];?><? $nr = 0;$items_per_row = 3;while($news_row=mysql_fetch_array($news_result)){  if ($nr % $items_per_row == 0)  {    echo '<tr>';  }?><td width="150" valign="top" style="padding: 15px;"><a href="java script:open(<?=$id?>)"><h2><?=$header?></h2></a> <p style="margin-top: 0px; font-size: 11px; color: rgb(207, 206, 194);"><?=$news_row['date'];?></p><p><div id=exp<?=$id?>><?=$review?><BR><BR><a href="java script:close(<?=$id?>)">hide</a></p></div> <?php  if ($nr % $items_per_row == $items_per_row - 1)  {    echo '</tr>';  }  $nr++;}?>

but then nothing loaded at all. I don't know if I put it in the wrong place or what.

Link to comment
Share on other sites

My eyes may deceive me, but I think I see two while loops, but only one closing brace, the one at the end. That will cause a parse error, and nothing will show.
I've added another bracket, but still no results. This is what I've now got:
<?		$news_sql="select * from customers where status='active' limit 0,9";		$news_result=mysql_query($news_sql);		while($news_row=mysql_fetch_array($news_result))		 {		$id= $news_row['members_id'];        $header= $news_row['header'];        $review= $news_row['review'];		}		?><? $nr = 0;$items_per_row = 3;while($news_row=mysql_fetch_array($news_result)){  if ($nr % $items_per_row == 0)  {    echo '<tr>';  }?><td width="150" valign="top" style="padding: 15px;"><a href="java script:open(<?=$id?>)"><h2><?=$header?></h2></a> <p style="margin-top: 0px; font-size: 11px; color: rgb(207, 206, 194);"><?=$news_row['date'];?></p><p><div id=exp<?=$id?>><?=$review?><BR><BR><a href="java script:close(<?=$id?>)">hide</a></p></div> <?php  if ($nr % $items_per_row == $items_per_row - 1)  {    echo '</tr>';  }  $nr++;}?>

Link to comment
Share on other sites

You need to pay more attention to what you're pasting. Don't just paste something in the middle of your code and expect it to work. The example I posted has this line in it:while($news_row=mysql_fetch_array($news_result))Your code also has that line in it (I mean, before you pasted what I wrote). The code I posted that's above that line goes above that line in your code, and the code I posted below that line goes below that line in your code.I'm not giving you a whole new while loop to add, I'm trying to tell you how to change the one you already have.

Link to comment
Share on other sites

You need to pay more attention to what you're pasting. Don't just paste something in the middle of your code and expect it to work. The example I posted has this line in it:while($news_row=mysql_fetch_array($news_result))Your code also has that line in it (I mean, before you pasted what I wrote). The code I posted that's above that line goes above that line in your code, and the code I posted below that line goes below that line in your code.I'm not giving you a whole new while loop to add, I'm trying to tell you how to change the one you already have.
Still nothing :) I think that the code is ow right.
<?        $news_sql="select * from customers where status='active' limit 0,9";        $news_result=mysql_query($news_sql);		$nr = 0;		$items_per_row = 3;        while($news_row=mysql_fetch_array($news_result))         {  if ($nr % $items_per_row == 0)  {    echo '<tr>';  }		 {        $id= $news_row['members_id'];        $header= $news_row['header'];        $review= $news_row['review'];        }        ?><td width="150" valign="top" style="padding: 15px;"><a href="java script:open(<?=$id?>)"><h2><?=$header?></h2></a> <p style="margin-top: 0px; font-size: 11px; color: rgb(207, 206, 194);"><?=$news_row['date'];?></p><p><div id=exp<?=$id?>><?=$review?><BR><BR><a href="java script:close(<?=$id?>)">hide</a></p></div><?php  if ($nr % $items_per_row == $items_per_row - 1)  {    echo '</tr>';  }  $nr++;}?>

but I'm not 100% sure

Link to comment
Share on other sites

You probably have error messages disabled and a syntax error. Create another file to include the one you're working on.

<?phperror_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);include 'file.php';?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...