Jump to content


Photo

php loop troubles


  • Please log in to reply
5 replies to this topic

#1 danthorpe2002

danthorpe2002
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 June 2006 - 10:00 PM

Hi, i have a loop running and i want to stop it. insert a new column in a table and then resume the loop from were it stopped how can i do thiis?? This is the current code


<td width="130" align="center">
<?php
echo mysql_error();
$num = mysql_num_rows($result);

$j=5;
while ($j < $num) {
$title=mysql_result($result, $j, 0);
$desc=mysql_result($result, $j, 1);
$hasImage=mysql_result($result, $j, 2);
?>
<p><a href="play.php?game=<?php echo $title;?>" title="Play <?php echo $title;?> Flash Game"/><?php echo $title;?><br /><img src="preview/<?php echo($hasImage > 0? $title : "missing");?>.gif" alt="Play <?php echo $title;?> Flash Game" width="90" height="90" border="0"/></p>
<?php
$j++;
}
?>
<td align="center">
<?php
echo mysql_error();
$num = mysql_num_rows($result);

$j=5;
while ($j < $num) {
$title=mysql_result($result, $j, 0);
$desc=mysql_result($result, $j, 1);
$hasImage=mysql_result($result, $j, 2);
?>
<p><a href="play.php?game=<?php echo $title;?>" title="Play <?php echo $title;?> Flash Game"/><?php echo $title;?><br /><img src="preview/<?php echo($hasImage > 0? $title : "missing");?>.gif" alt="Play <?php echo $title;?> Flash Game" width="90" height="90" border="0"/></p>
<?php
$j++;
}
?>
</td>
</td>
[a href="http://www.squareadvert.com" target="_blank"]Free Advertising[/a]
[a href="http://games.SquareAdvert.com" target="_blank"]Free Flash Games[/a]

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:27 PM

where do you want to "stop" it? explain what your actual goal is
z..z..z..z..z..z..z..z..

#3 danthorpe2002

danthorpe2002
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 June 2006 - 10:30 PM

Ok, i just need the loop to run 5 times, then insert a new column and resume the loop but i don''t know how to do this, i have indicated in the code were i need the loop to resume

<td width="130" align="center">
<?php
echo mysql_error();
$num = mysql_num_rows($result);

$j=5;
while ($j < $num) {
$title=mysql_result($result, $j, 0);
$desc=mysql_result($result, $j, 1);
$hasImage=mysql_result($result, $j, 2);
?>
<p><a href="play.php?game=<?php echo $title;?>" title="Play <?php echo $title;?> Flash Game"/><?php echo $title;?><br /><img src="preview/<?php echo($hasImage > 0? $title : "missing");?>.gif" alt="Play <?php echo $title;?> Flash Game" width="90" height="90" border="0"/></p>
<?php
$j++;
}
?>
<td align="center">

//LOOP SHOULD CONTINUE HERE

<?php
echo mysql_error();
$num = mysql_num_rows($result);

$j=5;
while ($j < $num) {
$title=mysql_result($result, $j, 0);
$desc=mysql_result($result, $j, 1);
$hasImage=mysql_result($result, $j, 2);
?>
<p><a href="play.php?game=<?php echo $title;?>" title="Play <?php echo $title;?> Flash Game"/><?php echo $title;?><br /><img src="preview/<?php echo($hasImage > 0? $title : "missing");?>.gif" alt="Play <?php echo $title;?> Flash Game" width="90" height="90" border="0"/></p>
<?php
$j++;
}
?>
</td>
</td>
[a href="http://www.squareadvert.com" target="_blank"]Free Advertising[/a]
[a href="http://games.SquareAdvert.com" target="_blank"]Free Flash Games[/a]

#4 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 16 June 2006 - 10:37 PM

change the code to thiis

$sql = ""; // your sql here
$result = mysql_query ($sql) or die (mysql_error ());
$num = 0;
while ($data = mysql_fetch_array ($result))
{
  // loop
  if ($num == 5) echo "</td><td>";
  $num++;
}

z..z..z..z..z..z..z..z..

#5 danthorpe2002

danthorpe2002
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 16 June 2006 - 10:44 PM

thanks i appreciate youe help

but which parts of the code go were??


[a href="http://www.squareadvert.com" target="_blank"]Free Advertising[/a]
[a href="http://games.SquareAdvert.com" target="_blank"]Free Flash Games[/a]

#6 danthorpe2002

danthorpe2002
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 June 2006 - 12:29 PM

Ok, sorted
[a href="http://www.squareadvert.com" target="_blank"]Free Advertising[/a]
[a href="http://games.SquareAdvert.com" target="_blank"]Free Flash Games[/a]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users