my echo "<tr> </tr"; error when i use bootstrap - php

echo "<tr class ='a'>
<td>".$data->id."</td>
<td>".$data->nis."</td>
<td>".$data->nama."</td>
<td>".$data->jenis_kelamin."</td>
<td>".$data->telp."</td>
<td>".$data->alamat."</td>
<td><a class="btn btn-warning" href="'.base_url("siswa/ubah/".$data->id).'">Ubah</a></td>
<td><a class="btn btn-danger" href="'.base_url("siswa/hapus/".$data->id).'">Hapus</a></td>
</tr>";
its error when i use bootstrap in my coding, how to keep this from error?

try it
<?php
echo "<tr class ='a'>
<td>".$data->id."</td>
<td>".$data->nis."</td>
<td>".$data->nama."</td>
<td>".$data->jenis_kelamin."</td>
<td>".$data->telp."</td>
<td>".$data->alamat."</td>
<td><a class=\"btn btn-warning\" href=".base_url("siswa/ubah/".$data->id).">Ubah</a></td>
<td><a class=\"btn btn-warning\" href=".base_url("siswa/hapus/".$data->id).">Hapus</a></td>
</tr>";
?>

Try this method. Hope it will help you
<td><?php echo $data->id; ?></td>
<td><?php echo $data->ins; ?></td>
<td><?php echo $data->name; ?></td>
<td><?php echo $data->jenis_kelamin; ?></td>
<td><?php echo $data->telp; ?></td>
<td><?php echo $data->alamat; ?></td>
<td><a class=\"btn btn-warning\" href="<php echo base_url("siswa/ubah/".$data->id)?>">Ubah</a></td>
<td><a class=\"btn btn-warning\" href="<?php echo base_url("siswa/hapus/".$data->id)?>">Hapus</a></td>

Related

How to show image in table using PHP

I tried the following code to show my SQL database data in a table in my dashboard
<tbody>
<?php
while ($row = $result->fetch_assoc()):?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img src="<?php echo $row['image']; ?>" width=100px height=100px></td>;
<td><?php echo $row['class']; ?></td>
<td><?php echo $row['reg_no']; ?></td>
<td><?php echo $row['capacity']; ?></td>
<td><?php echo $row['oname']; ?></td>
<td><?php echo $row['province']; ?></td>
<td><?php echo $row['district']; ?></td>
<td><?php echo $row['contact']; ?></td>
<td><a href="#" class="btn btn-warning btn-circle editbtn">
<i class="fas fa-edit"></i></a></td>
<td><a href="#" class="btn btn-info btn-circle viewbtn">
<i class="fas fa-eye"></i></a></td>
<td><a href="#" class="btn btn-danger btn-circle deletebtn">
<i class="fas fa-trash"></i></a></td>
</tr>
<?php endwhile; ?>
</tbody>
But that image column image does not show has an image
Result show like this:
my result
How to solve that problem
To me it seems your are inserting to the src attribute the context of the file rather then the URL of the image.
you are saving the image content it self in the DB,
check this out :
https://www.codexworld.com/upload-store-image-file-in-database-using-php-mysql/

Id from PHP not being passed to URL

I have some data displayed from SQL to PHP, when the user clicks the eye icon, he is redirected to another page with id on the URL, I did the following code
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><i class="fa fa-eye" aria-hidden="true"></i></td>
</tr>
<?php } ?>
Instead of the id, some special characters are coming in the URL, how can I fix it?
Below is how your anchor tag should be.
<i class="fa fa-eye" aria-hidden="true"></i>
You need to enclose the $record variable inside php tags and echo it.
You should echo it, like you did with another values:
<?php echo $record['id']; ?>
Full code:
<tr>
<td><?php echo $record['id']; ?></td>
<td><?php echo $record['firstname'];?></td>
<td><?php echo $record['Email'];?></td>
<td><?php echo $record['mobilenumber']?></td>
<td><?php echo $record['company']?></td>
<td><?php echo $record['designation']?></td>
<td><?php echo $record['state']?></td>
<td><i class="fa fa-eye" aria-hidden="true"></i></td>
</tr>
<?php } ?>
You should echo ID
as below
<a href="detail.php?id=<?= $record['id'] ?>\">

Use variables in PHP foreach loop

I use a foreach loop in php to fill a table, after that I use id and data-id to work with the line of the table.
The problem is that I can't figured how to increment a variable during the loop and add it in the id like this :
id='addr0' data-id="0",
id='addr1' data-id="1"
// etc.
Here is my loop :
foreach($result as $key => $value): ?>
<tr id='addr0' data-id="0">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del0" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php endforeach; ?>
Try the following.
$counter = 0;
foreach($result as $key => $value): ?>
<tr id='addr<?php echo $counter?>' data-id="<?php echo $counter?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button name = "del<?php echo $counter?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php
$counter++;
endforeach;
?>
You can get auto increment in two way.
Case 1 : If your $result is indexed array.
foreach($result as $key => $value): ?>
<tr id="addr<?php echo $key ?>" data-id="<?php echo $key ?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del<?php echo $key ?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr> <?php endforeach; ?>
Case 2 : If your $result is associative array.
<?php
$i = 0;
foreach($result as $key => $value): ?>
<tr id="addr<?php echo $i ?>" data-id="<?php echo $i ?>">
<td><?php echo $value['Nom']; ?></td>
<td><?php echo $value['Prenom']; ?></td>
<td><?php echo $value['Adresse']; ?></td>
<td><?php echo $value['Date de naissance']; ?></td>
<td><?php echo $value['Numero de telephone']; ?></td>
<td data-name="del">
<button nam"del<?php echo $i ?>" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>
</td>
</tr>
<?php
$i++;
endforeach;
?>

How to open file by using windowpopup

I have file (feeColect.php) which display information by using php, now I want to run (stockreportPDF.php) file after click Export PDF button, its real confuse me that what is wrong with the code while I used the same on previous project
1: this is (feeColect.php) file.
<tr><td><?php echo $list->idnumber; ?></td>
<td><?php echo $list->name; ?></td>
<td><?php echo $list->class; ?></td>
<td><?php echo $list->boarding_fee; ?></td>
<td><?php echo $list->school_fee; ?></td>
<td><?php echo $list->trans_fee; ?></td>
<td><?php echo $balance; ?></td>
<td><?php echo $list->term; ?></td>
<input type="hidden" name="id" id="id" value="<?php echo $list->id; ?>">
<?php $url_PDFstock ="stockreportPDF.php?from_date=$from_date&to_date=$to_date "; ?>
this is button that it suppose to open windowpop after click
<?php echo "<p> <a onclick=\"return windowpop('". $url_PDFstock ."')\">
<input class='btn btn-round btn-orange' type='button' value='Export PDF'></a></p>";?>

Need to get dynamic HTML content as a string

I want to be able too add this piece of code in a surrounded by an echo""
and stil be able to output the variables that is currently in the like below. This is where my mind is shutting down badly.
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
You are in need of using ob_get_contents();
Your code will look like this.
<?php
ob_start();
?>
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
<?php
$output = ob_get_contents();
ob_end_clean();
echo $output;
?>
In cases if you cannot use output buffering as #PratikSoni suggested, I would recommend looking up printf() or sprintf() functions for having formatted output.
Usage example:
$output .= sprintf("<td>%s </td>", $row_Recordset1['leaveID']);
This way you have it in a variable, and could do echo or whatever else you might need it for.
See if this works
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>

Categories