Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you want is completely possible with the use of ob_start(); Take a look here... <a href="http://www.php.net/ob_start" rel="nofollow">http://www.php.net/ob_start</a> and that will give you an idea. I don't know what your code looks like but as an example you could do something like this...</p> <pre><code>&lt;?php ob_start(); $query = "SELECT * FROM users"; $results = DB::get()-&gt;query($sql); echo "&lt;pre&gt;"; print_r($results); echo "&lt;/pre&gt;"; $content = ob_get_content(); @ob_end_clean(); echo $contents; //continue processing </code></pre> <p>obviously you need to tailor that for your specific script but that is an idea to get you where you need to go</p> <p>~~~~~~~~~EDIT~~~~~~~~~~~~~</p> <p>OK so using your code and comments here you go. First, yes you can do more than one while loop with the results, though you shouldn't as that is bad coding practices. That being said here is what I would do...</p> <pre><code>ob_start(); $level = ob_get_level(); $dbc = mysql_connect("$db_host","$db_username","$db_pass"); if (!$dbc) { die('SERVER ERROR PLEASE CONTACT US FOR MORE INFORMATION!'); } mysql_select_db("$db_name", $dbc); $sql = "SELECT * FROM `ads` WHERE (`status` LIKE 'active%' OR `status` LIKE 'featured%') ORDER BY `clicks` DESC LIMIT 10;"; $result = mysql_query($sql,$dbc); $totalads=mysql_num_rows($result); $str=""; while ($row = mysql_fetch_assoc($result)) { $str .= $row["banner"] . "][". $row["link"] . "&lt;br /&gt;"; $views[] = $row['views']; $target_views[] = $row['targetviews']; $ids[] = $row['id']; } echo $str; $content = ob_get_contents(); if(ob_get_level() &gt; $level + 1) { ob_end_flush(); } echo $content; @ob_end_clean(); for($i = 0, $len = count($views); $i &lt; $len; $i++) { if((intval($views[$i] + 1) &gt;= intval($target_views[$i]) { $sql = "UPDATE `ads` SET `views` = `views` + 1 , `status` = 'expired' WHERE `ID`=".$ids[$i].";"; } else { $sql = "UPDATE `ads` SET `views` = `views` + 1 WHERE `ID`=".$ids[$i].";"; } $result = mysql_query($sql); mysql_free_result($result); } //I don't know what this stuff here is for except for the close line, but it's her if you want it $str=rtrim($str,"&lt;BR&gt;"); mysql_free_result($result); mysql_close($dbc); die ($str); </code></pre> <p>?></p> <p>You no longer need the die statement there, but I left it incase you wanted it for something else. That should do what you need, check my stuff for typos though I just kinda pushed it out real quick for ya. please don't forget to mark that little check box for the right answer if it works, or leads you to the solution. Thanks man</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload