Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

variable and array

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

variable and array

Postby mohsenmatrix » Fri May 17, 2013 10:41 pm

hello! i want to make a php code for simple poll with Drop down list.in my php file when i increase y_value and echo i other side i see y_value didn't change!help me!
php file:
Code: Select all
<?php

   $poll=array("programming"=>array("1"=>0,"2"=>0,"3"=>0,"4"=>0,"5"=>0,"6"=>0),
            "logical"=>array("1"=>"0","2"=>"0","3"=>"0","4"=>"0","5"=>"0","6"=>"0"),
            "automata"=>array("1"=>"0","2"=>"0","3"=>"0","4"=>"0","5"=>"0","6"=>"0"),
            "compiler"=>array("1"=>"0","2"=>"0","3"=>"0","4"=>"0","5"=>"0","6"=>"0"));
   $first=$_POST['activity'];
   $second=$_POST['time'];
   
   
   function add(&$poll,&$first,&$second){
            foreach($poll as $x=>$x_value)
               if($x==$first){
                     foreach($x_value as $y=>$y_value)
                         if($y==$second){   
                           $y_value=$y_value+1;
                           }
                           $first++;
                           }
                           }
   
   add($poll,$first,$second);
         
                         echo $first."<br />";
         foreach($poll as $x=>$x_value)
            foreach($x_value as $y=>$y_value)
           {
           echo "Key=" . $x." value ".$y_value ;
           echo "<br>";
           }
      
      
?>



and this is my html file:
Code: Select all
<!DOCTYPE html>
<head>
<title>polling</title>
<style type="text/css">
   #pollform{
      text-align:center;
      background-color:#f6f8fd;
      margin:5px auto;
      padding:30px;
   }
</style>
</head>
 
<body dir="rtl">
<div id="pollform">
<form action="register.php" method="post">
which books you want?
   <select name="activity">
      <option value="programming">programming</option>
      <option value="logical">logical </option>
      <option value="automata">automata</option>
      <option value="compiler">compiler</option>
   </select>
   <br />
what time?
   <select name="time">
      <option value="1">8-9</option>
      <option value="2">9-10</option>
      <option value="3">10-11</option>
      <option value="4">11-12</option>
   </select>
<br />
   <input style="padding:10px; font:14px tahoma bold;" value="send" type="submit">
</form>
</div>
</body>
</html>
mohsenmatrix
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri May 17, 2013 10:40 pm

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron