PDA

View Full Version : Loop in PHP Direct Execution


ocean86
05-02-2010, 08:48 PM
Hi,
I create a widget type "PHP Direct Execution". In the PHP code that I've written, there is a cycle (while). When I insert this PHP code in the widget, the cycle doesn't function. Only the last result of the query it's printed.

This is the PHP Code:
$db_host = "localhost";
$db_user = "user";
$db_password = "pwd";
$db_name = "database";
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);

$countdown_true = "1";
$query_ViewCountdown = mysql_query("SELECT * FROM city WHERE countdown='$countdown_true'", $db);
$num_rows = mysql_num_rows($query_ViewCountdown);
if ($num_rows > 0)
while($row = mysql_fetch_array($query_ViewCountdown)){
$username = $row['id_user'];
$nave = $row['id_nave'];
$testo = "Pinco pallino parte $username davvero tanto bravo $nave "; }
$output = $testo; "<br />";
}

Why the cycle isn't execute?

Thank you and excuse me for bad english!

bpr
05-02-2010, 08:58 PM
change $output = $test to $output .= $testo

that should solve your problem

ocean86
05-11-2010, 06:26 PM
I've done what you tell me but the problem isn't solved.

Other?

Thank you

bpr
05-11-2010, 08:27 PM
what about

$output = $testo; "<br />";

to

$output .= $testo . "<br />";

there was an ; instead of an / between $testo and br