I am working on a small course registration system. I have a table called 20182019carryovertbl I select students carry over fron the table and its working well. I need to convert the selected info to an HTML form with submit button( This will go into another table 20192020coursestbl). How d i set name for my inputs
<table>
<thead>
<tr>
<th>Register course</th>
<th>Course Title</th>
<th>Corse Code</th>
<th>Unit</th>
<th>Lecturer</th>
</tr>
</thead>
<tbody>
<?php $sql = "SELECT * from 20182019carryovertbl WHERE matricno = '$matno' ";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<tr>
<td> <input type="checkbox" name="reg1" value="1" class="custom-control-input"></td>
<td>
<?php echo htmlentities($result->coursetitle);?>
</td>
<td>
<?php echo htmlentities($result->coursecode);?>
</td>
<td>
<?php echo htmlentities($result->unit);?>
</td>
<td>
<?php echo htmlentities($result->lecturer);?>
</td>
</tr>
<?php $cnt=$cnt+1; }} ?>
</tbody>
</table>
you can use your unique key from database like Id:
<td>
<input type="checkbox" name="reg<?php echo $result->id;" value="1"class="custom-control-input">
</td>
and it's gonna be unique name
Related
After successfully inputting data inside a key, I am now facing the problem of trying to display it.
this is the code that I've been trying and modifying to try and fetch it but to still to no avail
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
<?php
include('dbcon.php');
if(isset($_GET['id']))
{
$key_child = $_GET['id'];
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
$fetchdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
if($fetchdata > 0)
{
$i = 0;
?>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<?php
foreach($fetchdata as $key_child => $row)
{
?>
<tr>
<td> <?= $row['Course_Code'];?> </td>
<td> <?= $row['Desc_title'];?> </td>
<td> <?= $row['Unit'];?> </td>
<td> <?= $row['Pre-Req'];?> </td>
<td> <?= $row['Grade'];?> </td>
</td>
</tr>
<?php
}
}
else
{
?>
<td colspan = "5"> Nothing Found </td>
<?php
}
}
else
{
?>
<td colspan = "5"> No Record found </td>
<?php
}
It is displaying the "Nothing Found" when I execute it even though there are data in the database.
And this is the code that I initially tried for some context.
<tr>
<th>Course Code</th>
<th>Discriptive Title</th>
<th>Unit</th>
<th>Pre-Requisite</th>
<th>Grade</th>
</tr>
$key_child = $_GET['id'];
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem';
$getdata = $database->getReference($ref_table)->getChild($key_child)->getValue();
if($getdata > 0)
{
?>
<input type="hidden" name = "id" value = "<?=$key_child;?>">
<tr>
<td> <?= $row['Course_Code'];?> </td>
<td> <?= $row['Desc_title'];?> </td>
<td> <?= $row['Unit'];?> </td>
<td> <?= $row['Pre-Req'];?> </td>
<td> <?= $row['Grade'];?> </td>
</td>
</tr>
If $key_child is 5nKX..., then you're missing a / after User in this code:
$ref_table = 'User'.$key_child.'/Grades/1st Year/1st Sem'
So to fix that problem:
$ref_table = 'User/'.$key_child.'/Grades/1st Year/1st Sem'
// 👆
<?php include("header.php"); ?>
<?php
if (#$_POST['delete']=="Delete"){
$count=count($_POST['delbx']);
for($i=0;$i<$count;$i++){
$delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resulty = mysqli_query($conn, $delete) or die(mysql_error());
$select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resultrowdy = $conn->query($select_delete);
$rowdy = $resultrowdy->fetch_assoc();
$path="admin/".$rowdy['a_image'];
echo $path;
unlink($path);
echo '<script>window.location="view_user.php"</script>';
}
} ?>
<div class="table-responsive">
<table class="table">
<caption>All Users</caption>
<?php
$sql = "SELECT a_id, a_name, a_phone, a_password, a_role, a_mail, a_image FROM admin";
$result = $conn->query($sql);
if ($result->num_rows > 0) {?>
<thead>
<tr>
<th><form action="view_user.php" method="post"><input name="delete" type="submit" id="delete" value="Delete"></th><th>S. No.</th> <th>Name</th> <th>Phone No.</th> <th>Mail Id</th> <th>Role</th> <th>Password</th> <th>Image</th>
</tr>
</thead>
<?php
while($row = $result->fetch_assoc()) { ?>
<tbody>
<tr>
<th scope="row">
<?php echo $row["a_id"]; ?>
</th>
<td align="center" bgcolor="#FFFFFF">
<input name="delbx[]" type="checkbox" id="delbx[]" value="<?php echo $row["a_id"]; ?>" />
</td>
<td>
<?php echo $row["a_name"]; ?>
</td>
<td>
<?php echo $row["a_phone"]; ?>
</td>
<td>
<?php echo $row["a_mail"]; ?>
</td>
<td>
<?php echo $row["a_role"]; ?>
</td>
<td>
<?php echo $row["a_password"]; ?>
</td>
<td>
<img src="admin/<?php echo $row["a_image"]; ?>" width="60" height="40">
</td>
<th>
Edit
</th>
</tr>
</tbody>
<?php
}
} else {
echo "0 results";
}?>
</table>
</form>
</div>
<?php include("footer.php"); ?>
The code I mention is not deleting the multiple images from the source folder but deleting the multiple data from database whereas I am trying to delete images from the source folder along with data please help thanks in advance
One of the problem is you are deleting the row and trying to select image column from the deleted row.. dont use user supplied variables directly in your query
your code should be
for($i=0;$i<$count;$i++){
$select_delete = "SELECT `a_image` FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
$resultrowdy = $conn->query($select_delete);
$rowdy = $resultrowdy->fetch_assoc();
$delete = "DELETE FROM admin WHERE a_id='".$_POST['delbx'][$i]."'";
if(mysqli_query($conn, $delete)){
$path="admin/".$rowdy['a_image'];
unlink($path);
echo '<script>window.location="view_user.php"</script>';
}
}
I need to display data from a database in a table, and I was wondering if you can create 2 separate tables based on a variable.
I have code to display it all in one table:
<table>
<tr>
<th> Name </th>
<th> Event </th>
</tr>
<?php
while($row = $result->fetch_assoc())
{?>
<tr>
<td> <?php echo $row["name"] ?> </td>
<td> <?php echo $row["event"] ?> </td>
</tr>
<?php } ?>
</table>
So each person has an option of 2 fundraisers. Is there a way to create 2 separate tables based on the event variable? I know I could create another table in the database, but I want to keep all the data in one area.
I only know basic PHP and any help is appreciated.
<table>
<tr>
<th> Name </th>
<th> Event </th>
</tr>
<?php
while($row = $result->fetch_assoc())
{?>
<tr>
<td> <?php echo $row["name"] ?> </td>
</tr>
<?php } ?>
</table>
<table>
<tr>
<th> Name </th>
<th> Event </th>
</tr>
<?php
while($row = $result->fetch_assoc())
{?>
<tr>
<td> <?php echo $row["event"] ?> </td>
</tr>
<?php } ?>
</table>
I have two HTML tables. Each has three rows and one column only. I'd like to join them programmatically such that I get one table with two columns and three rows.
Is there some function or hack to achieve this? How can I achieve this?
For example
First Table:
<table id="table_one">
<tbody>
<tr>
<td>
<label>data one</label>
</td>
</tr>
<tr>
<td>
<label>data two</label>
</td>
</tr>
<tr>
<td>
<label>data three</label>
</td>
</tr>
</tbody>
</table>
Second Table:
<table id="table_two">
<tbody>
<tr>
<td>
<label>data one</label>
</td>
</tr>
<tr>
<td>
<label>data two</label>
</td>
</tr>
<tr>
<td>
<label>data three</label>
</td>
</tr>
</tbody>
</table>
This is what I want from the above two tables:
<table id="table_three">
<tbody>
<tr>
<td>
<label>data one</label>
</td>
<td>
<label>data one</label>
</td>
</tr>
<tr>
<td>
<label>data two</label>
</td>
<td>
<label>data two</label>
</td>
</tr>
<tr>
<td>
<label>data three</label>
</td>
<td>
<label>data three</label>
</td>
</tr>
</tbody>
</table>
Well, this is a way to proceed (check in-code comments):
$table1 = <<<'_DATA_'
<table id="table_one">
<tbody>
<tr>
<td>
<label>data one</label>
</td>
</tr>
<tr>
<td>
<label>data two</label>
</td>
</tr>
<tr>
<td>
<label>data three</label>
</td>
</tr>
</tbody>
</table>
_DATA_;
$table2 = <<<'_DATA_'
<table id="table_two">
<tbody>
<tr>
<td>
<label>data one</label>
</td>
</tr>
<tr>
<td>
<label>data two</label>
</td>
</tr>
<tr>
<td>
<label>data three</label>
</td>
</tr>
</tbody>
</table>
_DATA_;
// Load teh 1st table
// Create a DOM object
$html1 = new simple_html_dom();
// Load HTML from a string
$html1->load($table1);
// Load teh 2nd table
// Create a DOM object
$html2 = new simple_html_dom();
// Load HTML from a string
$html2->load($table2);
// Find all rows from both tables
$rows1 = $html1->find('tr');
$rows2 = $html2->find('tr');
// Build teh 3rd table
$table3 = '<table id="table_three">
<tbody>';
// Insert rows cells from both initial tables
for ($i=0; $i < count($rows1); $i++) {
$table3 .= '<tr>';
// get row's innerhtml
$table3 .= $rows1[$i]->innertext;
$table3 .= $rows2[$i]->innertext;
$table3 .= '</tr>';
};
// finish the table
$table3 .= '</tbody>
</table>';
// Clear DOM objects
$html1->clear();
unset($html1);
$html2->clear();
unset($html2);
It creates this:
<table id="table_three">
<tbody>
</tbody>
</table>
<script type="text/javascript">
jQuery(document).ready(function($){
$('#table_one tr').each(function(index){
var row = $(this);
var row2 = $('#table_two tr').get(index);
$(row).append($(row2).find('td'));
$('#table_three').append($(row));
});
});
</script>
Here's how I'd do it:
// assume we have the tables in three strings:
// table_one in $str_1, table_two in $str_2, and table_three in $str_3.
// create $str_3 by copying $str_1 and replacing the table ID
$str_3 = $str_1;
$str_3 = str_replace('table_one', 'table_three', $str_3);
// load table_two and table_three in simple-html-dom and collect the TD elements
$tab_2 = str_get_html($str_2);
$tab_3 = str_get_html($str_3);
$tds_3 = $tab_3->find("td");
$tds_2 = $tab_2->find("td");
// go through the TDs in table_three and append the corresponding table_two TD
$acc = 0;
foreach ($tds_3 as &$td) {
$td->outertext = $td->outertext . $tds_2[$acc]->outertext;
$acc++;
}
// done!
echo $tab_3;
Not sure I understood the question, but:
<?php
// first and second table
//Select data
$reponse = $bdd->prepare('SELECT data1, data2 FROM '.RESEARCH.' WHERE X=X');
$reponse->execute(array(X));
?>
//Begin table
<table id="table_one_or_two">
<tbody>
//Loop the rows
while ($data = $reponse->fetch())
{
<tr>
<td>
<label>$data['data1']</label>
</td>
</tr>
}
//end of loop, end of table
</tbody>
</table>
// 3TH table
//Select data
$reponse = $bdd->prepare('SELECT data1, data2 FROM '.RESEARCH.' WHERE X=X');
$reponse->execute(array(X));
?>
//Begin table
<table id="table_three">
<tbody>
//Loop the rows
while ($data = $reponse->fetch())
{
<tr>
<td>
<label>$data['data1']</label>
</td>
<td>
<label>$data['data2']</label>
</td>
</tr>
}
//end of loop, end of table
</tbody>
</table>
I have a database
that have two tables.
The sql query fetching data correctly.
I want to sort fields data by typing table heading in text box and click on go that in table footer.
Many Thanks
<table border="0" cellpadding="0" cellspacing="0" width="50%">
<thead>
<tr>
<th class="capt" colspan="6">Available Projects</th>
</tr>
<tr>
<th>Select</th>
<th>Project</th>
<th>Crawler</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include(dirname(__file__)."/includes/dbConn.php");
$result = mysql_query("SELECT *, ( SELECT name FROM projects WHERE projects.id = crawlers.pid ) AS pname FROM `crawlers`", $appConn);
while($row = mysql_fetch_array($result))
{
?>
<tr id="crawler_<?php echo $row['id']; ?>">
<td>
<input value="" id="check" type="checkbox">
<input id="crawler_id_<?php echo $row['id']; ?>" type="hidden" value="<?php $row['id']; ?>" /> <!-- crawler id -->
</td>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>username#domain.com</td>
<td>Enabled</td>
<td><a class="edit" href="#">edit</a><a class="add" href="#">run</a><a class="delete" href="#">delete</a></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="6"> Sort Fields by <input value="type here" id="field" type="text"> Go </th>
</tr>
</tfoot>
</table>
I think, you are looking for ORDER BY
Have a look at the MySQL Documentation about the SELECT syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html