i have a list of checkboxes, right now i am able to retrieve data at database from multiple selected checkbox, and display them in a table.. below this is the code..
But my problem is how to display similar output data just like in comparetable.php to a histogram..i tried to used google chart but it just display data of a histogram exactly from the database, not getting from multiple selected checkboxes. Thank you very much for your time...
history.php
<FORM NAME ="form1" METHOD ="POST" action="comparetable.php">
<table>
<tr>
<th></th>
<th>TITLE</th>
<th>ACTION</th>
</tr>
<?php
$query = "SELECT * FROM compareresult where idmember='$idmembersession'";
$sql_query = mysql_query($query) or die('Error 3 :'.mysql_error());
while($data = mysql_fetch_array($sql_query,MYSQL_ASSOC)){
$title = $data['subject'];
?>
<tr>
<td><input type="checkbox" name="selectedcheck[]"
value="<?php echo $title ?>"/></td>
<?php
echo "<td>$title</td>"
}
?>
</tr>
</table>
<INPUT TYPE = "Submit" Name = "submit1" VALUE = "COMPARE SELECTED"></form>
comparetable.php
<body>SUSTAINABILITY OF PERCENTAGE </br></br></br>
<table border='1'>
<tr>
<th>TITLE</th>
<th>PERCENTAGE RESULT</th>
</tr>
<?php
if(isset ($_POST["submit1"]))
{
$checkbox = isset($_POST['selectedcheck']) ? $_POST['selectedcheck'] : array();
foreach($checkbox as $title)
{
$query = "SELECT * FROM compareresult where subject='".$title."'";
$sql_query = mysql_query($query) or die('Error 3 :'.mysql_error());
while($data = mysql_fetch_array($sql_query))
{
$result = $data['result'];
echo "<tr>";
echo "<td>".$title."</td>";
echo "<td>".$result."</td>";
echo "</tr>";
}
}
}
?>
</table></body></html>
Related
I have a MYSQL table with Update link button on each row. he Update link goes to update.php which has a form. now the problem is i want to fetch the id from the row clicked on to update.php and show that id on update form in id field. i have transfered the id variable through link. but in other .php file it is printing anything.
i want to print id in update form field when i click on update button
Here is the code in index.php file
Display.php=>
<html>
<head><title>Support Page</title></head>
<body>
<table border="2">
<tr>
<th>ID</th>
<th>NAME</th>
<th>Email</th>
<th>phone no</th>
<th>Product Name</th>
<th>Company</th>
<th>Query</th>
<th>Any Other Info</th>
<th>Status</th>
<th>Date</th>
<th>Operations</th>
</tr>
<?php
$query ="SELECT * FROM query_data";
$data = mysqli_query($conn,$query);
$total = mysqli_num_rows($data);
echo $result['id']." ".$result['Name']." ".$result['Email']." ".$result['phone_no']." ".$result['Product_Name']." ".$result['Company']." ".$result['Query']." ".$result['Any_Other_Query']." ".$result['Status']." ".$result['Date'];
if($total!=0)
{
while($result = mysqli_fetch_assoc($data))
{
echo "
<tr>
<td>".$result['id']."</td>
<td>".$result['Name']."</td>
<td>".$result['Email']."</td>
<td>".$result['phone_no']."</td>
<td>".$result['Product_Name']."</td>
<td>".$result['Company']."</td>
<td>".$result['Query']."</td>
<td>".$result['Any_Other_Info']."</td>
<td>".$result['Status']."</td>
<td>".$result['Date']."</td>
<td><a href = 'http://mexyz.tech/?page_id=586?i=$result[id]'>Update</td>
</tr>";
}
}else{
echo "No record found";
}
?>
</table>
</body>
</html>
and this is update.php=>
<?php
include("connection.php");
$id = $_GET['i'];
?>
form action="" method="GET">
Enter id : <input type="text" value="<?php echo "id" ?>" name="id" required>
<br><br>
Enter Query Code: <input type="text" name="QC">
<br><br>
<td>
<select name="Status">
<option>Choose Option</option>
<option>Pending</option>
<option>Assigned</option>
<option>Resolved</option>
</select>
</td>
<br><br>
<input type="submit" value="Submit" name="Submit">
</form>
<?php
if (isset($_POST['Submit'])) {
$ids = $_POST['id'];
$s = $_POST['Status'];
$QC = $_POST['QC'];
$tablename = "query_data";
$data = array("Status" =>$s, "Query_Code" =>$QC);
$wherecondition = array('id' => $ids);
$updated = $wpdb->update( $tablename, $data, $wherecondition );
// $sql = $wpdb->insert("query_data",array("Status" =>$s,"Query_Code" =>$QC));
if ($updated == true) {
echo "<script> alert('Submitted Successfully!...')</script>";
}
}
?>
</div><!-- #primary -->
<?php
if (astra_page_layout() == 'right-sidebar') :
get_sidebar();
endif;
get_footer();
I dont know exactly what you are trying to achieve from your code but
you should pass your update link with a query string if you want to get the id in your update.
this is how to pass the link with a query string
<td>Update</td>
if you do it that way then got to your update page
and do this
if (isset($_GET[id])){
$id = $_GET[id];
}
I get the data from mysql and display it in the table now i'm trying to send it to the database for each student by checking the checkbox, then what should i do to send all table data into the msql database with the different student id
<form class="col-md-12" action="Attendance.php" method="post">
<table id="example" class="myclass table table-striped" />
<thead>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Father Name</th>
<th><label><input type="checkbox" id="selectAll" name="chbox[]"> All Present </label></th>
</tr>
</thead>
<tbody>
<?php
$SrNo = 0;
global $dbManager;
$sql = "SELECT * FROM studentinfo";
$stmt = $dbManager->query($sql);
while($DataRows = $stmt->fetch()){
$RollNo = $DataRows['id'];
$FullName = $DataRows['fullname'];
$FatherName = $DataRows['fathername'];
?>
<tr>
<td><?php echo $RollNo; ?></td>
<td><?php echo $FullName; ?></td>
<td><?php echo $FatherName; ?></td>
<td><input type="checkbox" name="chbox[]" value="1" /></td>
</tr>
</tbody>
<?php } ?>
<tfoot>
<?php
if(isset($_POST['Submit'])){
$StudentRollNo = $RollNo;
$Attendance = $_POST['chbox'];
// date_default_timezone_set("Asia/Kabul");
$CurrentTime = time();
$DateTime = strftime("%B-%d-%Y %H:%M:%S", $CurrentTime);
if(empty($Attendance)){
$_SESSION['ErrorMessage'] = "Please filled all fields";
RedirectTo("Attendance.php");
}
else{
// the sql code is here.
global $dbManager;
foreach ($Attendance as $key => $value) {
$sql = "INSERT INTO attendance(sid, subjectid, classid, attendance, datetime) VALUES(:studentId,'1','2', :attendancE, :dateTime)";
$stmt = $dbManager->prepare($sql);
$stmt->bindValue(':studentId',$StudentRollNo);
$stmt->bindValue(':attendancE',$value);
$stmt->bindValue(':dateTime',$DateTime);
$Execute = $stmt->execute();
if($Execute){
$_SESSION['SuccessMessage'] = "Attendance Submited Successfully.";
RedirectTo("Attendance.php");
}
else{
$_SESSION['ErrorMessage'] = "Something went wrong. Try Again!";
RedirectTo("Attendance.php");
}
}
}
?>
<tr>
<td>
<i class="fa fa-check"></i>
<input type="submit" name="Submit" value="Save Attendance">
</td>
</tr>
</tfoot>
</table>
</form>
Mysql database: the problem is that the record saves only for one student.
Bring you table inside the while loop where you are fetching the values from the database and then assign the value of students dynamically for the checkbox value
you can do
value="<?php echo $RollNo; ?>";
just like you echo out the other values add the echo into the value field of the checkbox in order to get the values dynamically assigned to each checkbox
I want to create time table. Need to get subject names from database in check boxes and teachers name from database in select dropdown. I am using following code but it give me only single row. I don't know where I am doing mistake.
<table width="100%">
<tr>
<th>Select Subject</th>
<th>Period Time</th>
<th>Teacher</th>
</tr>
<?php
$query = mysqli_query($conn, "select * from subjects");
while ($row = mysqli_fetch_array($query))
{
$subject_id = $row['subject_id'];
$subject_name = $row['subject_name'];
echo "<tr>
<td><input type='checkbox' name='subject_id' value='$subject_id'> $subject_name</td>
<td>
<div class='form-group'>
<select name='class_time' class='form-control'>
<option>10:00</option>
<option>11:00</option>
<option>12:00</option>
<option>01:00</option>
</select>
</div>
</td>
<td>
<div class='form-group'>
<select name='employee_id' class='form-control'>";
$query = mysqli_query($conn, "select * from employees where designation = 'Teacher' OR designation = 'Principal'");
while ($row = mysqli_fetch_array($query))
{
$employee_id = $row['employee_id'];
$employee_name = $row['employee_name'];
echo "
<option>$employee_name</option>";
}
echo "</select></div>
</td>
</tr>";
}
?>
</table>
The problem you have is that you use the same variable name $query for both queries, and so the second one overwrites the first one. Try using $empQuery or something else for the second one.. (same for $row -> $empRow)
how can I get multiple ID while POST multiple selection option value to next form? I only get the first selection ID from array. Can you guys can suggest any ideas to me?
here is my code when select the value.
<tr>
<label>Auditor: </label>
<select class="form-control" name="auditor[]" multiple="multiple" >
<?php
$result = $db->query("SELECT * FROM auditor");
while($row = mysqli_fetch_array($result))
{
echo '<option value="'.$row["auditor_name"].'">'.$row["auditor_name"].'</option>';
}
echo "</select>";
?>
</tr>
here is another code while POST to the next page.
$myselected = $_POST["auditor"];
if(count($myselected)>1){
$auditor = implode ("','",$myselected);
}else{
$auditor =$myselected;
}
$query10 = "SELECT * FROM auditor WHERE auditor_name IN ('$auditor') ";
$result10 = $db->query($query10);
$row10 = $result10->fetch_array();
?>
<form action="audit_action/audit_action.php" role="form" method="post" name="auditformdetails" onsubmit="return(validate());">
<table width='100%' border='0' class="table">
<tr>
<td colspan=6>Audit details</td>
<td colspan=6>Outlet details</td>
</tr>
<tr>
<td><b>Auditor:</b></td>
<td colspan='5'>
**<?php
echo'<input type="hidden" name="auditor_id" value="'.$row10["id"].'">';
foreach ($myselected as $auditor){
echo $auditor."<br>\n";
}
?>**
</td>
You can not compare string with mysql IN Clause. So, you have to connect each of your value with or condition in query as i written below.
$myselected = $_POST["auditor"];
$sql_cond = "";
if(count($myselected)>1){
foreach($myselected as $selected){
if($sql_cond != "")
$sql_cond.=" or auditor_name = ".$selected;
else
$sql_cond.=" auditor_name = ".$selected;
}
}else{
$auditor =$myselected;
}
$query10 = "SELECT * FROM auditor WHERE ".$sql_cond;
I want to create a table with input fields where student records can be inserted. The name of the students are in the first column of the table fetched from the database with a while loop. The other columns contain fields for inputing the student scores. The challenge I'm facing is how to insert the records of all the students in different row of a table called result_sec into the database. I've search for similar post but couldn't get a suitable answer. Below is the code. Thanks in advance.
<?php require('header.php'); ?>
<?php
$query_form = sprintf("SELECT * FROM regform LIMIT 2");
$form = mysqli_query($conn, $query_form) or die(mysqli_error($conn));
$formdata = mysqli_fetch_assoc($form);
if(isset($_POST['submit']))
{
$exes = $_POST['exe'];
$asss = $_POST['ass'];
$ca1s = $_POST['ca1'];
$ca2s = $_POST['ca2'];
$exams = $_POST['exam'];
foreach($exes as $key => $exe)
{
$sql = "INSERT INTO result_sec (exe, ass, ca1, ca2, exam) VALUES ('$exe', '$asss[$key]', '$ca1s[$key]', '$ca2s[$key]', '$exams[$key]')";
}
$insert = mysqli_multi_query($conn, $sql);
}
?>
<form method="POST">
<table>
<thead>
<tr>
<th>Name</th>
<th>Ass.</th>
<th>Exe.</th>
<th>1st C.A.</th>
<th>2nd C.A.</th>
<th>Exam</th>
</tr>
</thead>
<tbody>
<?php do { ?>
<tr>
<td><?php echo $formdata['surname']." ".$formdata['firstname']; ?></td>
<td><input name="ass[]" size="1px"/></td>
<td><input name="exe[]" size="1px" /></td>
<td><input name="ca1[]" size="1px" /></td>
<td><input name="ca2[]" size="1px" /></td>
<td><input name="exam[]" size="1px" /></td>
<input type="hidden" name="regformid[]" value="<?php echo $formdata['regformid'];?>" />
</tr>
<?php } while ($formdata = mysqli_fetch_assoc($form)); ?>
</tbody>
</table>
<button type="submit">Insert Student Record</button>
</form>
<?php require('footer.php'); ?>
See If this resolve your problem
if(isset($_POST['submit'])){
$exes = $_POST['exe'];
$asss = $_POST['ass'];
$ca1s = $_POST['ca1'];
$ca2s = $_POST['ca2'];
$exams = $_POST['exam'];
//You can use a foreach loop to loop over one of the repeated inputs, and then use the index to access the corresponding elements in the others:
foreach ($exes as $i => $exe) {
$exee = mysqli_real_escape_string($exe);
$ass = mysqli_real_escape_string($asss[$i]);
$ca1 = mysqli_real_escape_string($ca1s[$i]);
$ca2 = mysqli_real_escape_string($ca2s[$i]);
$exam = mysqli_real_escape_string($exams[$i]);
$sql = "INSERT INTO result_sec (exe, ass, ca1, ca2, exam)
VALUES ('$exee', '$ass', '$ca1', '$ca2', '$exam')";
$insert = mysqli_multi_query($conn, $sql);
}
}