Jump to content

Recommended Posts

Hi, i'm currently having some troubles with my for loop. For some reason, it doesn't stop after it reached its conditions

 

<?php

include 'connect.php';

// Extracting Body Data
$sql = "SELECT div_file, table_file, flash_file, image_fol
	FROM stageone
	WHERE id = '1'";
$result = mysql_query ($sql) or die (mysql_error());
list ($div_num, $table_num, $flash_num, $image_fol) = mysql_fetch_row($result); 

$int_val3 = 0;
$int_val4 = 0;
$int_val5 = 0;

for ($int_val3 = 0; $int_val3 < $div_num; $int_val3++)
{
//$div_num remains '0'
$div_top = $_POST["div_top".$int_val3];
$div_left = $_POST["div_left".$int_val3];
$div_image = $_POST["div_name".$int_val3];
echo "<div style='position:absolute; left:".$div_left."px; top:".$div_top."px; overflow:auto;'>\n";
echo "<img src='".$image_fol."/".$div_image."'>\n";
echo "</div>\n";
//$div_num becomes '1'
}

//create table variables
for ($int_val4 = 0; $int_val4 < $table_num; $int_val4++)
{
$table_width.$int_val4 = $_POST["table_width".$int_val4];
$table_height.$int_val4 = $_POST["table_height".$int_val4];
$table_top.$int_val4 = $_POST["table_top".$int_val4];
$table_left.$int_val4 = $_POST["table_left".$int_val4];
$table_border.$int_val4 = $_POST["table_border".$int_val4];
$table_con.$int_val4 = $_POST["content".$int_val4];

echo "<div style='position:absolute; left:".$table_left."px; top:".$table_top."px; overflow:auto;'>\n";
}

$sql_delete = mysql_query("DELETE * FROM stageone");

if ($sql_delete)
{
echo "Delete Success";
}


?>

 

it outputs

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
dvien</title>

<link rel='stylesheet' href='' type='text/css'>
<link rel='stylesheet' href='' type='text/css'>
<script language='JavaScript' src='' type='text/javascript'></script>
<script language='JavaScript' src='' type='text/javascript'></script>
</head>

<body>
<div style='position:absolute; left:px; top:px; overflow:auto;'>

<img src='asdfasfsfsfsafasf/'>
</div>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<img src='asdfasfsfsfsafasf/'>
</div>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>

<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>
<div style='position:absolute; left:px; top:px; overflow:auto;'>

Link to comment
https://forums.phpfreaks.com/topic/106847-preventing-a-infinite-loop/
Share on other sites

ueon, the error I pointed out is causing the loop to run forever.  The condition for loop termination is that $int_val4 is not less than $table_num, but you are resetting $int_val4 to null every time through the loop.

 

If you fix that and you still have problems, post your code again here.

change to

for ($int_val4 = 0; $int_val4 < $table_num; $int_val4++)
{
$table_width = $_POST["table_width".$int_val4];
$table_height = $_POST["table_height".$int_val4];
$table_top = $_POST["table_top".$int_val4];
$table_left = $_POST["table_left".$int_val4];
$table_border = $_POST["table_border".$int_val4];
$table_con = $_POST["content".$int_val4];

echo "<div style='position:absolute; left:".$table_left."px; top:".$table_top."px; overflow:auto;'>\n";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.