Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    147
    Thanks
    31
    Thanked 2 Times in 2 Posts

    function wont echo in my while loop only out side

    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.


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

  • #2
    New Coder
    Join Date
    Jul 2009
    Posts
    52
    Thanks
    6
    Thanked 1 Time in 1 Post
    I don't know if this will work, but try this
    PHP Code:
    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
    Last edited by firetag; 08-25-2009 at 10:03 PM.

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Posts
    147
    Thanks
    31
    Thanked 2 Times in 2 Posts
    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

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Posts
    147
    Thanks
    31
    Thanked 2 Times in 2 Posts
    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

    PHP Code:
    function test(){
        echo 
    "test_this";
    }

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



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •