MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 9th, 2003, 08:27 PM
mg03 mg03 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 mg03 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Formatting MySQL Results

I currently have a page that displays the content of one of my databases. I would like to insert a <HR> after every 5 entries. How would I go about doing this? My current code:

PHP Code:
<?
// grab the users from the database and throw them in a table
$conf_v02 mysql_query("SELECT * FROM users");
$numrows  mysql_numrows($conf_v02);

WHILE (
$disp_v01 mysql_fetch_array($conf_v02)) {
    
$bgcolor = (++$i 1) ? '#4B8FFF' '#1F73FF';
    
$txclass = (++$j 1) ? 'style2'  'style4' ;
?>
<TR>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>">PAGE # SHOULD GO HERE</TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>" STYLE="margin-top: 3; margin-bottom: 3;"><? echo $disp_v01['id']; ?></TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>"><? echo $disp_v01['name_f']; ?></TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>"><? echo $disp_v01['name_l']; ?></TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>"><? echo $disp_v01['name_u']; ?></TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>"><? if ($disp_v01['seclvl'] == '2') { $thelvl 'Admin'; } elseif ($disp_v01['seclvl'] == '1') { $thelvl 'Moderator'; } else { $thelvl='Basic'; } ?><?=$thelvl?></TD>
<TD WIDTH="14%" BGCOLOR="<?=$bgcolor;?>"><P ALIGN="center" CLASS="<?=$txclass;?>"><? if ($disp_v01['locked'] == '1') { $islocked='Yes'; } else { $islocked='No'; } ?><?=$islocked;?></TD>
</TR>
<?
}
// end loop
?>

Last edited by mg03 : July 9th, 2003 at 08:34 PM.

Reply With Quote
  #2  
Old July 9th, 2003, 09:02 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
PHP Code:
// enter loop...

// do stuff...

if (++$rowcount == && $rowcount $numrows 1) {
  echo 
'<tr><td colspan="7"><hr/></td></tr>';
}

// end loop 

Last edited by avit : July 9th, 2003 at 09:10 PM.

Reply With Quote
  #3  
Old July 9th, 2003, 09:41 PM
mg03 mg03 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 mg03 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thankyou, but unfortunately it echos a <HR> after the first 2 rows for some reason. After that, it functions correctly and places them every 5 rows. Do you have a clue why?

Reply With Quote
  #4  
Old July 9th, 2003, 10:46 PM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
I had an off-by-one error in my original code; the $numrows - 1 wasn't necessary so change it to just $numrows (see code sample below).

However, that doesn't solve your problem. I can't really say what's wrong without seeing it in place in your code. You don't have another existing variable called $rowcount do you?

Try running this stand-alone and see that it works:

PHP Code:
<pre>
<?
php
$numrows 
51;
for (
$i $i <= $numrows $i++) {
  echo 
"row $i counted as $rowcount\n";
  if (++
$rowcount == && $rowcount $numrows) {
    echo 
"------------------------ $rowcount \n";
  }
}
?>
</pre> 

Reply With Quote
  #5  
Old July 9th, 2003, 11:52 PM
mg03 mg03 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 7 mg03 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks a lot avit. That fixed it! I can program for hours and always get stuck on one tiny little thing.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Formatting MySQL Results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT