PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old June 28th, 2002, 12:36 PM
chobo4ever chobo4ever is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Vienna, Austria
Posts: 63 chobo4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
how to count an array?

my problem is: I have in my database 30 rows. what I want to do is make radiobuttons for every row, but AFTER THE 15th ROW I WANT TO WRITE THE OTHER 15 IN A NEW COLUMN. here is my code. right now it just lists the subjects and does not care how long the $row array is.

Code:
while($row = mysql_fetch_array($result)) 
			{

										echo "<tr><td><input type="checkbox" name="" . $row['nr'] . "" value="newsletter" border="0">"" . $row['subject'] . ""</td></tr>";
	    	   		}

Reply With Quote
  #2  
Old June 28th, 2002, 03:18 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: how to count an array?

php Code:
Original - php Code
  1.  
  2. <?php
  3. //your code
  4. while($row = mysql_fetch_array($result)){
  5.   echo "<tr><td><input type="checkbox" name="" . $row['nr'] . "" value="newsletter" border="0">"" . $row['subject'] . ""</td></tr>";
  6. }
  7.  
  8. //my version
  9. //something like this will work...
  10. while($row[]=mysql_fetch_array($result));
  11. for($x=0,$y=count($row)/2;$x<$y;$x++){
  12.   $out_table.='<tr>';
  13.   $out_table.='<td><input type="checkbox" name="'.$row[$x]['nr'].'" value="newsletter" border="0">"'.$row[$x]['subject'].'"</td>';
  14.   $out_table.='<td><input type="checkbox" name="'.$row[$x+$y]['nr'].'" value="newsletter" border="0">"'.$row[$x+$y]['subject'].'"</td>';
  15.   $out_table.='</tr>';
  16. }
  17. ?>



Cheers,
Keith.

Reply With Quote
  #3  
Old June 28th, 2002, 03:26 PM
chobo4ever chobo4ever is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Vienna, Austria
Posts: 63 chobo4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: how to count an array?

thanks, good to know there is help out there ...

Reply With Quote
  #4  
Old June 28th, 2002, 03:51 PM
chobo4ever chobo4ever is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Vienna, Austria
Posts: 63 chobo4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: how to count an array?

it basicly works. but because the for loop starts with $x=0, it writes in the second column the last subject of the first column again! but when I start with 1, the first subject is obviously lost. How can I solve this problem?

and at the end it writes two empty subjects which arent in the database. but look for yourself. here is the LINK.

thanks again

Reply With Quote
  #5  
Old June 28th, 2002, 04:52 PM
Taoism Taoism is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Winnipeg, MB, Canada
Posts: 81 Taoism User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 30 sec
Reputation Power: 2
RE: how to count an array?

php Code:
Original - php Code
  1.  
  2. <?php
  3. //remember this solution only works if there is an even number of rows.
  4. while($row[]=mysql_fetch_array($result));
  5. //get rid of the extra blank row added by the while loop
  6. unset($row[count($row)-1]);
  7. for($x=0,$y=count($row)/2;$x<$y;$x++){
  8.   $out_table.='<tr>';
  9.   $out_table.='<td><input type="checkbox" name="'.$row[$x]['nr'].'" value="newsletter" border="0">"'.$row[$x]['subject'].'"</td>';
  10.   $out_table.='<td><input type="checkbox" name="'.$row[$x+$y]['nr'].'" value="newsletter" border="0">"'.$row[$x+$y]['subject'].'"</td>';
  11.   $out_table.='</tr>';
  12. }
  13. ?>


Cheers,
Keith.

Reply With Quote
  #6  
Old June 28th, 2002, 05:01 PM
chobo4ever chobo4ever is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Vienna, Austria
Posts: 63 chobo4ever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: how to count an array?

thx, worx now!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > how to count an array?


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 5 hosted by Hostway