Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 23rd, 2004, 11:42 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default Loop and move next

i have 11 records in a database(MSSQL) i want to dispaly 4 records for a line.(LIKE)
now i have display like this format
***********

I want display like this format
****
****
***

please send me the php code.
thank you

surendran
(Anything is Possible)
__________________
surendran
(Anything is Possible)
http://www.suren.info
http://ssuren.spaces.msn.com
 
Old July 24th, 2004, 01:27 PM
Authorized User
 
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

do a loop?
set the loop to display four records, a line break, and then four more records, a line break, and so on.


$total = totalNumberOfRecordsToBeDisplayed;
$break = theNumberOfRecordsDisplayedBetweenLineBreaks;

for($counter=0; $counter<$total; $counter++)
  {
  codeThatDisplaysARecord;
  if($counter == $break)
    {
    echo "<br>";
    }
  }


you'll need to change the code to include the lines needed to get the number of records and display the records, but seeing as you're already successful at displaying the records, it shouldn't be much trouble for you.
 
Old July 25th, 2004, 11:18 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

Thanks grimmy,
but still i recive this format answer
* * * *
* * * * * * *

this code working like this,
i need like
****
****
***
thanks ,
<?
$total = 11;
$break = 4;
for($counter=0; $counter<$total; $counter++)
  {
  echo "* ";


surendran
(Anything is Possible)
 
Old July 27th, 2004, 12:17 PM
Authorized User
 
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, my mistake! i missed the fact that it needs to count both the total number of records to be displayed and the number of records to be displayed on one line.
the following code should clear that up:

$total = 11; //total number of records to be displayed
$break = 4; //number of records displayed between line breaks
$records = 0; //the number of records already displayed on a single line

for($counter=0; $counter<$total; $counter++)
{
echo "*"; //code that displays a record
$records++;
if($records == $break)
    {
    echo "<br>";
    $records = 0;
    }
}

the above is cut directly from something i tested just a couple of minutes ago and it worked fine. i've made the text in the code into comments, but in essence the red is what i've added or changed to make it work and the output it gave was:
****
****
***

just the way you wanted it, right?
let me know if you have any further problems!

grimmy
God, grant me the serenity to accept the things I cannot change, the courage to change the things I can, and the wisdom to hide the bodies of those people I had to kill because they pissed me off.





Similar Threads
Thread Thread Starter Forum Replies Last Post
loop value move to table mateenmohd Classic ASP Basics 9 August 21st, 2005 06:12 PM
loop values and text box values move mateenmohd Classic ASP Basics 2 April 5th, 2005 11:33 PM
Which book should I move on to next? El Morenito All Other Wrox Books 4 September 24th, 2004 03:04 PM
how shall I move the cursor? nerssi Javascript 0 September 21st, 2004 09:27 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.