unplugged_web Posted February 10, 2009 Share Posted February 10, 2009 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 More sharing options...
webtrix Posted February 10, 2009 Share Posted February 10, 2009 It would be nice if you could post your html output..<?php echo result1 \n result2 \n result3 ;?> Link to comment Share on other sites More sharing options...
jeffman Posted February 10, 2009 Share Posted February 10, 2009 $l has no value. You should also have a way to add corresponding </tr> tags. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 10, 2009 Share Posted February 10, 2009 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 More sharing options...
unplugged_web Posted February 11, 2009 Author Share Posted February 11, 2009 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 More sharing options...
jeffman Posted February 11, 2009 Share Posted February 11, 2009 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. Link to comment Share on other sites More sharing options...
unplugged_web Posted February 11, 2009 Author Share Posted February 11, 2009 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 More sharing options...
justsomeguy Posted February 11, 2009 Share Posted February 11, 2009 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 More sharing options...
unplugged_web Posted February 12, 2009 Author Share Posted February 12, 2009 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 More sharing options...
justsomeguy Posted February 12, 2009 Share Posted February 12, 2009 Are you getting any errors? Make sure error reporting is enabled on the page.error_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1); Link to comment Share on other sites More sharing options...
unplugged_web Posted February 12, 2009 Author Share Posted February 12, 2009 Are you getting any errors? Make sure error reporting is enabled on the page.error_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);Nope no errors at all Link to comment Share on other sites More sharing options...
justsomeguy Posted February 12, 2009 Share Posted February 12, 2009 So what are you seeing? Link to comment Share on other sites More sharing options...
unplugged_web Posted February 13, 2009 Author Share Posted February 13, 2009 So what are you seeing?Nothing at all. The page isn't loading anything Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2009 Share Posted February 16, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.