Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[PHP] Array problem

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Mon Jul 21, 2008 2:39 pm    Post subject: [PHP] Array problem Reply with quote

Hey,

Well I'm really stuck.
I'm trying to build a dynamic menu with a template engine (Smarty).
It works perfectly with my static array:
For example:
Code:
   $content->assign('menu', array(array('Main-Menu' => array("http://www.google.de" => "Google.de", "http://www.google.com" => "Google.com"))));

template:
Code:
{foreach name=menu item=kontakt from=$menu}
  {foreach key=menutitle item=value from=$kontakt}
   <center><u>{$menutitle}</u></center>
   {foreach key=link item=title from=$value}
      <center><a href="{$link}">{$title}</a></center>
   {/foreach}
  {/foreach}
{/foreach}


Will display:
Quote:
Main-Menu
Google.de
Google.com


Works fine.
But I want to read the menu out of the MySQL.
So there is a table for Menu-Sections (Main-Menu in this case) and a table for MenuItems (google.de, google.com in this case).
So my function so far is:
Code:
function GetMenu($sql){
   $result = $sql->query("SELECT * FROM site_menu ORDER BY position ASC");
   if(mysql_num_rows($result) > 0) {
      while($row = mysql_fetch_assoc($result)){
         $id = $row['id'];
         $title = $row['title'];
         $menuresult = $sql->query("SELECT * FROM site_menuitems WHERE menuid= $id ORDER BY position ASC");
         if(mysql_num_rows($menuresult) > 0) {
            while($menurow = mysql_fetch_assoc($menuresult)){
               $temp[] = array($menurow['link'] => $menurow['title']);
            }
         }
         $menu[] = array($title => $temp);
      }
   }
   return $menu;
}


Displays
Quote:
Main-Menu
Array
Array


Then I found it it's because of this line
Code:
$menu[] = array($title => $temp);

Because when I'm using this:
Code:
$menu[] = array($title => $temp[0]);

It shows the Main-Menu with the first Google link (.de in this case)

How can I fix this?

Edit:
Ohwut, I finally got it. After like 1.5 hours of trying I finally got it.
Code:
$temp[] = array($menurow['link'] => $menurow['title']);

=
Code:
$temp[$menurow['link']] = $menurow['title'];


(Mod can close)
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Tue Jul 22, 2008 1:22 pm    Post subject: Reply with quote

Closed due to request of OP. Smile
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites