Results 1 to 8 of 8

Thread: [UnResolved]CheckBox array Problem

  1. #1

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Resolved [UnResolved]CheckBox array Problem

    this script is a modification of a solution i was given for a similiar problem
    http://vbforums.com/showpost.php?p=2323616&postcount=7

    What im trying to do now... is list a table. The table is full of Links and menu's.

    This is how im trying to have it outputted.

    Navigation minRank: 0
    Home minRank: 0
    Members minRank: 0
    Console minRank: 1
    Forums minRank: 0
    Downloads minRank: 1
    All minRank: 1
    Images minRank: 1
    Exe minRank: 2
    Zip minRank: 1

    This is the script as it is currently. This is also confusing the ***** outa me and i dont know why.

    PHP Code:
    $sql "SELECT * FROM navigation_links WHERE menu_id = -1";
    $result mysql_query($sql) or die(mysql_error());
    $menus = array();

        while(
    $row mysql_fetch_array($result)) {
              
    $menus[] = $row;
        }
    //Tryed this to see if it'd work.
        
    foreach($menus as $menu){
            
    $sql1 "SELECT * FROM navigation_links  WHERE menu_id = '".$menu['link_id']."'";

             
    $result mysql_query($sql1) or die(mysql_error());
            
    $links = array();
            while(
    $row1 mysql_fetch_array($result)) {
              
    $links[$row1['menu_id']][] = array('id' => $row1['link_id'], 
                                                
    'name' => $row1['link_name'], 
                                              
    'url' => $row1['link_url'], 
                                              
    'minRank' => $row1['minRank']);
      
              }
          }

        foreach(
    $menus as $menu) { 
            echo
    '
        <div class="forum"> 
          <span class="name"><font color="orange">Menu :'
    $menu['link_name'].'</font></span> 
          <span class="description"> minRank:'
    .$menu['minRank'].'</span><br /> 
          <span class="mods">Menu Links:'
    ;
    //*
        
    foreach($links[$menu['id']] as $link) { 

              echo 
    'Mod:'.$link['link_name'].' : '.$link['link_url']. ' : '.$link['minRank']; 
            }
    //*/ 
        
    echo'</span></div><br />'

        } 
    Also this is my database table:
    PHP Code:
    CREATE TABLE `navigation_links` (
      `
    link_idtinyint(3NOT NULL auto_increment,
      `
    link_urlvarchar(50NOT NULL default '',
      `
    link_namevarchar(50NOT NULL default '',
      `
    menu_idtinyint(21NOT NULL default '0',
      `
    minRankint(11NOT NULL default '0',
      `
    disabledint(11NOT NULL default '0',
      
    PRIMARY KEY  (`link_id`)
    TYPE=MyISAM AUTO_INCREMENT=34 
    The problems i had... Were either all links and nav's would show.Or just nav's would show. Depending on what i changed in the query.

    Help is much needed and apperciated.

    EDIT:: RESOLVED

    Solution::

    PHP Code:
    $sql = 'SELECT * FROM navigation_links WHERE menu_id= -1';
    $result = mysql_query($sql) or die(mysql_error());
    $forums = array();
    while($row = mysql_fetch_array($result)) {
      $forums[] = $row;
    }
         
             $sql1 = "SELECT nav.*, nav2.* FROM navigation_links nav JOIN navigation_links nav2 ON nav2.menu_id = nav.link_id";

     $result = mysql_query($sql1) or die(mysql_error());
    $moderators = array();
    while($row1 = mysql_fetch_array($result)) {
      $moderators[$row1['menu_id']][] = array('url' => $row1['link_url'], 'name' => $row1['link_name']);
      
      }
      
    foreach($forums as $forum) { 
    ?> 
    <div class="forum"> 
      <span class="name"><?php echo $forum['link_name']; ?></span> 
      <span class="description"><?php echo $forum['link_url']; ?></span> 
      <span class="mods">Moderators: 
      <?php 
        
    foreach($moderators[$forum['link_id']] as $mod) { 
          
    ?> 
          <a href="userinfo.php?id=<?php echo $mod['url']; ?>"><?php echo $mod['name']; ?></a> 
          <?php 
        

      
    ?></span> 
    <?
    }
    it was this query that made it happen.
    PHP Code:
             $sql1 "SELECT nav.*, nav2.* FROM navigation_links nav JOIN navigation_links nav2 ON nav2.menu_id = nav.link_id"

    Check That...maybe NOt.
    Last edited by PlaGuE; Jun 8th, 2006 at 10:12 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  2. #2

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [RESOLVED] Foreach Problem.

    hmmm.... Well It works now... but i have another problem.


    I need to be able to disable/enable the links.... I was thinking of using a checkbox. Where checked would be disabled. And enabled would be unchecked.... But the problem with this is... if its already enabled... it will be disabled. And Vise Versa.

    Or a radio button system...But the snag there was... I click 1 radio button for enabled on 1 link.... and thats it... only does it for 1 link.


    This is the code i use now.

    PHP Code:
    <?php 
    function disabled_menus_links(){
     
            if(isset(
    $_POST['update_submit'])){ 

                    if(
    is_array($_POST['navigation'])){ 

                    foreach(
    $_POST['navigation'] as $id){ 

                    echo 
    $id

                    
    $query mysql_query"SELECT * FROM navigation_links WHERE link_id = $id); 

            while ( 
    $row mysql_fetch_array$query ) ) { 

                    if ( 
    $row['disabled'] == ) { 

                        
    mysql_query"UPDATE navigation_links SET disabled =  1 WHERE link_id = $id); 

                        echo
    'Disabled'

                        echo 
    $id ' == ' $row['link_id']; 

                        }  
                    
                    if ( 
    $row['disabled'] == ) { 

                        
    mysql_query"UPDATE navigation_links SET disabled =  0 WHERE link_id = $id); 

                        echo
    'Undisabled'

                        echo 
    $id ' == ' $row['link_id']; 

                       }  

                    }  

                }  

            }  

        }else{ 

                        
    $sql 'SELECT * FROM navigation_links WHERE menu_id= -1'

                        
    $result mysql_query$sql ) or die( mysql_error() ); 

                        
    $menus = array(); 

                while ( 
    $row mysql_fetch_array$result ) ) { 

                        
    $menus[] = $row

                      }  


                    
    $sql1 "SELECT nav.*, nav2.* FROM navigation_links nav JOIN navigation_links nav2 ON nav2.menu_id = nav.link_id"

                    
    $result mysql_query$sql1 ) or die( mysql_error() ); 

                    
    $links = array(); 

                    while ( 
    $row1 mysql_fetch_array$result ) ) { 

                    
    $links[$row1['menu_id']][] = array( 'id' => $row1['link_id'], 'url' => $row1['link_url'], 'name' => $row1['link_name'], 'disabled' => $row1['disabled'] ); 

                    }  

    echo
    '<form name="form1" method="post" action="' $_SERVER['REQUEST_URI'] . '"> 

      <table cellspacing="1" cellpadding="0" id="TABLE" class="table_width"> 

        <tr id="TRHEADER">'


    echo


            <td colspan="2"><div align="center"><font size="5">Disable/Enable Links or Menus </font></div></td> 

          '


    echo
    '</tr> 

        <tr id="TRHEADER"> 

          <td colspan="2">When you click to disable a &quot;menu&quot;, ALL links to that menu should be selected for disablement.Same goes for enabling a &quot;menu&quot;.<br /> 

    </td> 

        </tr> 

        <tr id="TRHEADER"> 

          <td width="85%"><div align="left">Menu/Link Name </div></td> 

          <td width="15%"><div align="center">Enable/Disable</div></td> 

        </tr>'


                foreach( 
    $menus as $menu ) { 

                echo


        <tr id="TRHEADER"> 

          <td width="85%">' 
    $menu['link_name'] . '</td> 

          <td><div align="center"> 

            <input type="checkbox" name="navigation[]" value="' 
    $menu['link_id'] . '" ' . ( $menu['disabled'] == 'checked':'' ) . '> 

          </div></td> 

        </tr> 

        '


            foreach( 
    $links[$menu['link_id']] as $link ) { 

            echo


        <tr> 

          <td width="85%" ID="TDROW1">' 
    $link['name'] . '</td> 

          <td ID="TDROW2"><div align="center"> 

            <input type="checkbox" name="navigation[]" value="' 
    $link['id'] . '" ' 

            ( ( 
    $link['disabled'] == || $menu['disabled'] == ) ? 'checked ':'' ) . 

            ( ( 
    $menu['disabled'] == ) ? ' disabled':'' ) . '> 

          </div></td> 

        </tr> 

        '


    }  

    }  

    echo


        <tr id="TRFOOTER">'


    echo


            <td height="25" colspan="2"><div align="center"> 

              <input name="update_submit" type=submit id="menuadded" value=\'Update Nagigation\' class="buttonlink"> 

            </div></td> 

        </tr> 

      </table> 

    </form>'


        }  

    }  

    ?>
    Last edited by PlaGuE; Jun 10th, 2006 at 04:24 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [UnResolved]CheckBox array Problem

    How big are your tabs?

    Also, don't use echo() to output HTML. Output is what PHP does anyway. Just close the php tags ?>.

    Now, I'm not fully understanding your second problem. When something's enabled, something's disabled... what? can you draw a bad picture of how you want it in Paint or something?

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [UnResolved]CheckBox array Problem

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [UnResolved]CheckBox array Problem

    I knew you would post that!

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [UnResolved]CheckBox array Problem

    Quote Originally Posted by penagate
    I knew you would post that!
    Doesn't my predictability sicken you? It does me.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [UnResolved]CheckBox array Problem

    I knew he'd post it too.
    Quote Originally Posted by penagate
    How big are your tabs?

    Also, don't use echo() to output HTML. Output is what PHP does anyway. Just close the php tags ?>.

    Now, I'm not fully understanding your second problem. When something's enabled, something's disabled... what? can you draw a bad picture of how you want it in Paint or something?
    Thats PHPEdits Code Beautifier for you.
    Also i dont care about what the inside looks like right now. I'll be going thru it and fixing things up when i finish the few problems im still having...
    Not to mention...That no one will be seeing the inside of the script anyways.Or so we are hoping. Im also slowly learning to indent properly.

    My Second Problem is like this.
    This problem is occuring in the "$_POST['update_submit'] IF Statement" at the top
    PHP Code:
                    if(is_array($_POST['navigation'])){ 

                    foreach(
    $_POST['navigation'] as $id){ 

                    echo 
    $id

                    
    $query mysql_query"SELECT * FROM navigation_links WHERE link_id = $id); 

            while ( 
    $row mysql_fetch_array$query ) ) { 

                    if ( 
    $row['disabled'] == ) { 

                        
    mysql_query"UPDATE navigation_links SET disabled =  1 WHERE link_id = $id); 

                        echo
    'Disabled'

                        echo 
    $id ' == ' $row['link_id']; 

                        }  
                    
                    if ( 
    $row['disabled'] == ) { 

                        
    mysql_query"UPDATE navigation_links SET disabled =  0 WHERE link_id = $id); 

                        echo
    'Undisabled'

                        echo 
    $id ' == ' $row['link_id']; 

                       }  

                    }  

                }  

            } 

    Like the image states.If i disable a link.An enabled Link will be disabled..But not all the time...Sometimes in order for the link to enable.Sumtin must be disabled....

    Im trying to find a solution.That in the end.Will allow me to enable and disable links.One at a time.And it needs to know whether im disabling or enabling a link or many links.

    Like i said...This is confusing.
    Attached Images Attached Images  
    Last edited by PlaGuE; Jun 10th, 2006 at 04:25 AM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

  8. #8

    Thread Starter
    Hyperactive Member PlaGuE's Avatar
    Join Date
    Jun 2005
    Location
    in ur mind.
    Posts
    445

    Re: [UnResolved]CheckBox array Problem

    There's gotta be a solution...
    Fixed up Code.However I still will be echo'ing the HTML.For Now.

    Pointless...this way seems...yet i've seen it done.Cant Remember where...tho.
    I'll try a different way...for now.



    What would be my best solution to doing what im trying to do? Instead of using checkbox's what else could i do....

    Idk why but... i cant seem to think.
    Last edited by PlaGuE; Jun 10th, 2006 at 12:36 PM.
    Without balance, there could only be chaos.
    Without chaos, there could be no balance.
    I live with karma. Eat with destiny. Dream of life without shackles....
    Yet. If life had no consequences, life could not exist, nor could it flourish.


    If at first you dont succeed.You're screwed.

    C++/Java NOOB.

    I aint a professional at PHP, but if i can help i will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width