954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need help with an array

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\nMySQL 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

sassenach
Junior Poster in Training
61 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

Please search in tutorialized.com

ayesha789
Posting Pro in Training
496 posts since Jun 2009
Reputation Points: 17
Solved Threads: 7
 
$result		= mysql_query($sql);//execute query
if(mysql_num_rows($result)>0)
{
	$i=0;
	while($row=mysql_fetch_object($res))
	{	
		$data[$i]['table_id']	= $row->table_id;
		$data[$i]['title']		= $row->table_title;
		$mylinks				= $data[$i]['title'];
		$i++;
		
	}
}

Now $mylinks is an array having the values titles.
Hope this will do the work.

jino
Junior Poster
117 posts since Feb 2008
Reputation Points: 10
Solved Threads: 10
 

What is your database layout like?

How are you handling the children? Do you have any logic in place for those.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

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\nMySQL 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;
}
sassenach
Junior Poster in Training
61 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You