PHP table in collapse - php

I'm having trouble to collapse the next row in table. My code works only for the first row of the table where ever I click the collapse button.
Code :
<table id="yourEvent" class="table table-hover">
<thead>
<tr>
<td style="text-align: center" width="20px"><strong>No.</strong></td>
<td><strong>Attendee Name</strong></td>
</tr>
</thead>
<?php while($row = mysqli_fetch_array($resultAttendeeList))
{ ?>
<tbody>
<tr>
<td class="counterCell" style="text-align: center" width="20px"></td>
<td><button type="button" class="btn btn-xs bg-maroon" style="width: 20px" data-toggle="collapse" data-target="#divCol"><i class="fa fa-plus"></i></button> <?php echo $row['fullname'];?>
<div class="collapse" id="divCol">
<table>
<tr>
<td>Address: <?php echo $row['address']; ?></td>
</tr>
<tr>
<td>Contact: 0<?php echo $row['contact']; ?></td>
</tr>
</table>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>

You are using same ID for multiple divs in your loop. You can create incremental int variable and concatenate in your div IDs.
try this code: added $ctr variable increments through loop. Also, you should start your loop after the <tbody> tag.
<tbody>
<?php $ctr=1;
while($row = mysqli_fetch_array($resultAttendeeList))
{ ?>
<tr>
<td class="counterCell" style="text-align: center" width="20px"></td>
<td><button type="button" class="btn btn-xs bg-maroon" style="width: 20px" data-toggle="collapse" data-target="#divCol_<?=$ctr?>"><i class="fa fa-plus"></i></button> <?php echo $row['fullname'];?>
<div class="collapse" id="divCol_<?=$ctr?>">
<table>
<tr>
<td>Address: <?php echo $row['address']; ?></td>
</tr>
<tr>
<td>Contact: 0<?php echo $row['contact']; ?></td>
</tr>
</table>
</div>
</td>
</tr>
<?php $ctr=$ctr+1; } ?>

Please try this is complete code. Please give dynamic id. make sure when you process any jquery/javascript operation, divid should always unique. Otherwise event will not bind for all element.
<?php
$servername = "host";
$username = "user";
$password = "pass";
// Create connection
$conn = mysqli_connect($servername, $username, $password, 'testdb');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM table ORDER BY ID limit 5";
$result = mysqli_query($conn, $sql);
// Numeric array
//$row = mysqli_fetch_array($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<table id="yourEvent" class="table table-hover">
<thead>
<tr>
<td style="text-align: center" width="20px"><strong>No.</strong></td>
<td><strong>Attendee Name</strong></td>
</tr>
</thead>
<tbody>
<?php
$j = 1;
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td class="counterCell" style="text-align: center" width="20px"><?php echo $j; ?></td>
<td>
<button type="button" class="btn btn-xs bg-maroon" style="width: 20px" data-toggle="collapse" data-target="#divCol_<?php echo $j; ?>">
<i class="fa fa-plus"></i>
</button> <?php echo $row['EMP_FULLNAME']; ?>
<div class="collapse" id="divCol_<?php echo $j; ?>">
<table>
<tr>
<td>Address: <?php echo $row['EMP_ADDRESS']; ?></td>
</tr>
<tr>
<td>Contact: 0<?php echo $row['EMP_MOBILE']; ?></td>
</tr>
</table>
</div>
</td>
</tr>
<?php
$j++;
}
?>
</tbody>
</table>
</body>
</html>

Related

My modal is displayed but there is no content inside the displayed modal

I want to include a simple bootstrap modal. The code is minimal, but there seems to be something wrong.
When I click the view button the modal is displayed but no data shows up in it.
This is my index.php:
<?php
$connect = mysqli_connect("localhost", "root", "", "baps");
$query = "SELECT * FROM tab_organizers";
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Webslesson Tutorial | Bootstrap Modal with Dynamic MySQL Data using Ajax &
PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">
</script>
</head>
<body>
<br /><br />
<div class="container" style="width:700px;">
<h3 align="center">Visitor's List</h3>
<br />
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th width="70%">Group Name</th>
<th width="30%">View</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["GroupName"]; ?></td>
<td><input type="button" name="view" value="view" id="<?php echo
$row["id"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Visitor Details</h4>
</div>
<div class="modal-body" id="visitor_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var OrganizerID = $(this).attr("id");
$.ajax({
url:"select.php",
method:"post",
data:{OrganizerID:OrganizerID},
success:function(data){
$('#visitor_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
This is my select.php:
<?php
if(isset($_POST["OrganizerID"]))
{
$output = '';
$connect = mysqli_connect("localhost", "root", "", "baps");
$query = "SELECT * FROM tab_organizers WHERE OrganizerID = '".$_POST["OrganizerID"]."'";
$result = mysqli_query($connect, $query);
$output .= '
<div class="table-responsive">
<table class="table table-bordered">';
while($row = mysqli_fetch_array($result))
{
$output .='
<tr>
<td><label>Record Entered on: </label></td>
<td>'.$row["Datetimestamp"].'</td>
</tr>
<tr>
<td><label>Organizer ID: </label></td>
<td>'.$row["OrganizerID"].'</td>
</tr>
<tr>
<td><label>Group Name</label></td>
<td>'.$row["GroupName"].'</td>
</tr>
<tr>
<td><label>Contact Name</label></td>
<td>'.$row["ContactName"].'</td>
</tr>
<tr>
<td><label>House or Apartment #: </label></td>
<td>'.$row["Address1"].'</td>
</tr>
<tr>
<td><label>Street Name: </label></td>
<td>'.$row["Address2"].'</td>
</tr>
<tr>
<td><label>City: </label></td>
<td>'.$row["City"].'</td>
</tr>
<tr>
<td><label>Province: </label></td>
<td>'.$row["Province"].'</td>
</tr>
<tr>
<td><label>Postal Code: </label></td>
<td>'.$row["PostalCode"].'</td>
</tr>
<tr>
<td><label>Country: </label></td>
<td>'.$row["Country"].'</td>
</tr>
<tr>
<td><label>Title or Profession: </label></td>
<td>'.$row["Title"].'</td>
</tr>
<tr>
<td><label>Home or Office #: </label></td>
<td>'.$row["Telephone1"].'</td>
</tr>
<tr>
<td><label>Cell Number: </label></td>
<td>'.$row["Telephone2"].'</td>
</tr>
<tr>
<td><label>Fax Number: </label></td>
<td>'.$row["FaxNumber"].'</td>
</tr>
<tr>
<td><label>School Email Address: </label></td>
<td>'.$row["SchoolGeneralEmail"].'</td>
</tr>
<tr>
<td><label>Personal Email Address: </label></td>
<td>'.$row["Email"].'</td>
</tr>
<tr>
<td><label>How did you hear about us: </label></td>
<td>'.$row["HowDidYouHear"].'</td>
</tr>
<tr>
<td><label>Santo`s or Karyakar`s Comments on this Organizer</label></td>
<td>'.$row["Comments"].'</td>
</tr>
<tr>
<td><label>Diwali Invites to be send?</label></td>
<td>'.$row["Diwaliinvites"].'</td>
</tr>
<tr>
<td><label>Subscribe to BAPS mailing list?</label></td>
<td>'.$row["SubscribedToMailingList"].'</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
my database column names are as follows: OrganizerID(int(11))
GroupName(varchar(240)) ContactName(varchar(50)) Address1(varchar(50))
Address2(varchar(50)) City(varchar(50)) Province(varchar(50))
PostalCode(varchar(50)) Country(varchar(50)) Title(varchar(50))
Telephone1(varchar(50)) Telephone2(varchar(50)) FaxNumber(varchar(50))
SchoolGeneralEmail(varchar(50)) Email(varchar(100))
SubscribedToMailingList(bit(1)) HowDidYouHear(varchar(50))
Comments(mediumtext) Datetimestamp(datetime) Diwaliinvites(bit(1))

Get php checkbox data from multiple tables

First I will tell what I want to achieve, and then I will explain how I was trying to do it.
I have two tables, one stores type of vessels with a description and their own Id. Then I have another table in wich the vessel type has been stored as text. My goal is to select each one (both records in both tables) with a checkbox in both and store in the table 2 the Id from the table 1.
I will introduce data, to help.
Table 1
1|Balandra|Some description
2|Bergantin|Some description
3|Whatever |Whatever.....
Table2
Balandra
Bergantin
Whatever
Then, I have created a php page that shows both tables with the checkbox I mentioned above. Checkboxes store the Table1 Id and Table2 vesseltypename.
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<a href=<?php echo '../vista/modificar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
pencil"></em></a>
<a href=<?php echo '../datos/borrar.php?id=' .
$navio['idtiponavio']; ?> class="btn btn-default"><em class="fa fa-
trash"></em></a>
</td>
<td class="hidden-xs"><?php echo
$navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid" value=<?
php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body paneltodo">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
So, I want to check both table records and store the table1 Id in the table2 idtypevessel field.
I thought that a php file could store both items and call the update function with those parameters, like this:
<?php
require './modelo.php';
$idnavio = $_GET['agruparid'];
$vessel = $_GET['agruparvessel'];
Any suggestions, because I think I have to do a button to submit this parameters, but it must be working on both tables, and I don't know how to access both foreach loop at the same time.
Thanks in advance.
E. Salas
review bellow reference code to submit multi selected checkbox values
for multi selected checkbox submission you must use [] operator after name attribute in html
index.php
<form action="/checkbox.php" method="post">
<strong>Cars:</strong><br>
<?php
$cars = array("Volvo", "BMW", "Toyota");
$colors = array("Red", "Green", "Black");
foreach($cars as $single){
?>
<input type="checkbox" name="cars[]" value="<?php echo $single; ?>">
<?php
}
<br>
<strong>colors:</strong><br>
foreach($colors as $single){
?>
<input type="checkbox" name="colors[]" value="<?php echo $single; ?>">
<?php
}
?>
<br>
<input type="submit" value="Submit!">
</form>
checkbox.php
<?php
echo "<pre>";
var_dump($_POST);
exit;
In your case:
<form action="/checkbox.php" method="post">
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th class="hidden-xs">idtiponavio</th>
<th>Tipo de Navío</th>
<th>Descripción</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosdyncoop as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-pencil"></em>
<em class="fa fa-trash"></em>
</td>
<td class="hidden-xs"><?php echo $navio['idtiponavio']; ?></td>
<td><?php echo $navio['tiponavio']; ?></td>
<td><?php echo $navio['descripcion']; ?></td>
<td><input type="checkbox" name="agruparid[]" value=<?php echo $navio['idtiponavio']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-md-6">
<div class="panel-body">
<table class="table table-striped table-bordered table-list">
<thead>
<tr>
<th><em class="fa fa-cog"></em></th>
<th>Tipo de Navío</th>
<th>Agrupar</th>
</tr>
</thead>
<tbody>
<?php foreach ($naviosforsea as $key => $navio) { ?>
<tr>
<td align="center">
<em class="fa fa-arrow-circle-o-left"></em>
</td>
<td><?php echo $navio['typevessel']; ?></td>
<td><input type="checkbox" name="agruparvessel[]" value=<?php echo $navio['typevessel']; ?> /></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<input type="submit" value="Submit!">
</form>
Finally I solved this with Javascript. One of my partners helped me, I post this to help people in my situation.
I created a script, here is the code:
<script type="text/javascript">
function cogeNavioDyncoopnet(){
var checkedValueNavioD = null;
var inputElements = document.getElementsByClassName('checknaviod');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioD = inputElements[i].value;
break;
}
}//return checkedValueNavioD;
var input_nav_dyn = document.getElementById("nav_dyn");
input_nav_dyn.value = checkedValueNavioD;
}
function cogeNavioForSea(){
var checkedValueNavioFs = null;
var inputElements = document.getElementsByClassName('checknaviofs');
for(var i=0; inputElements[i]; ++i){
if(inputElements[i].checked){
checkedValueNavioFs = inputElements[i].value;
break;
}
}//return checkedValueNavioFs;
var input_nav_fs = document.getElementById("nav_fs");
input_nav_fs.value = checkedValueNavioFs;
}
</script>
Then I created a Form below, that collects values and sends them to my .php control file.
<div class="hidden-xs">
<form class="hidden-xs" method="POST"
action="../datos/actualizarnavios.php">
<input id="nav_dyn" type="text" name="idnaviodyncoop">
<input id="nav_fs" type="text" name="navioforsea" >
<input id="botonasignar" type="submit" name="enviardatosdynfs">
</form>
</div>
I hope this helps. Thanks for the feedback, as always.

php code to retrieve data from mysql database and display in html table

I want to retreive information in MySQL database and display it html table.when i try with this code i get error message.i cant resolve that.i am new to php.help me. here is my code
<?php
session_start();
?>
<?php
$conn = mysqli_connect("localhost","root","","doctor");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST['button'])) {
$sql="select Mid,Mname,Mnic,amount,month,bank from payments ";
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Approvals</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<br>
<br>
<div class="table-responsive">
<table id="mytable" class="table table-bordred table-striped" border="1">
<thead style="background-color: sandybrown">
<th><input type="checkbox" id="checkall" /></th>
<th>Doctor ID</th>
<th>Doctor Name</th>
<th>Payment Type</th>
<th>Mobile Number</th>
<th>Email</th>
<th>Pay Date</th>
</thead>
<tbody>
<tr>
<td><input type="checkbox" class="checkthis" /></td>
<?php
while( $row = mysqli_fetch_assoc($sql)): ?>
<td > <?php echo $row['Mid']; ?> </td >
<td > <?php echo $row['Mname']; ?></td >
<td > <?php echo $row['Mnic']; ?> </td >
<td > <?php echo $row['amount']; ?></td >
<td > <?php echo $row['month']; ?> </td >
<td ><?php echo $row['bank']; ?></td >
</tr >
<?php endwhile ?>
</tbody>
</table>
<div class="form-group " align="center">
<a style="box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);border: 2px solid #4CAF50;background-color: white;color: black;width: 15%; float: right" href="#" target="_blank" type="button" id="button" name="button" class="btn btn-primary btn-lg btn-block login-button">Submit</a>
</div>
</div>
</div>
</div>
</body>
</html>
I agree with the other answers but before that you need to actually query.
your $sql="select Mid,Mname,Mnic,amount,month,bank from payments "; is just a string within the if block.
set
$sql="";
outside.
if (isset($_POST['button'])) {
$sql="select Mid,Mname,Mnic,amount,month,bank from payments ";
}
And call
$res = mysqli_query($conn,$sql);
and
while( $row = mysqli_fetch_assoc($res))
You closed the connection too early. The connection must be open while iterating over the items.
Remove this line :
conn->close();
if this do not works specify that error clearly.
and add this line after endwhile after
<?php endwhile;
mysqli_close();
?>

Update specific column in loop

Is this the right way to update a specific column for one row in mysqli_array_fetch? It doesn't work for me.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row[id] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row[name] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row[ticketnumber] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row[email] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row[subject] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$repsonse = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
after editing, I think I did it in wrong again
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {border: 1px solid black; text-align:center}
.contents { position:static}
p1 {font-size:15px; font-weight:bolder}
.inputresponse {resize:none}
.inputid {text-align:center; font-size:10px}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td> <input value="<?php echo $row['id'] ?>" name="id" class="inputid" readonly> </td>
<tr>
<tr>
<td> <p1> الإسم </p1> </td>
<tr>
<td> <?php echo $row['name'] ?> </td>
</tr>
<tr>
<td> <p1> رقم التذكرة</p1> </td>
</tr>
<tr>
<td> <?php echo $row['ticketnumber'] ?> </td>
</tr>
<tr>
<td> <p1> الإيميل</p1> </td>
</tr>
<tr>
<td> <?php echo $row['email'] ?> </td>
</tr>
<tr>
<td> <p1> الموضوع </p1> </td>
</tr>
<tr>
<td> <?php echo $row['subject'] ?> </td>
</tr>
<tr>
<td> <p1> الرد </p1> </td>
</tr>
<tr>
<td> <textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea> </td>
</tr>
<tr>
<td> <input type="submit" value="إرسال" name="send"> </td>
</tr>
<tr>
<td>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = ("UPDATE contact SET response ='$response' WHERE id= $row[id]");
$rst = mysqli_query($con,$result);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
}
}
}
?>
</form>
</table>
</div>
</body>
</html>
Your HTML formatting is strange but I think this should accomplish what you want.
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>الرد على التذكرة</title>
<style>
.table, tr, td {
border: 1px solid black;
text-align:center
}
.contents {
position:static
}
p1 {
font-size:15px;
font-weight:bolder
}
.inputresponse {
resize:none
}
.inputid {
text-align:center;
font-size:10px
}
</style>
</head>
<body class="body">
<div class="contents" align="right">
<?php
include 'config.php';
$sql = "SELECT * FROM contact ORDER BY id";
$con->set_charset('utf8');
$users = mysqli_query($con,$sql);
?>
<table class="table">
<?php
while($row = mysqli_fetch_array($users)) {
?>
<form id="<?php echo $row['id'] ?>" method="post" name="respone" action="addresponse.php">
<tr>
<td><input value="<?php echo $row['id'] ?>" name="id" class="inputid" type="hidden"></td>
<tr>
<tr>
<td><p1> الإسم </p1></td>
<tr>
<td><?php echo $row['name'] ?></td>
</tr>
<tr>
<td><p1> رقم التذكرة</p1></td>
</tr>
<tr>
<td><?php echo $row['ticketnumber'] ?></td>
</tr>
<tr>
<td><p1> الإيميل</p1></td>
</tr>
<tr>
<td><?php echo $row['email'] ?></td>
</tr>
<tr>
<td><p1> الموضوع </p1></td>
</tr>
<tr>
<td><?php echo $row['subject'] ?></td>
</tr>
<tr>
<td><p1> الرد </p1></td>
</tr>
<tr>
<td><textarea name="response" rows="5" dir="rtl" class="inputresponse"> </textarea></td>
</tr>
<tr>
<td><input type="submit" value="إرسال" name="send"></td>
</tr>
</form>
<?php
}
?>
</table>
<?php
if(isset($_POST['send'])){
$response = $_POST['response'];
$result = "UPDATE contact SET response = ? WHERE id= ?";
$rst = mysqli_prepare($con,$result);
mysqli_stmt_bind_param($rst, 'si', $response, $_POST['id']);
mysqli_stmt_execute($rst);
if($rst){
echo "تم الإرسال";
} else {
echo " لم يتم الإرسال";
echo mysqli_stmt_error($rst);
}
}
?>
</div>
</body>
</html>
Changes/potential improvements:
Using prepared statements in place of inline values.
Moved update outside of while loop since it is irrelevant.
Moved closing form tag inside the while loop. As is you were making multiple forms but every one was a child of the first because it never closed.
The p1s look like they might be headings? If so they should be outside of the loop.
If you want to display a message next to the row that was updated you could move the whole update process before the page process. Assign it to a variable the status to a variable then in the outputting when you are on that record output the message as well.
Your table rows seem to be closing incorrectly.

mysql_fetch_array(), is not work in my program

i need to fetch multiple row or single row from mysql table, but my code retrieve data from table only multiple rows as given in my where clause condition is true, not fetch single row even my condition is true. plz suggest me anyone. (i know only little bit english)
<?php
include 'connection/db_connection.php';
$sqlquery=mysql_query("select * from sadmin_invoiceno order by sno desc");
$row1=mysql_fetch_assoc($sqlquery);
$invoice=$row1['invoice_no'];
/* if($row1['invoice_no']<=9)
{
$myvalue=$row1['invoice_no'];
$idvalue="".$myvalue;
}
if($row1['invoice_no']>9 && $row1['sno']<100)
{
$myvalue=$row1['invoice_no'];
$idvalue="".$myvalue;
} */
$sql="SELECT * FROM sadmin_sales where invoice_no='".$invoice."'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>IT Flower invoice</title>
<link rel="stylesheet" href="assets/css/style_popup.css" media="all" />
<link href="assets/css/utopia-white.css" rel="stylesheet">
</head>
<body>
<div class="invoice">
<header class="clearfix">
<div id="logo">
<img src="assets/img/utopia-logo1.png">
</div>
<div id="company">
<h2 class="name">Indian Traditional Flowers</h2>
<div>10 - 3500 McNicoll Ave., <br>Toronto, Ontario ON M1V 4c7</div>
<div>+1.647.836.9999</div>
<div>info#itflowers.com</div>
</div>
</header>
<main>
<div id="details" class="clearfix">
<div id="client">
<div class="to">INVOICE TO:</div>
<h2 class="name"><?php
$sql2=mysql_query("SELECT franchies, customer FROM sadmin_sales where invoice_no='".$invoice."'");
$res1=mysql_fetch_array($sql2);echo $res1['customer'];
$franchies= $res1['franchies'];
$sql3=mysql_query("SELECT * FROM sadmin_customer where email='".$franchies."'");
$res2=mysql_fetch_array($sql3);
echo $res2['shop_name'];
?></h2>
<div class="address"> <?php echo $res2['owner_name']; ?> </div>
<div class="address"><?php echo $res2['address']; ?></div>
<div class="email"><?php echo $res2['email']; ?></div>
<div class="email"><?php echo $res2['phone']; ?></div>
</div>
<div id="invoice">
<h1>INVOICE NO: <?php echo $invoice; ?></h1>
<div class="date">Date of Invoice: <?php echo $date = date('d/m/Y h:i:s a'); ; ?></div>
</div>
</div>
<table class="inventory" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr style="text-align: center;">
<th class="no">#</th>
<th class="desc">DESCRIPTION</th>
<th class="unit">UNIT PRICE</th>
<th class="qty">QUANTITY</th>
<th class="total">TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$tax=0;
$ship=0;
$paid=0;
$bal=0;
$grand=0;
$sum=0;
for($i=1; $i<$count;)
{
while($row = mysql_fetch_array($result))
{
$franchies = $row['franchies'];
echo "<td class='no'>".$i."</td> ";
echo "<td class='desc'>" . $row['product_name'] . "</td>";
echo "<td class='unit'>" . $row['unit_price'] . "</td>";
echo "<td class='qty'>" . $row['quantity'] . "</td>";
echo "<td class='total' >".$row['total']."</td>";
echo "</tr>";
$sum=$sum + $row['total'];
$i++;
//$tax=$sum *.13;
$include=$row['tax_type'];
if ($include =='includetax')
{
$tax1=mysql_query("select * from sadmin_tax where tax_type like 'include%'");
$res1=mysql_fetch_array($tax1);
$tax2=$res1['percentage'];
$tax=$sum * $tax2/100;
$sum1=$sum - $tax;
}
else
{
$tax3=mysql_query("select * from sadmin_tax where tax_type like 'exclude%'");
$res3=mysql_fetch_array($tax3);
$tax4=$res3['percentage'];
$tax=$sum * $tax4/100;
$sum1=$sum + $tax;
}
$ship=$row['shipping_amt'];
$paid=$row['paid_amt'];
$grand=$sum1 + $ship;
$bal=$grand - $paid;
}
}
?>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td colspan="2">SUBTOTAL</td>
<td>$ <?php echo $sum; ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">TAX 13%</td>
<td>$ <?php echo $tax; ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">SHIP</td>
<td>$<?php echo $ship; ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">PAID</td>
<td>$<?php echo $paid; ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">BALANCE</td>
<td>$<?php echo $bal; ?></td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">GRAND TOTAL</td>
<td>$<?php echo $grand; ?></td>
</tr>
</tfoot>
</table>
<button onclick="myFunction()" class="btn btn-primary" style="width: 106px;float: right;">Print this page</button>
<!-- <div id="thanks">Thank you!</div>
<div id="notices">
<div>NOTICE:</div>
<div class="notice">A finance charge of 1.5% will be made on unpaid balances after 30 days.</div>
</div>
</main>
<footer>
Invoice was created on a computer and is valid without the signature and seal.
</footer> -->
</div>
<script>
function myFunction() {
window.print();
}
</script>
</body>
</html>
I'm not certain I understand your question fully, are you saying you have multitple rows but only want one?
If so , check out MySQL "LIMIT " which will limit your SQL query to X number of rows, such as SELECT * FROM sadmin_customer where email='".$franchies." LIMIT 1
This will return only 1 row, the first row where the conditions are true.

Categories