Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks
Author Message
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Thu Feb 26, 2009 8:21 pm Reply with quote

I couldnt search for this as Im having one of those days where I wouldn't have a clue what to search for :(

Im building a simple menu block that will have main categories and sub links (only 1 sub level)


see the following table structure

Code:


DROP TABLE IF EXISTS nuke_menu_cat;
CREATE TABLE nuke_menu_cat (
  cid int(11) NOT NULL AUTO_INCREMENT,
  title varchar(50) NOT NULL DEFAULT '',
  parentid int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (cid)
) TYPE=MyISAM;

--
-- Dumping data for table 'nuke_menu_cat'
--


-- --------------------------------------------------------

--
-- Table structure for table 'nuke_menu'
--

DROP TABLE IF EXISTS nuke_menu;
CREATE TABLE nuke_menu (
  mid int(11) NOT NULL AUTO_INCREMENT,
  cid int(11) NOT NULL DEFAULT '0',
  title varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (mid),
  KEY cid (cid)
) TYPE=MyISAM;


can anyone give me some hints on the sql for it. I guess I need to query for the categories and then display the listings per category.Ive been playing all morning and come up with this so far.

Code:


global $prefix, $db, $admin, $user;

$content = '';
$ThemeSel = get_theme();

function get_subs($catid) {
    global $prefix, $db;
    $catid = intval($catid);
    $sql = 'SELECT * FROM '.$prefix.'_menu WHERE cid=\''.$catid.'\'';
    $result = $db->sql_query($sql);
  while ($row = $db->sql_fetchrow($result)) {
    $mid = intval($row['mid']);
    $title = stripslashes(check_html($row['title'], 'nohtml'));
   $content .= '<li>' . "\n";
   $content .= '<a href="#"><strong>'.$title.'</strong></a><br />';
   $content .= '<li>' . "\n";
   } 
}


$content .= '<div id="sidetree">' . "\n";
$content .= '<div class="treeheader">&nbsp;</div>' . "\n";
$content .= '<div id="sidetreecontrol"><a href="#">Collapse All</a> | <a href="#">Expand All</a></div>' . "\n";
$content .= '<ul id="tree">' . "\n";

$result2 = $db->sql_query('SELECT * FROM ' . $prefix . '_menu_cat');
while ($row2 = $db->sql_fetchrow($result2)) {
   $cid = stripslashes($row2['cid']);
    $title = stripslashes($row2['title']);
   $parentid = stripslashes($row2['parentid']);
   $content .= '<li><a href="#"><strong>'.$title.'</strong></a><ul>';
   echo '<pre>';
     var_dump(get_subs('1'));
     echo '</pre>';
   $content .= get_subs('1');
   $content .= '</ul></li>' . "\n";
}
$content .= '</ul></div></div>';


any ideas?
 
View user's profile Send private message
testy1







PostPosted: Fri Feb 27, 2009 12:50 am Reply with quote

Ok came back later and could see where I was going wrong (partly)

here's what Ive got and the code

Image


Code:



  if ( !defined('BLOCK_FILE') ) {
    Header( 'Location: ../index.php' );
    die();
  }

  global $prefix, $db, $admin, $user;

  $content = '';
  $ThemeSel = get_theme();

// Not Currently In Use
/*
function get_subs($catid) {
global $prefix, $db;
$catid = intval($catid);
$sql = 'SELECT * FROM '.$prefix.'_menu WHERE cid=\''.$catid.'\'';
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result)) {
$mid = intval($row['mid']);
$title = stripslashes(check_html($row['title'], 'nohtml'));
$content .= '<li>' . "\n";
$content .= '<a href="#"><strong>'.$title.'</strong></a><br />';
$content .= '<li>' . "\n";
}
}
*/

  $content .= '<div id="sidetree">' . "\n";
  $content .= '<div id="sidetreecontrol">' . "\n";
  $content .= '<a href="#">Collapse All</a> | <a href="#">Expand All</a>' . "\n";
  $content .= '</div>' . "\n";
  $content .= '<ul id="tree">' . "\n";

  $sql = $db->sql_query( 'SELECT c.cat, m.title FROM ' . $prefix . '_menu m LEFT JOIN ' . $prefix . '_menu_cat c ON c.cid = m.cid ORDER BY c.cat' );

// Oh I see what's Happening NOOOOOOOOOOOOOOOOOOOOOOOOOT

  while ( $result = $db->sql_fetchrow($sql) ) {

    $cat = stripslashes( $result['cat'] );
    $title = stripslashes( $result['title'] );

    $content .= '<li><a href="#"><strong>' . $cat . '</strong></a>' . "\n";
    $content .= '<ul>' . "\n";
    $content .= '<li><a href="#">' . $title . '</a></li>' . "\n";
  }

  $content .= '</ul></li></ul></div>' . "\n";





As you can see it displays categories more than once....And if I add another 15 links I will have to fly to the US to click it.
 
testy1







PostPosted: Fri Feb 27, 2009 1:37 am Reply with quote

ohhhhhhhhhhh


Image


Code:



  if ( !defined('BLOCK_FILE') ) {
    Header( 'Location: ../index.php' );
    die();
  }

  global $prefix, $db, $admin, $user;

  $catid = '';
  $content = '';

  function get_subs( $catid )
  {
    global $prefix, $db;
    $catid = intval( $catid );
    $sql = $db->sql_query( 'SELECT m.title FROM ' . $prefix . '_menu m LEFT JOIN ' . $prefix . '_menu_cat c ON c.cid = m.cid WHERE c.cid=\'' . $catid . '\'' );
    while ( $row = $db->sql_fetchrow($sql) ) {
      $title = stripslashes( check_html($row['title'], 'nohtml') );
      $content .= '<li><a href="#">' . $title . '</a></li>' . "\n";
    }
    return $content;
  }

  $content .= '<div id="sidetree">' . "\n";
  $content .= '<div id="sidetreecontrol">' . "\n";
  $content .= '<a href="#">Collapse All</a> | <a href="#">Expand All</a>' . "\n";
  $content .= '</div>' . "\n";
  $content .= '<ul id="tree">' . "\n";
  $sql2 = $db->sql_query( 'SELECT * FROM ' . $prefix . '_menu_cat ORDER BY cat ASC' );
  while ( $row2 = $db->sql_fetchrow($sql2) ) {
    $catid = stripslashes( intval($row2['cid']) );
    $cat = stripslashes( check_html($row2['cat'], 'nohtml') );
    $content .= '<li><strong>' . $cat . '</strong>' . "\n";
    $content .= '<ul>' . "\n";
    $content .= get_subs( $catid );
    $content .= '</ul></li>' . "\n";
  }
  $content .= '</ul></div>' . "\n";




Seems to be ok, Can this be done any better or am I super duper wooper leet with sugar on top Smile
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Blocks

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©