Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff
Author Message
Dawg
RavenNuke(tm) Development Team



Joined: Nov 07, 2003
Posts: 928

PostPosted: Mon Feb 11, 2008 6:49 am Reply with quote

Greetings all,
I have a loop that is driven me nutz!

Here is the deal...
I am pulling info from a dbase and inserting it in some html for display.

Code:
for($m=0; $m < sql_num_rows($resultboats, $dbi); $m++) { 

  list(BlaBlaBla) = sql_fetch_row($resultboats, $dbi);
$content = <<<END
and bunch of html calling out the $vars....
END;
}

If I call content inside the loop it displays the html as expected. The problem is if I have more that 2 records it will push it off the page. (The HTML containes tables that are set to %50 width)

I need it to insert a newline or break every 2 $contents. I know how increment works but I can not seem to get to insert the break.

Just to make sure ya'll understand what I am trying to do....let's say I have 10 records coming from the dbase. What I want to do is loop through 2 records....insert a newline or break....then loop through the next two records....insert a newline or break.....loop through the next 2 records...etc.

Thank You for the help!

Dawg
 
View user's profile Send private message
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Mon Feb 11, 2008 8:31 am Reply with quote

Here is a loop that outputs something every 2 iterations.

Code:


$i = 0;
for ($m = 0; $m < 20; ++$m)
{
   if (++$i % 2 == 0)
   {
      echo '<br />';
   }
}

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
Dawg







PostPosted: Mon Feb 11, 2008 8:46 am Reply with quote

Gremmie,
I will be sure to try it....I have questions about how it will work in my case....but let me bang on it a little before I ask.

Thank You for your help!

Dave
 
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Wed Feb 13, 2008 6:33 am Reply with quote

Gremmie, there is programming "wisdom" behind that code. Good job Gremmie. The pre-increment takes only 3 op-codes rather than 4 (only applies to PHP) so its faster (ref: PHP Optimization Tricks). Also, using the modulus function (the "%") is nice and tight.

However, I have one concern: since this is being used to build out a table, Dawg, you need to make sure you handle the case where you have an odd number of total rows. Don't forget the second column of <td>&nbsp;</td> to finish up the last row.

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more... 
View user's profile Send private message Visit poster's website
Dawg







PostPosted: Wed Feb 13, 2008 7:05 am Reply with quote

Gremmie,
Thank You for the code. It took a little while but I finialy got it working.

but..... if (++$i % 2 == 1) was the only way i could get her to go without an error.

montego,
The last table seems to be coming out fine. I jsut really got it working last night.....and now I am off working on the upgrade to RN....but I will make sure I look how it handles the odd number at the end.

Thank You both for your help!

Dave
 
Gremmie







PostPosted: Wed Feb 13, 2008 8:06 am Reply with quote

What was the "error" that caused you to change the 0 to a 1?
 
Dawg







PostPosted: Wed Feb 13, 2008 8:36 am Reply with quote

The "0" makes for 1 TD in the first row and "1" makes 2 TD's in the first row. I am sure it is something quirky in how I did it...HEre is the whole loop edited to be brief.....
Code:
$i = 0;             

for($m=0; $m < sql_num_rows($resultboats, $dbi....etc...); $m++) {

  list($id,$tid) = sql_fetch_row($resultboats, $dbi);

 if (++$i % 2 == 1)
   {

      echo "<table width='100%' border='5' cellspacing='0' cellpadding='0'><tr>";

   }

$content = <<<END

       <td width='50%'><center>
         <p><b><font face='Georgia, Times New Roman, Times, serif' size='5' font color='#0000FF'>$boat_title</font></b></p>
         <p><b>$logo</b></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'>$town Charter Boat</font></b></p>
         <p><b><img src='$img_one' alt='$boat_title'/></b></p>
         <table width='90%' border='5' align='center' cellspacing='0' cellpadding='0'>
           <tr>
             <td width='50%'><center><p><b><img src='$img_two' alt='$boat_title'/></b></p></center>
               <center><p><b><img src='$img_three' alt='$boat_title'/></b></p></center></td>
             <td><center><b><font face='Times New Roman, Times, serif' size='3'>$boat_text</font></b></center></td>
           </tr>
         </table><br/>
         <p><b><font face='Times New Roman, Times, serif' size='3'>$town, $state</font></b></p>
       <p><b><font face='Georgia, Times New Roman, Times, serif' size='4' font color='#0000FF'>$boattext2</font></b></p>
         <p><font face='Georgia, Times New Roman, Times, serif' color='#FF0000' font size='4'><b>$captain</b></font></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'>$phone</font></b></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'><a href='mailto:$email?subject=$boat_title'>$email</a></font></b></p>
      
         <p><b><font face='Times New Roman, Times, serif' size='3'><a href='$fishreport'>Read Our Fishing Reports</a></font></b></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'><a href='$photolink'>Come See Our Photos</a></font></b></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'><a href='$teampage'>See More Details</a></font></b></p>
         <p><b><font face='Times New Roman, Times, serif' size='3'><a href='$website'>Visit Our Website</a></font></b></p><br/>
       </center>
       </td>
END;

//echo $i;
           echo $content;


}


I am no guru. I just beat on it till it works! LOL! and I guess "Error" was the wrong word for it....It wouldn't come out the way I wanted....is more accurate...


Dawg

PS....No Laughing at my poor coding.....I was very proud of myself for getting this far with it.... Smile
 
Gremmie







PostPosted: Wed Feb 13, 2008 9:37 am Reply with quote

Is the resulting code compliant? I wouldn't expect to see the <table> generation inside the loop like that. And then the table is closed every time through the loop.
 
Dawg







PostPosted: Wed Feb 13, 2008 11:00 am Reply with quote

Gremmie,
Compliant.....I doubt it. The orginal idea was to do it with just the TD's inside the loop. But I could not get that to work. It worked just fine in FF but would not work correctly in IE. This loop will be the basis for MANY pages in this module that I am building and I am open to suggestions from those that are smarter than me.

I am tickled to death that I got the information into the database....out of the datbase and presented on the screen in one piece. Now if I could do that correctly.....that would be even better. I know I sux at this....but it is fun and I do enjoy it.

Dawg
 
Gremmie







PostPosted: Wed Feb 13, 2008 11:17 am Reply with quote

Absolutely it is fun! I'm not quite sure what you are doing, sorry, but I would try to open and close the table outside the loop, and then inside the loop just generate rows.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> General/Other Stuff

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©