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 8 of 8

Thread: PHP Won't echo?

  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts

    PHP Won't echo?

    Hello,

    For some reason, php won't echo the $row[2], so I assume there is something wrong with my code. If you help, I will be highly grateful.

    THanks

    PHP Code:
    <?php
    ob_start
    ();
    require_once(
    'connect.php');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    <link rel="stylesheet" href="style.css" type="text/css" />
    </head>

    <body>
    <div class="header">
    <div class="global-nav">
    <p>Welcome to my blog! I've not really finished the CMS yet so bear with me! Latest Post: Why Marc is sexy.</p>
    </div></div>
    <div id="container">
    Introduction - <a href="#">Hide / Show</a><br />
    Blah Blah<br /.
    <?php
    $query 
    mysql_query("SELECT `id`, `title`, `body` FROM `posts`") or die(mysql_error());
    while(
    $row mysql_fetch_array($queryMYSQL_NUM)) {
        echo 
    $row[2];
        
        
    print_r($row);
    }
    ?>

    <a href="#"><h2>Why Marc is sexy</h2></a> Post by <a href="#">Steven</a> on 16th November 2008<br />
    <p>This is the post. Marc is sexy because the new stuff on www.codesleeprepeat.com, his website. Come on, admint he's aweosme!</p>
        <br /><br /
    <h2>Why Marc is sexy</h2> Post by <a href="#">Steven</a> on 16th November 2008<br />
    <p>This is the post. Marc is sexy because the new stuff on www.codesleeprepeat.com, his website. Come on, admint he's aweosme!</p>
    </div>
    </body>
    </html>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    See this ....

    http://www.php-mysql-tutorial.com/php-mysql-select.php

    I think you might try echo $row[0];

  • Users who have thanked mlseim for this post:

    Webmonkey (08-04-2008)

  • #3
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    What does print_r show?
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #4
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks both of you for your quick replies.

    The print_r shows:

    1 [1] => Why is Steven so hot? [2] => Not sure... someone please say! )

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    Edit: Never mind, you posted while I was writing this.

    More importantly, you need to tell us what you see in front of you when you try this.

    Does the portion of the page before the query show in the browser and does the portion of the page after the php logic show in the browser?
    Last edited by CFMaBiSmAd; 08-04-2008 at 04:05 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • Users who have thanked CFMaBiSmAd for this post:

    Webmonkey (08-04-2008)

  • #6
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Yes, everything is shown except the echo from the database. Even the print_r array is displayed corrently.

    Thanks

  • #7
    New Coder
    Join Date
    Apr 2006
    Location
    Tadley, UK
    Posts
    63
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I have now got this working. Thanks for your help everyone invloved.

  • #8
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,294
    Thanks
    4
    Thanked 203 Times in 200 Posts
    What did you find that resolved it?
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

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