943,545 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 714
  • PHP RSS
Jun 30th, 2009
0

need help with an array

Expand Post »
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:
PHP Syntax (Toggle Plain Text)
  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.
PHP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
sassenach is offline Offline
61 posts
since Mar 2009
Jun 30th, 2009
-2

Re: need help with an array

Please search in tutorialized.com
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Jun 30th, 2009
-1

Re: need help with an array

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 10
Junior Poster
jino is offline Offline
114 posts
since Feb 2008
Jun 30th, 2009
0

Re: need help with an array

What is your database layout like?

How are you handling the children? Do you have any logic in place for those.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Jul 1st, 2009
0

Re: need help with an array

ok so i got it to work. this works:
PHP Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
sassenach is offline Offline
61 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Automatically add a link & new page
Next Thread in PHP Forum Timeline: Upload File In Server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC