html - PHP/MySQL - List rows with own radio button, then add all rows with selected radio button -


i'm absolutely stumped i'll try , explain best can.

i'd make attendance system web app i'm making (nothing public, closed personal system). want grab data 'users' table , display 'forename' , 'surname' on table. each 'name' have radio button group. this:

<?php  include "functions.php";  $query = "select * users order surname asc";  $result = mysql_query($query) or die(mysql_error());  $row = mysql_fetch_assoc($result);  ?>  <table>  <tr>  <td>name</td>  <td colspan="5"></td>  </tr>  <form id="form" name="form" method="post" action="process.php">  <?php { ?>  <tr>  <td><?php echo $row['forename']. ' ' .$row['surname']; ?></td>  <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_pu" value="pu" >pu</td>  <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_pc" value="pc">pc</td>  <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_aa" value="aa">aa</td>  <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_s" value="s">s</td>  <td><input type="radio" name="<?php echo $row['id']; ?>" id="<?php echo $row['id']; ?>_awol" value="awol">awol</td>  </tr>  <?php } while ($row = mysql_fetch_assoc($result)); ?>   </form>  </table>

now, have do, when press submit button, data, , add data table called attendance? want table this

id | user_id | record | date 1  | 1       | pu     | current_timestamp 

with id , date being automatic.

can shed light? i'm pretty new , tinkering around

many in advance

see edit below - answer real question instead messing depreciated fucntions.
here non-depecriated function example use :

(mysql functions depreciated, safer use pdo or mysqli).

<?php  // fill these infos correct parameters $servername = "localhost"; $username = "root"; $password = ""; $dbname = "";  include "functions.php"; $query = "select * users order surname asc";  $mysqli = new mysqli($servername, $username, $password, $dbname);  if ($mysqli->connect_error) { die('connexion error (' . $mysqli->connect_errno . ') '         . $mysqli->connect_error); }  $result = mysqli->query($query); 

remove line : $row = mysql_fetch_assoc($result); change : while ($row = mysql_fetch_assoc($result)); while ($row = $result->fetch_assoc());

if problem persists - might issue query. provide :

print "<pre>"; print_r($row); print "</pre>"; 

edit :

situation : u have carry id_student(int) + tag_student(str) (let's call them that) through <form>.

that means each radio button have carry 2 informations :

  • the related id_student
  • the tag

best display array :

    [array2insert] => array     (         [0] => array(                      [num_student] => 14                      [tag_student] => pu)         [1] => array(                      [num_student] => 15                      [tag_student] => pc) ) 

i tend using trick of using array name of radio button + formatting datas need stored using pattern : (id_student)_(tag_student).

example :

[array2insert] => array     (         [0] => 14_pu         [1] => 15_pc         [2] => 16_aa         [3] => 17_awol         [4] => 18_s     ) 

finally here's code : (i use int number_student make simple - replace classic loop result query loop)

<?php  if(isset($_post) && !empty($_post)) {     $pattern = '/(\d{1,})_(.*?)$/';      foreach($_post['array2insert'] $row)     {         preg_match($pattern, $row, $output);         echo "num student : " . $output[1] . " tag : " . $output[2] . "<br />";      }         print "<pre>";     print_r($_post);     print "</pre>"; } ?> <html> <body> <form action="" method="post">  <?php  $num_student = 14; for($i = 0; $i < 5; ++$i) { ?>     <table>     <tr>     <td><input type="radio" name="array2insert[<?php echo $i; ?>]"                value="<?php echo $num_student;?>_pu">pu</td>     <td><input type="radio" name="array2insert[<?php echo $i; ?>]"                value="<?php echo $num_student;?>_pc">pc</td>     <td><input type="radio" name="array2insert[<?php echo $i; ?>]"                value="<?php echo $num_student;?>_aa">aa</td>     <td><input type="radio" name="array2insert[<?php echo $i; ?>]"                value="<?php echo $num_student;?>_s">s</td>     <td><input type="radio" name="array2insert[<?php echo $i; ?>]"                value="<?php echo $num_student;?>_awol">awol</td>     </tr>     </table> <?php      ++$num_student;  } ?> <input type="submit" name="submit" value="get selected values" /> </form> </body> </html> 

example of output :

num student : 14 tag : pu num student : 15 tag : pc num student : 16 tag : aa num student : 17 tag : awol num student : 18 tag : s 

all datas went through $_post , extracted regex. hope helped.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -