I'm a PHP noob, I keep getting this error:
Parse error: syntax error, unexpected end of file...
The line it points to is at the very last line. My 'header.php' declares the !DOCTYPE html and my 'config.php' holds the database properties.
Any help would be greatly appreciated.
<?php
include 'config.php';
include 'header.php';
?>
<div id='wrapper'>
<div style='height:50em;width:100%;z-index:10;margin-top:1em;text-align:left;'>
<table id='mainDPUtable'>
<th class='cen'>NUM</th>
<th class='cen'>TYP</th>
<th class='cen'>LVL</th>
<th class='cen'>Job No.</th>
<th class='cen'>Responsible</th>
<th class='cen'>Rep</th>
<th class='cen'>Initiated</th>
<th class='cen'>Age</th>
<th class='cen'>Part Number</th>
<th class='cen'>Qty</th>
<th class='cen'>Description</th>
<th class='cen'>Location</th>
<th class='cen'>Complete</th>
<?php
$db = new PDO("mysql:host=localhost;dbname=".$dbname.",".$user.",".$pswd);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$result = $db->prepare("SELECT NUM, TYP, LVL, JOBNO, RESP, REP, DATE_INITIATED, AGE, PARTNO, QTY, DESCRIPTION, LOC FROM ".$dbtable);
$result->execute();
while ($row = $result->fetch(PDO::FETCH_ASSOC)){
$num=$row["NUM"];
$typ=$row["TYP"];
$lvl=$row["LVL"];
$jobNo=$row["JOBNO"];
$resp=$row["RESP"];
$rep=$row["REP"];
$date_initiated=$row["DATE_INITIATED"];
$age=$row["AGE"];
$partNo=$row["PARTNO"];
$qty=$row["QTY"];
$description=$row["DESCRIPTION"];
$loc = $row["LOC"];
$comp=$row["COMP"];
?>
<tr>
<td><?php echo $num; ?></td>
<td><?php echo $typ; ?></td>
<td><?php echo $lvl; ?></td>
<td><?php echo $jobNo; ?></td>
<td><?php echo $resp; ?></td>
<td><?php echo $rep; ?></td>
<td><?php echo $date_initiated; ?></td>
<td><?php echo $age; ?></td>
<td><?php echo $partNo; ?></td>
<td><?php echo $qty; ?></td>
<td><?php echo $description; ?></td>
<td><?php echo $loc; ?></td>
<td><input type='button' id=<?php echo 'btn'.$num; ?> value='Complete'/></td>
</tr>
<?php}?>
</table>
</div>
</div>
</body>
</html>
Missing spaces:
<?php}?>
should be
<?php } ?>
^-^--
Related
I have a table for saving details including logging time.Just as soon as a new record is inserted I want the column 'Countdown' to start an automatic time countdown from 30min until it gets to zero(0).How do I go about it?Thanks.
Here is the table php code
`<?php $results = mysqli_query($db, "SELECT
Vehicle_name,Vehicle_make,Vehicle_color,Number_plate,Date,Time FROM
vehicle"); ?>
<div class="table">
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle color</th>
<th>Reg Number</th>
<th>Date</th>
<th>Time</th>
<th>Countdown</th>
<th colspan="4">Action</th>
</tr>
</thead>
<?php while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row['Vehicle_name']; ?></td>
<td><?php echo $row['Vehicle_make']; ?></td>
<td><?php echo $row['Vehicle_color']; ?></td>
<td><?php echo $row['Number_plate']; ?></td>
<td><?php echo $row['Date']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td><?php echo $row['Time']; ?></td>
<td>
<a href="php_code.php?del=<?php echo $row['Number_plate']; ?>"
class="del_btn">Delete</a>
</td>
</tr>
<?php } ?>
`
I have a foreach in the table. I foreach a row for every row in my database. So my database has got 10 records, I and my table is showing all those records underneath eachother. So far so good.
I want to number them, from 1 to 10, displayed in front of every row.
This is my table:
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php for($i = 1; $i < $count; $i++;)
{
echo $i; ?>}
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This is my method
public function fifaLeagueTable() {
$getTable = "SELECT * FROM fifa_league ORDER BY points DESC";
$table = $this->model->readAll($getTable);
$count = count($table);
include('app/views/fifaLeagueTable.php');
}
If I var_dump the $count, I receive int(10). So it's counting the amount of rows and I have access to the 10. I am getting a white page, so there might be something wrong in the for loop or something. What did I do wrong?
You just need to create one more variable and its done. Here is updated code :
<table class="table table-striped mt-3">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Team</th>
<th scope="col">Player</th>
<th scope="col">P</th>
<th scope="col">W</th>
<th scope="col">D</th>
<th scope="col">L</th>
<th scope="col">GF</th>
<th scope="col">GA</th>
<th scope="col">GD</th>
<th scope="col">P</th>
</tr>
</thead>
<tbody>
<?php $count = count($table); $num = 1; ?>
<?php foreach($table as $t): ?>
<tr>
<td><?php echo $num; ?>
</td>
<td><?php echo $t['team']; ?></td>
<td><?php echo $t['speler']; ?></td>
<td><?php echo $t['gw']; ?></td>
<td><?php echo $t['w']; ?></td>
<td><?php echo $t['g']; ?></td>
<td><?php echo $t['v']; ?></td>
<td><?php echo $t['dv']; ?></td>
<td><?php echo $t['dt']; ?></td>
<td><?php echo $t['ds']; ?></td>
<td><?php echo $t['points']; ?></td>
</tr>
<?php $num++ ; endforeach; ?>
</tbody>
</table>
<table id="b" class="table table-hover" border="1" cellspacing="0" cellpadding="5">
<tr>
<th>Serial No</th>
<th>Student Name</th>
<th>Student ID</th>
<th>Point ID</th>
<th>CV</th>
<th>USI</th>
<th>Reference</th>
<th>Academic Certificate</th>
<th>Training Documents</th>
<th>Pay Slips</th>
<th>Work Pictures</th>
<th>Other Documents</th>
<th>Work Documents</th>
<th>Applicants Form</th>
<th>Employer Form</th>
<th>Action</th>
</tr>
<?php
$result = mysql_query("select * from student_portal");
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['student_id']; ?></td>
<td><?php echo $row['point_id']; ?></td>
<td><?php echo $row['cv']; ?></td>
<td><?php echo $row['usi']; ?></td>
<td><?php echo $row['reference']; ?></td>
<td><?php echo $row['academic_certificate']; ?></td>
<td><?php echo $row['training_documents']; ?></td>
<td><?php echo $row['Pay_slips']; ?></td>
<td><?php echo $row['work_pictures']; ?></td>
<td><?php echo $row['other_documents']; ?></td>
<td><?php echo $row['work_documents']; ?></td>
<td><?php echo $row['declaraction_form']; ?></td>
<td><?php echo $row['declaraction_employer']; ?></td>
</tr>
Here is the code, I want to download all file in a zip format. In zip file all in a folder.
You will probably have to create a row HTML file of the output and run it through a php zipper function.
Here's one to get you started
function unzip_file($location,$newLocation){
if(exec("unzip $location",$arr)){
mkdir($newLocation);
for($i = 1;$i< count($arr);$i++){
$file = trim(preg_replace("~inflating: ~","",$arr[$i]));
copy($location.'/'.$file,$newLocation.'/'.$file);
unlink($location.'/'.$file);
}
return TRUE;
}else{
return FALSE;
}
}
<?php
$connect = mysqli_connect('localhost', 'root', ' ', ' ');
if(mysqli_connect_errno($connect)){
echo 'Failed to connecto to database'.mysqli_connect_error();}
$result= mysqli_query($connect, "SELECT * FROM Products WHERE ProductCategory = 'Electronics'");
?>
<table width="500", cellpadding=5 callspacing=5 border=1>
<tr>
<th>Product Name</th>
<th>Product Price</th>
<th>Product Image</th>
<th>Product Description</th>
<th>Product Category</th>
</tr>
<?php while($rows = mysqli_fetch_array($result)): ?>
<tr>
<td><?php echo $rows['ProductName']; ?></td>
<td><?php echo $rows['ProductPrice']; ?></td>
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
<td><?php echo $rows['ProductDescription']; ?></td>
<td><?php echo $rows['ProductCategory']; ?></td>
</tr>
<?php endwhile; ?>
</table>
My issue is that the code that I currently have only makes it so that it will run through the database line by line and get the information but when it comes to the images row then it doesn't retrieve anything and my directory is correct as the image is stored in a folder called images that is within the folder the web page is.
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You forgot to close the <p and also missing the "s" in rows
this should be <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
also dont forget to close the <p> tag later
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
You're missing a closing > on p before img and subsequently a closing p.
Try:
<td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
You can edit the size of your pictures by using CSS, if photoshop is not a solution.
Instead of
<td><?php echo '<p<img src="images/'.$row["ProductImage"].'" />'; ?></td>
Use below code
<td><?php
$productImage = !empty($row["ProductImage"])?$row["ProductImage"]:'no-image.png';
echo "<img src='/images/{$productImage}' />";?>
You're missing the "s" in rows
Try: <td><?php echo '<p><img src="images/'.$rows["ProductImage"].'" /></p>'; ?></td>
I display the table from db. and i have checkbox for each row,I want to move the selected rows from one table to another "selected table" from the page without page refresh. ? the current selection has to be removed from current table. I can do the query like select * from tab-1 where id=$selected. and also can move it to another table with insert into tab_name and so on. but dont know how to do it without refresh and with some nice effects ? may be with jquery any pointers or help.
<table id="tab-1">
<thead>
<tr>
<th scope="col">Select</th>
<th scope="col">ID</th>
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">C</th>
<th scope="col">D</th>
<th scope="col">E</th>
<th scope="col">E</th>
<th scope="col">F</th>
<th scope="col">G</th>
<th scope="col">H</th>
<th scope="col">I</th>
<th scope="col">J</th>
<th scope="col">k</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['ID']; ?>" /></td>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['A']; ?></td>
<td><?php echo $row['B']; ?></td>
<td><?php echo $row['D']; ?></td>
<td><?php echo $row['E']; ?></td>
<td><?php echo $row['F']; ?></td>
<td><?php echo $row['G']; ?></td>
<td><?php echo $row['H']; ?></td>
<td><?php echo $row['I']; ?></td>
<td><?php echo $row['J']; ?></td>
<td><?php echo $row['K']; ?></td>
<td><?php echo $row['L']; ?></td>
<td><?php echo $row['M']; ?></td>
</tr>
</tbody>
<table>
using jQuery , Ajax you can do this .
<script>
$('.checkBox').change(function() {
var selected = $(this).val();
$.post('yourfile.php' , {
selected : selected
} , function(data){
alert(data);
});
});
$('.checkBox').mousedown(function() {
if (!$(this).is(':checked')) {
$(this).trigger("change");
}
});
</script>
in yourfile.php you can execute SELECT and INSERT queries