Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

choose a user of the list (loop)

Tags:

sql

php

mysql

here i fetched all information of my users with a loop. as you see my table is like this:

enter image description here

and my code is this:

  <?php
$id=$fgmembersite->UserID(); 

/* echo "$id"; */


$db_host = 'localhost';
$db_name= 'site';
$db_table= 'tablesite';
$db_user = 'root';
$db_pass = '';


$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET  utf8");

$dbresult=mysql_query("SELECT tablesite.name,
                              tablesite.family,
                              tablesite.username,
                              tablesite.phone_number,
                              tablesite.email
                       FROM  $db_table",$con);
   $i = 1;

                       while($amch=mysql_fetch_assoc($dbresult))

{?>
  <?php

echo "<form name=f1 id='form_$i' method='post' action='{$_SERVER['PHP_SELF']}' accept-charset='UTF-8'>\r\n";
echo'<div dir="rtl">';
echo "نام خدمت دهنده: "."&nbsp&nbsp&nbsp".$amch["name"]." ".$amch["family"]."&nbsp&nbsp&nbsp"."شماره تماس: ".$amch["phone_number"]."&nbsp&nbsp&nbsp"."ایمیل: ".$amch["email"].'<br>';
echo '<input type="submit" name="submit" value="انتخاب مشتری"/>';echo'<hr/>';
echo'<hr/>';
echo'</div>';
echo "</form>\r\n";
    $i++;
}
?>


  <?php
if(isset($_POST['submit']))
{ 

}
?>

for each user, there is a button for choosing hem/her (for send him/her information to another page)

this is a part of printing user's information with button for each one of them. enter image description here

i just do not know how to choose that buddy and send selected information to another page. thanks

like image 470
sammy Avatar asked Nov 14 '15 18:11

sammy


1 Answers

You can add a hidden input with the value of that buddy. For example (I only added the email field, but you can extend this however you need):

echo "<form name=f1 id='form_$i' method='post' action='{$_SERVER['PHP_SELF']}' accept-charset='UTF-8'>\r\n";
echo'<div dir="rtl">';
echo "نام خدمت دهنده: "."&nbsp&nbsp&nbsp".$amch["name"]." ".$amch["family"]."&nbsp&nbsp&nbsp"."شماره تماس: ".$amch["phone_number"]."&nbsp&nbsp&nbsp"."ایمیل: ".$amch["email"].'<br>';
echo '<input type="submit" name="submit" value="انتخاب مشتری"/>';echo'<hr/>';
echo'<hr/>';
echo'</div>';
echo '<input type="hidden" name="email" value="' . $amch["email"] . '">'; // SEND THE EMAIL ADDRESS IN THE "email" FIELD
echo "</form>\r\n";
like image 177
Alon Eitan Avatar answered Sep 30 '22 18:09

Alon Eitan