1 reply [Last post]
ChadBaus
ChadBaus's picture
Offline
newbie
Chicago, IL
Last seen: 11 years 43 weeks ago
Chicago, IL
Timezone: GMT-5
Joined: 2008-06-08
Posts: 1
Points: 0

I'm new to the forum but have a perplexing problem I hope an expert in CSS can help me with.

I have a navigation bar that at the top level is some images inside a DIV, but the sub menus need to all be driven by PHPMySQL. I've tried separating the images into individual GIFs and tried stylizing the top level of UL tags to use the background-image property and set the display to be inline but I can't figure out how to tie the images to the Spry menu widget. The code for the page is as follows (the real page will have the image menu inside a DIV tag, this page is my "experiment". The database abstraction layer and other common functions I have placed in common.php.

If anyone has any other suggestion how I can make this work with PHP/MYSQL/CSS I would greatly appreciate it!

HELP!!!!!

<? include("inc/common.php"); ?>

Untitled Document

<?

$fullindents = false; // change this to true if you want full indentation
$recordset = mysql_query("SELECT id, parent, title FROM articles ORDER BY id ASC"); // query

$all = array();
while($row = mysql_fetch_assoc($recordset)) {
// $row['title'] = str_replace(' ',' ',$row['title']);
$all[$row['id']] = $row; // add everything on one big array
}

$top = array_filter($all, 'topcat'); // extract the top parents (with parent = 0)
$depth = 0; // depth of our traversing, this is for indentation

?>





<?

echo "

foreach($top as $cat) { // for every top parent

buildchild($cat); // build its children
}
echo "\n";

function buildchild($cat) { // the recursive builder
global $depth, $fullindents;
$depth++;
$link = '';
if ($fullindents) {
echo t() . "

  • \n" . t(1) . $link . $cat['title'] . '';
    }
    else {
    echo t() . "
  • " . $link . $cat['title'] .'';
    }
  • if ($children = haschildren($cat['id'])) { // check if the current element has children and build them
    $ul = true;
    $depth++;
    echo "\n" . t() . "

      \n";
      foreach($children as $child) {
      buildchild($child);
      }
      echo t() . "
    ";
    $depth--;
    }
    if ($fullindents) {
    echo "\n" . t() . "\n";
    }
    else {
    if ($ul) echo "\n" . t();
    $ul = false;
    echo "\n";
    }
    $depth--;
    }

    function haschildren($id) { // checks if an element has children
    global $all;
    foreach($all as $cat) {
    if ($cat['parent'] == $id) {
    $result[] = $cat;
    unset($all[$cat['id']]); // unset this value so that we dont
    // search it again when looking through
    // the array next time, this gives a
    // ~20% increase in speed to the script
    }
    }
    if (count($result) > 0) {
    return $result; // return the children if found
    }
    return false; // otherwise return false
    }

    function t($x=null,$s=" ") { // indentation function, you can change spaces to \t (tabs) if you like
    global $depth;
    return str_repeat($s, $depth+$x);
    }
    function topcat($row) { // used for the array_filter to weed out categories with parent != 0
    return $row['parent'] == 0;
    }

    ?>

    Tyssen
    Tyssen's picture
    Offline
    Moderator
    Brisbane
    Last seen: 5 years 25 weeks ago
    Brisbane
    Timezone: GMT+10
    Joined: 2004-05-01
    Posts: 8201
    Points: 1386

    When posting code, please

    When posting code, please post code sent to the browser, not the server-side code, ie, view source, copy & paste.

    In the meantime, you might find this useful.

    How to get help
    Post a link. If you can't post a link, jsFiddle it.
    My blog | My older articles | CSS Reference