Jump to content

need help with an array


sassenach

Recommended Posts

I am using wysiwygPro editor and i want to be able to display the menu titles coming from the database.

 

This is an example layout:

$editor->links = array(
    array('title'=>'Home', 'URL'=>'/'),
    array('title'=>'About Us','URL'=>'/about/', 'children'=>array(
        array('title'=>'Company History','URL'=>'/about/history.php'),
        array('title'=>'Franchise Information','URL'=>'/about/franchise.php'),
        array('title'=>'Shareholders Information','URL'=>'/about/shareholders.php'),
    )),
    array('title'=>'Services', 'URL'=>'/services/'),
    array('title'=>'Contact Us', 'URL'=>'/contact/'),
);

 

So this is my SELECT query with the array. But i cant seem to get it right.

$menuQ = mysql_query("SELECT menu_id, title FROM menu ORDER BY menu_id ASC") or trigger_error("Query: $menuQ\n<br />MySQL Error: " .mysql_error());				
if(mysql_num_rows($menuQ) > 0){
    echo 'array(';
    while ($menuR = mysql_fetch_array($menuQ, MYSQL_ASSOC)) {
            //echo $menuR['title'].'<br/>';
            $mylinks[] = array('title'=>''.$menuR['title'].'', 'URL'=>'/?mid='.$menuR['menu_id'].'');            
    }
    echo ');';
    $editor->links = array($mylinks);    
}

 

can anyone correct me please?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/164216-need-help-with-an-array/
Share on other sites

ok so i got it to work. this works:

$menuQ = mysql_query("SELECT menu_id, title FROM menu ORDER BY menu_id ASC") or trigger_error("Query: $menuQ\n<br />MySQL Error: " .mysql_error());               
if(mysql_num_rows($menuQ) > 0){
    while ($menuR = mysql_fetch_array($menuQ, MYSQL_ASSOC)) {
        $mylinks[] = array('title'=>''.$menuR['title'].'', 'URL'=>'/index.php?mid='.$menuR['menu_id'].'');           
    }
    $editor->links = $mylinks;
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.