Jump to content

Loop inside a loop


sogorman

Recommended Posts

So I have a PHP parent page that is accesses that scans the database for the passed token in the URL and then replaces content on the template page using a loop. My issue is that I am trying to use a loop on the secondary page which causes the white screen of death. From what I can tell the loop inside a loop is causing the issue.

I'll paste the code below, let a newbie know if you have any ideas or can point me in the right direction.

 

Thanks everyone!

 

 

Here is the chunk of code from the parent page with the loop function....

 

 

// output pre content

eval("\$preContent = \"$preContent\";");

print_r( replaceChar($preContent) );

 

$sqlSearch = "SELECT * FROM ".$row[tdbd_name]." WHERE ".$sqlKeyword." LIMIT ".MAX_ROWS;

$resultSearch = mysql_query($sqlSearch);

 

while($displayrows = mysql_fetch_assoc($resultSearch)) {

$display = replaceTokens($loopTemplate);

$display = str_replace('\\', '[backslash]', $display);

$display = str_replace('[%', '$displayrows[', $display);

$display = addslashes(str_replace('%]', ']', $display));

$display = replaceTokens($display);

$display = changeCase($display);

 

eval("\$display = \"$display\";");

 

$display = stripslashes($display);

$display = str_replace('[backslash]', '\\', $display);

$display = replaceChar($display);

 

print_r( $display );

 

}

// output post content

 

 

And here is the loop function from the page that the above code loops through replacing tokens in.

 

 

 

<?php

$mySQLServer = "xxxxxxxxx";

$mySQLUser = "xxxxxxxxxx";

$mySQLPass = "xxxxxxxx";

$mySQLDB = "xxxxxxxxxxxxx";

$SQLToday = date("m/d/y") . "<br />";

$SQLsevendays = mktime(0,0,0,date("n"),date("j")-7,date("Y"));

$SQLsevenname = (date("l", $SQLsevendays));

$SQLsevennumber = (date("jS", $SQLsevendays));

$dbhandle = mssql_connect($mySQLServer, $mySQLUser, $mySQLPass)

  or die("Couldn't connect to SQL Server on $myServer");

$selected = mssql_select_db($mySQLDB, $dbhandle)

  or die("Couldn't open database $myDB");

$query = "WEB_ApproveHistory @State='CA', @Days=5, @Records=8";

$data = mssql_query($query);

$result = array();

 

while ($row = mssql_fetch_object($data))

{

      $result[] = $row;

      $returnedresults = (97*($row->TotalApprovals)) ;

}

 

$englishreturnedresults = number_format($returnedresults);

echo 'In just the last week since ' . $SQLsevenname . ' the ' . $SQLsevennumber . '  has delivered ';

echo $englishreturnedresults;

echo '  Here are just a few people ';

 

echo '<ul class="BulletCheck">';

 

mssql_next_result($data);

 

 

while ($row = mssql_fetch_object($data))

{

      $result[] = $row;

      echo '<li>' . '  ' . $row->FirstName  . ' From '. $row->City . ', ' . $row->State .' PreApproved On ' .$row->ApprovedDate . '</li>';

}

 

 

mssql_close($dbhandle);

?>

 

Link to comment
https://forums.phpfreaks.com/topic/228071-loop-inside-a-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.