Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Nested loops that dont loop
Old 05-09-2005, 06:01 AM Nested loops that dont loop
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Hi again.
Im rewriting my php so instead of using 15 pages and a load of if statements it will use about 5 pages of loops within loops. The trouble is i can only make my loops work if they are 1st generation. The code printed below works and gives me $_SESSION[numbed] outputs, but if i remove alll of my // marks which blank the nested loop i only get feedback as if $_SESSION[numbed] were equal to 1. The nested loop itself should return multiple outputs each time it is triggered by surrounding one but it doesn't. Would anyone be able to shed some light??
Thankyou
PHP Code:
<?php
session_start
();
echo
"
<html>
<head>
</head>
<body>"
;
$user="root";
$host="localhost";
$password="";
$database="doorstop";
$connection mysql_connect($host,$user,$password)   or die ("couldn't connect to server");
$db mysql_select_db("doorstop")                    or die ("coudn't locate the database");



for(
$i 0$i $_SESSION[numbed]; $i++)

{
$_SESSION["apwidth$i"]  =   $_POST["apwidth$i"];
$_SESSION["apheight$i"] =   $_POST["apheight$i"];
$_SESSION[seekassist]="please call ********";
$overlap 30;
$doorsize2 = (($_SESSION["apwidth$i"] +  $overlap)      / 2);
$doorsize3 = (($_SESSION["apwidth$i"] + ($overlap 2)) / 3);
$doorsize4 = (($_SESSION["apwidth$i"] + ($overlap 3)) / 4);
$doorsize5 = (($_SESSION["apwidth$i"] + ($overlap 4)) / 5);

echo
"      bedroom$i aperture is ".$_SESSION["apwidth$i"]." mm wide x ".$_SESSION["apheight$i"]." mm high<br>"

  if (
$_SESSION["apwidth$i"] <= '2000')
  {

  
$numdoor='2';
  echo 
"For system$i you need $numdoor doors $doorsize2 mm wide and ".$_SESSION["apheight$i"]."mm high each.<br><br>";
  
$_SESSION["doorsize$i"] = "$doorsize2";
  
$_SESSION["numdoor$i"] = "$numdoor";

//******If i un comment the following for statement my loops fail***********
//    {
//    echo "now choose a glass type for";
//    }
//  for ($i = 0; $i < $_SESSION["numdoor$i"]; $i++)
//    {
//    $query="SELECT DISTINCT glass FROM price ORDER by glass";
//    $result=mysql_query($query)
//    or die ("nope"); 
//    echo"
//    Door $i:
//    <form action='chosenglass.php'
//    method='post'>\n
//    <select name="."door1glass$i".">\n";
//    while ($row = mysql_fetch_array($result))
//      {
//      extract($row);
//      echo"
//      <option value='$glass'>$glass\n";
//      }
//      echo"
//      </select>\n";
//    }
  
}
}

echo
"
  <input type='submit' value='Select'>
  </form>\n"
;
?>
</body>
</html>

Last edited by hiptobesquare; 05-09-2005 at 07:57 AM..
hiptobesquare is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-09-2005, 08:48 AM
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
ok this is a far simplified version of above still with the same problem. The result i get is as id expect until i remove the commented "for" loop- When that is uncommented my 1st loop wont rotate more than once.

PHP Code:
<?php
session_start
();
echo
"
<html>
<head>
</head>
<body>"
;

for(
$i 0$i $_SESSION[numbed]; $i++)
{
$_SESSION["apwidth$i"]  =   $_POST["apwidth$i"];
$_SESSION["apheight$i"] =   $_POST["apheight$i"];
$_SESSION[seekassist]="please call *******";
$overlap 30;
$doorsize2 = (($_SESSION["apwidth$i"] +  $overlap)      / 2);

echo
"bedroom$i aperture is ".$_SESSION["apwidth$i"]." mm wide x ".$_SESSION["apheight$i"]." mm high<br>"

  
$numdoor='2';
  echo 
"For system$i you need $numdoor doors $doorsize2 mm wide and ".$_SESSION["apheight$i"]."mm high each.<br><br>";
  
$_SESSION["doorsize$i"] = "$doorsize2";
  
$_SESSION["numdoor$i"] = "$numdoor";
 
// for ($i = 0; $i < $numdoor; $i++)
 //   {echo "$i<br>";
 //   }
   
  
}
?>
</body>
</html>

Last edited by hiptobesquare; 05-09-2005 at 08:54 AM..
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Old 05-09-2005, 10:03 AM
hiptobesquare's Avatar
Extreme Talker

Posts: 186
Location: London UK
Trades: 0
Because i was using $i in both loops it didnt work. by changing $i to $d in the inner loop i got the result i was after
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Old 05-09-2005, 10:08 AM
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
well done, this one knows what hes doin
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
Reply     « Reply to Nested loops that dont loop
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.80183 seconds with 12 queries