Re: NEWBIE: Can't Get My Loop Going. . .

From: Date: Mon, 28 Mar 2005 21:09:32 +0000
Subject: Re: NEWBIE: Can't Get My Loop Going. . .
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-211721@lists.php.net to get a copy of this message
Sorry folks. I have been told by a more knowledgeable friend that the problem was I forgot to ECHO out the join. It works now. Thanks anyway!! Jack On 28 Mar 2005, at 15:57, Jackson Linux wrote:
Hello all, I am a newbie trying to build a set of links to content in a db. I am connecting with the db and seeing the proper number of rows. if I echo out the values of $id and $sidebar I see that they take on the id# and text of the last entry in the database. I'm trying to make the script get each of the rows, until there are no more, and echo out the info I need for each row. Please can someone tell me where I'm going wrong? (the variables spelling out the db connection information are in a prepend file, and work.) Thanks in advance, Jack <?php $conn = mysql_connect($dbserver, $dbusername, $dbpassword); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("$dbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = " SELECT * FROM sidebar "; $sidebar = array(); $result = mysql_query($sql); if (!empty($result)) {
     while ($sidebar = mysql_fetch_assoc($result)) {
        $id = $sidebar['sidebar_id'];
        $linktext = $sidebar['headline'];
/* Build sidebar.*/
    $left_sidebar[] = "<li class='menu-item'>- <a class='sidebar-link' href='{$_SERVER['PHP_SELF']}?s={$id}' title=\"{$linktext}\">{$linktext}</a></li>";
    }
} else {} mysql_free_result($result); ?> <html><body> <ul><?php join("\n\n", $left_sidebar); ?></ul> </body></html> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#211721) next »