...

View Full Version : function wont echo in my while loop only out side



andrew1234
08-25-2009, 09:56 PM
Hi

this is a shortened version of what I'm trying to do.....

My function test won't echo in the while loop. If I write it like this it shows up before the while loop in the HTML.

any ideas?

Thanks for the help.




function test(){
echo "test_this";
}

while ($row = mysql_fetch_array($result)) {
echo " <td>". test()."</td>;
echo " <td>". $row['id']."</td>;

";
}

firetag
08-25-2009, 09:58 PM
I don't know if this will work, but try this

function test(){
echo "test_this";
}

while ($row = mysql_fetch_array($result)) {
ob_start();
echo " <td>". test()."</td>";
echo " <td>". $row['id']."</td>";
ob_end_flush();
}

show your code for $result if that doesn't work

andrew1234
08-25-2009, 10:12 PM
hi thanks for the reply

no it did not work

here is the $result

$result = mysql_query("SELECT * FROM videos_in_store WHERE video_ID =".$_GET['video_ID']);

Thanks for the help again

whizard
08-25-2009, 10:14 PM
Change

$result = mysql_query("SELECT * FROM videos_in_store WHERE video_ID =".$_GET['video_ID']);

to

$result = mysql_query("SELECT * FROM videos_in_store WHERE video_ID =".$_GET['video_ID']) or die(mysql_error());

That will spit out any errors in the query (just to see if there are any first).

Dan

andrew1234
08-25-2009, 10:22 PM
Hi Thanks everyone for the help with my the problem.

the error was -- that I was putting an echo in an echo.


so here is the solution


function test(){
echo "test_this";
}

while ($row = mysql_fetch_array($result)) {
echo " <td>";
test();
echo " </td><td>". $row['id']."</td>;

";
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum