need help with an array

Reply

Join Date: Mar 2009
Posts: 42
Reputation: sassenach is an unknown quantity at this point 
Solved Threads: 0
sassenach sassenach is offline Offline
Light Poster

need help with an array

 
0
  #1
Jun 30th, 2009
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:
  1. $editor->links = array(
  2. array('title'=>'Home', 'URL'=>'/'),
  3. array('title'=>'About Us','URL'=>'/about/', 'children'=>array(
  4. array('title'=>'Company History','URL'=>'/about/history.php'),
  5. array('title'=>'Franchise Information','URL'=>'/about/franchise.php'),
  6. array('title'=>'Shareholders Information','URL'=>'/about/shareholders.php'),
  7. )),
  8. array('title'=>'Services', 'URL'=>'/services/'),
  9. array('title'=>'Contact Us', 'URL'=>'/contact/'),
  10. );

So this is my SELECT query with the array. But i cant seem to get it right.
  1. $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());
  2. if(mysql_num_rows($menuQ) > 0){
  3. echo 'array(';
  4. while ($menuR = mysql_fetch_array($menuQ, MYSQL_ASSOC)) {
  5. //echo $menuR['title'].'<br/>';
  6. $mylinks[] = array('title'=>''.$menuR['title'].'', 'URL'=>'/?mid='.$menuR['menu_id'].'');
  7. }
  8. echo ');';
  9. $editor->links = array($mylinks);
  10. }

can anyone correct me please?

thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 219
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: need help with an array

 
-2
  #2
Jun 30th, 2009
Please search in tutorialized.com
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 90
Reputation: jino is an unknown quantity at this point 
Solved Threads: 6
jino's Avatar
jino jino is offline Offline
Junior Poster in Training

Re: need help with an array

 
-1
  #3
Jun 30th, 2009
  1. $result = mysql_query($sql);//execute query
  2. if(mysql_num_rows($result)>0)
  3. {
  4. $i=0;
  5. while($row=mysql_fetch_object($res))
  6. {
  7. $data[$i]['table_id'] = $row->table_id;
  8. $data[$i]['title'] = $row->table_title;
  9. $mylinks = $data[$i]['title'];
  10. $i++;
  11.  
  12. }
  13. }
Now $mylinks is an array having the values titles.
Hope this will do the work.
Last edited by peter_budo; Jul 1st, 2009 at 1:03 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
We only have to do a very few things right in our life, so long as we don't do too many things wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: need help with an array

 
0
  #4
Jun 30th, 2009
What is your database layout like?

How are you handling the children? Do you have any logic in place for those.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 42
Reputation: sassenach is an unknown quantity at this point 
Solved Threads: 0
sassenach sassenach is offline Offline
Light Poster

Re: need help with an array

 
0
  #5
Jul 1st, 2009
ok so i got it to work. this works:
  1. $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());
  2. if(mysql_num_rows($menuQ) > 0){
  3. while ($menuR = mysql_fetch_array($menuQ, MYSQL_ASSOC)) {
  4. $mylinks[] = array('title'=>''.$menuR['title'].'', 'URL'=>'/index.php?mid='.$menuR['menu_id'].'');
  5. }
  6. $editor->links = $mylinks;
  7. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC