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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux