Topic: Kaip selectinti dabartiny array is formos poste

    if (isset($_POST['ups'])){

        $up = $_POST['ups'];//kaip cia paimt dabartiny array        
     echo 'UP'. $up;
    }


 echo "<td><button type='submit' name='ups[$i]' value='".$rec['id']."'>
              <img src='$img_up' alt='' width='16' height='16' /></button></td>";}

Re: Kaip selectinti dabartiny array is formos poste

Gercass, patikslink klausimą, kas tas "dabartinys array"? Array yra masyvas, jis turi savo elementus, gal tu apie juos kalbi?

Re: Kaip selectinti dabartiny array is formos poste

paspaudus ant butono poste is foreach loop gauti array kuri paspaudziau zinau kad taip aglima

Re: Kaip selectinti dabartiny array is formos poste

Gercass kažką apie kosmosą šneki. Kokį dar masyvą turi nori gauti iš masyvo "sukdamas" per ciklą? Tavo $_POST jau automatiškai po formos submitinimo yra masyvas.

Re: Kaip selectinti dabartiny array is formos poste

<h3>Puslapio meniu</h3>
<a href="<?php echo $l_return;?>"><img src="<?php echo $img_return;?>" alt="" />
<?php
 $l_menu_add = "main.php?page=menu&sw=add";
 $img_add = "tmp/admin/images/add.png";
?>    
<p>
    <a href="<?php echo $l_menu_add;?>"><img src="<?php echo $img_add;?>">Pridėti meniu</a>
</p>
<?php
    
    $tbl_name = "menu";
    
    ###################################
    ###NOTE: Keitimo vietom funkcija###
    ###################################

 require_once("lib/menu.php");
        
    $muve = new muve();    
        
    if (isset($_POST['up'])){

        $up = $_POST['up'];        
        $muve->up($up);
    }
    
 if (isset($_POST['down'])){

        $down = $_POST['down'];
        $muve->down($down);
    }

    if (isset($_POST['ups'])){
        $up  = $_POST['ups'];    
        $kup = key($_POST['ups']);//man ce reik zinot
     $muve->ups($kup, $up[1]);
    }
    
 if (isset($_POST['downs'])){
        $downs = $_POST['downs'];    
        $kdowns = key($_POST['downs']);//man ce reik zinot masyvo elemento numeri
     $muve->downs($kdowns, $downs[1]);
    }

    
    $rows = $db->fetch_array("SELECT * FROM `$tbl_name`");
    
    ###################################
    ###NOTE: pirmas ir paskutinis id###
    ###################################
    $f_id = $db->query_first("SELECT * FROM `$tbl_name` ORDER BY `id` ASC Limit 1");
    $f_id = $f_id['id'];

    
    $l_id = $db->query_first("SELECT * FROM `$tbl_name` ORDER BY `id` DESC Limit 1");
    $l_id = $l_id['id'];



 $tbl_name = "submenu";
    echo "<form action='main.php?page=menu&sw=' method='POST'>";
    echo "<table>";
    $img_up    = "tmp/menu/images/Up.png";
    $img_down  = "tmp/menu/images/Down.png";
    $l_sub_add = "main.php?page=menu&sw=sub_add";
    foreach ($rows as $rec){
        
        echo "<tr>";
        if ($rec['id'] == $f_id){echo "<td></td>";}else{
         echo "<td><button type='submit' name='up' value='".$rec['id']."'>
              <img src='$img_up' alt='' width='16' height='16' /></button></td>";}
        if ($rec['id'] == $l_id){echo "<td></td>";}else{ 
   echo "<td><button type='submit' name='down' value='".$rec['id']."'>
        <img src='$img_down' alt='' width='16' height='16' /></button></td>";}
      echo "<td><h3>".$rec['name']."</h3>";
      
 
 
 
 
 
       echo "<table>";
       
       $rows_ = $db->fetch_array("SELECT * FROM `$tbl_name` WHERE `uid`='{$rec['listorder']}'");
       $i = 1;
       foreach($rows_ as $rec_){



                    $f_id_ = $db->query_first("SELECT * FROM `$tbl_name` WHERE `uid`='{$rec['listorder']}' ORDER BY `id` ASC Limit 1");
                    $f_id_ = $f_id_['id'];

                    
                    $l_id_ = $db->query_first("SELECT * FROM `$tbl_name` WHERE `uid`='{$rec['listorder']}' ORDER BY `id` DESC Limit 1");
                    $l_id_ = $l_id_['id'];



        
                    echo "<tr>";
           if ($rec_['id'] == $f_id_){echo "<td></td>";}else{
           echo "<td><button type='submit' name='ups[$i]' value='".$rec_['id']."'>
              <img src='$img_up' alt='' width='16' height='16' /></button></td>";}
           if ($rec_['id'] == $l_id_){echo "<td></td>";}else{ 
     echo "<td><button type='submit' name='downs[$i]' value='".$rec_['id']."'>
         <img src='$img_down' alt='' width='16' height='16' /></button></td>";}

                     echo "<td><h3>".$rec_['name']."</h3></td>";
            echo "<td><a href=''>Redaguoti</a></td>";
            echo "<td><a href=''>Ištrinti</a></td>";
                    echo "</tr>";
                    
                }
                ++$i;
       echo "</table>";
      
      echo "</td>";
         echo "<td><a href='$l_sub_add&id=".$rec['id']."'>Pridėti sub menu</a></td>";
         echo "<td><a href=''>Redaguoti</a></td>";
         echo "<td><a href=''>Ištrinti</a></td>";
        echo "</tr>";
        
    }

 echo "</table>";
 echo "</form>";

?>

Re: Kaip selectinti dabartiny array is formos poste

Gercass wrote:

paspaudus ant butono poste is foreach loop gauti array kuri paspaudziau zinau kad taip aglima

Tu paspaudi mygtuką. PHP script'e tu turi kažkokį savo masyvą, tai gal tau pagal kažkokį tai id (indeksą) reikia atrinkti kuris masyvo elemtnas buvo parinktas?

Re: Kaip selectinti dabartiny array is formos poste

Jau padariau dabar nepagaunu kampo kita beda kai submeniu keiiu veitomis blogai gaunasi keiciasi ne tie kurie reikai kame esme va kodas.

<?php
class muve{
        
 function __construct(){
        $this->db = Database::obtain();
 }
     
 function up($id){
     $tbl_name = "menu";
     
     $row_min = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= ('$id' -1)");
     
     $row_ = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= '$id'");
     
     $data = array();
     
     $data['name']      = $row_min['name'];
     $data['listorder'] = $row_min['listorder'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_['id']}'");
     
     $data = array();
     $data['name']      = $row_['name'];
     $data['listorder'] = $row_['listorder'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_min['id']}'");
 }
 
 function down($id){
     $tbl_name = "menu";
     
     $row_min = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= ('$id' +1)");
     
     $row_ = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= '$id'");
     
     $data = array();
     
     $data['name']      = $row_min['name'];
     $data['listorder'] = $row_min['listorder'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_['id']}'");
     
     $data = array();
     $data['name']      = $row_['name'];
     $data['listorder'] = $row_['listorder'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_min['id']}'");
 }
 
 function ups($uid, $id){
     $tbl_name = "submenu";
     
     $row_min = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= ('$id'-1) AND `uid`='$uid'");
     
     $row_ = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= '$id' AND `uid`='$uid'");
     
     $data = array();
     
     $data['uid']  = $row_min['uid'];
     $data['name'] = $row_min['name'];
    
     
     $this->db->update($tbl_name, $data, "`id`='{$row_['id']}'");
     
     $data = array();
     $data['uid']  = $row_['uid'];
     $data['name'] = $row_['name'];

     
     $this->db->update($tbl_name, $data, "`id`='{$row_min['id']}'");
 }
 
 function downs($uid, $id){
     $tbl_name = "submenu";
     
     $row_min = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= ('$id' +1)AND `uid`='$uid'");
     
     $row_ = $this->db->query_first("SELECT * FROM `$tbl_name` WHERE `id`= '$id' AND `uid`='$uid'");
     
     $data = array();
          
     $data['uid']  = $row_min['uid'];
     $data['name'] = $row_min['name'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_['id']}'");
     
     $data = array();
     $data['uid']  = $row_['uid'];
     $data['name'] = $row_['name'];
     
     $this->db->update($tbl_name, $data, "`id`='{$row_min['id']}'");
 }
}
?>

8 (edited by Gercass 2012-11-23 22:12:34)

Re: Kaip selectinti dabartiny array is formos poste

** tiek parasiau daugiau nerasysiu. Sita tema off viskas veikia.

Re: Kaip selectinti dabartiny array is formos poste

Taip panašu, kad ne pats rašai, o kopijuoji svetimą kodą, nes klausimas elementarus. Tiesiog per anksti dar lipi ne į savo traukinį.

Re: Kaip selectinti dabartiny array is formos poste

neturiu laiko gincytis

Re: Kaip selectinti dabartiny array is formos poste

print_r($_POST);

enjoy!