display type BLOB as a link - php

I want to display records in the website and the $row['data'] of the table report its type (BLOB) in a database and I want to display it as a link but it doesn't appear anymore.
What Can I do ? Whats the problem here?
<?php
include 'connect.php';
extract($_SESSION);
session_start();
?>
<html>
<body >
<table>
<?php
$sql="SELECT data,report.StudID,studFName,StudLName
FROM report,student
WHERE report.SuperID={$_SESSION['supervisor']} AND
report.StudID=student.StudID ";
$result= mysqli_query($con,$sql) or die ("could not found;
".mysqli_error($con));
while ($row=mysqli_fetch_array($result) )
{
?>
<tr>
<td><?php echo '<a href="data:application/pdf;base64,'.base64_encode($row ['data']).' " height="20" width="20" />'?></td>
<td><?php echo $row['StudLName'] ?></td>
<td><?php echo $row['studFName'] ?></td>
<td><?php echo $row['StudID'] ?></td>
<?php
}
?>
</tr>
</table>

Your link won't appear because you need to enclose it with </a> and specify text in it.
<?php
echo '<a href="data:application/pdf;base64,'.base64_encode($row ['data']).' " />Pdf Link</a>'
?>
I don't think you need to specify height and width for link.

Related

How to fetch images from database in base64_encode in php

Thank you all in advance....
I am doing a project in which I have a field to store the image. In that form, the image uploaded is completed with croppie plugin. and I stored the data in base 64 encodings. But I cannot fetch it to a page called view.php but the images are fetched to the form after cropping.
Please help me to figure it out the mistake that I have done
<tbody>
<?php
$no = 1;
$data = mysqli_query($con, "SELECT * FROM `register` WHERE app_registration IS NULL ORDER BY `app_id` DESC ");
while ($row = mysqli_fetch_assoc($data)) {
?>
<tr>
<td><?php echo $row['app_id'] ?></td>
<?php if (!empty($row['image_reference_id'])) {
$data1 = mysqli_query($con, "SELECT * FROM `photo_table` WHERE image_unique_id = '" . $row['image_reference_id'] . "'");
$row1 = mysqli_fetch_assoc($data1)
?>
<td><img src="data:image/jpg;base64,'.base64_encode($row['images']).'"/></td>
<?php } else {
?>
<td><img src="../images/<?php echo $row['app_image'] ?>" style="width: 100px; height: 100px;"></td>
<?php } ?>
<td><?php echo $row['app_name'] ?></td>
<td><?php echo $row['app_mobile_no_1'] ?></td>
</tr>
<?php } ?>
</tbody>
Note: In db the images are in Long Blob
You will need to change the following:
<img src="data:image/jpg;base64,'.base64_encode($row['images']).'" />
to
<img src="data:image/jpg;base64, <?php base64_encode($row['images']);?>" />

Can't list result from sql to html table

Trying to list the data from mysql to a html table using php in main html file. I've been through all of the other questions on here and I'm sure I have mostly the same methods and code as them.
For some reason (which I suspect has something to do with mysql and not the code) the only result is a blank table with one row and five columns. Each time I try to implement the other codes they just seem to print text onto the site.
I'm very confused as I think I've done the right thing. I've even been able to list the data from mysql through php echo so I know it's there and that I can access it. Really would appreciate some help on this. Thank you.
<table border="1">
<tbody>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query("SELECT title,url,details,file,submission_date FROM input");
while($row = mysqli_fetch_array($results)) {
?>
<td><?php echo $row['title']?></td>
<td><?php echo $row['url']?></td>
<td><?php echo $row['details']?></td>
<td><?php echo $row['file']?></td>
<td><?php echo $row['submission_date']?></td>
<?php
}
?>
</tbody>
</table>
You say this code is in your mail html file? And it is printing out onto the screen? Try changing your file to .php not .html! Php code won't run in a .html file, and will likely output your code directly onto the page.
Mysqli_query expect connection link as first parameter.
$results = mysqli_query($connect, "SELECT title,url,details,file,submission_date FROM input");
Just a quick not so related improvement. You can avoid inserting most of the php opening and closing clauses:
...
while($row = mysqli_fetch_array($results)){
echo "<td>".$row['title']."/td>";
echo "<td>".$row['url']"</td>";
...
}
?>
Use <tr> because table must have atleast one row(<tr>) and one column(<td>)
<table border="1">
<tbody>
<tr>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query("SELECT title,url,details,file,submission_date FROM input");
while($row = mysqli_fetch_array($results)) {
?>
<td><?php echo $row['title']?></td>
<td><?php echo $row['url']?></td>
<td><?php echo $row['details']?></td>
<td><?php echo $row['file']?></td>
<td><?php echo $row['submission_date']?></td>
<?php
}
?>
</tr>
</tbody>
<table border="1">
<tbody>
<?php
$connect = mysqli_connect("localhost", "daemon", "xampp", "test");
if (!$connect) {
die(mysqli_error());
}
$results = mysqli_query($connect, "SELECT title,url,details,file,submission_date FROM input");
if (!$results) {
mysqli_error($results);
die();
}
while ($row = mysqli_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['title'] ?></td>
<td><?php echo $row['url'] ?></td>
<td><?php echo $row['details'] ?></td>
<td><?php echo $row['file'] ?></td>
<td><?php echo $row['submission_date'] ?></td>
</tr>
<?php
}
?>
</tbody>
</table>

Add Echo in PHP

underneath is a small script which shows if someone has a birthday today.
The only thing what i miss is a line under the name with the text "Happy birthday" It should only appear, ofcourse is someone has a birthday. how can i achieve this?
<html>
<head>
<title>Vandaag Jarig:</title>
</head>
<body>
<table>
<thead>
</thead>
<tbody>
<?php
$connect = mysql_connect("localhost","root", "****");
if (!$connect) {
die(mysql_error());
}
mysql_select_db("my_site_db");
$results = mysql_query
("SELECT * FROM aevinew2_verjaardagen WHERE DAY(geboortedatum) = DAY (CURDATE ()) AND MONTH(geboortedatum) = MONTH(CURDATE())");
if(mysql_num_rows($results) > 0){
while($row = mysql_fetch_array($results)) {
?>
<tr>
<td><?php echo $row['Naam']?></td>
<td><?php echo $row['Afdeling']?></td>
</tr>
<?php
}
}else{
echo "Helaas geen taart vandaag, er is niemand jarig";
}
?>
</tbody>
</table>
</body>
</html>
Something like this? You had syntax error in your code aswell. Missing ; delimiter at end of echo command.
<td><?php echo $row['Naam'].'<br/>Happy Birthday!'; ?></td>
<td><?php echo $row['Afdeling']; ?></td>
Replace line 22 ,23 with these lines. You are missing ';' after echo statement.
<td><?php echo $row['Naam'].'<br/>Happy Birthday!'; ?></td>
<td><?php echo $row['Afdeling']; ?></td>
well, the script is working (it was already), but the only thing i need is an echo under the current echo which is just showing some text.
If i do that it letterly puts that kind of text on top include the text Echo

Display a tables value when a record is not empty

I have an activity table that contain the list of activity student had joined before. So if the student is new student, there will have been no activity for that student.
<table align="center" width="1000" border="1" >
<h3>Activity List</h3>
</br>
<tr align="center" style="font-weight:bold" >
<td>ID</td>
<td>Activity</td>
<td>Sem</td>
<td>Session</td>
<td>Achievement</td>
<td>Level</td>
</tr>
<?php do { ?>
<tr align="center">
<td><?php echo $row_Recordset1['student_id']; ?></td>
<td><?php echo $row_Recordset1['activity']; ?></td>
<td><?php echo $row_Recordset1['sem']; ?></td>
<td><?php echo $row_Recordset1['session']; ?></td>
<td><?php echo $row_Recordset1['achievement']; ?></td>
<td><?php echo $row_Recordset1['level']; ?></td>
</tr>
<?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
How can I make this table only show on screen if it is not empty. Btw, im using session to display the exist record.
The best way to do this would be to get your array via mysql(i)_fetch_array() of the query you have build and then to chec to see if the query has rows like:
$qry = "SELECT `this` FROM `table`"
while ($result = mysql_fetch_array($qry)) {
if (mysql_num_rows($result) > 0) {
echo "We have rows!";
}
else {
echo "Looks like we haven't got anything here!";
}
}
I hope this helps.
Might also help to look here: PHP mysql_num_rows method.
<?php if(!empty($activity))
{
your msg ..
}
else
{
}
?>
where empty() will check a given variable is empty or not
Well that's what the if statement is used for:
if(!count($activities)) {
echo "This student has no activities yet.";
} else {
//display activities
....
}

how to parse the contents of a particular row of a html table into array

I need to pass a one of these row contents of features-table to an array. But the problem is I used an iframe to display the table. And I need it to happen when after clicking the image of particular row.
In main.php
<iframe id="ifrm" src="reserved_tables/reserved_rooms_table.php"></iframe>
In reserved_rooms_table.php
<?php
include '../core/init.php';
$username = $user_data['username'];
$que = "SELECT * FROM ordered_rooms WHERE `username` LIKE '$username'";
$reslt = mysql_query($que);
echo '<table class="features-table" >';
echo '<thead>
<tr>
<td></td>
<td>Date</td>
<td>Start At</td>
<td>End At</td>
<td>Action</td>
</tr>
</thead>
<tbody>';
while($row = mysql_fetch_array($reslt)){
echo '<tr><td>' . $row['room_name'] .' </td><td> '. $row['date'] . '</td><td>'. $row['s_at'].'hrs</td>
<td>'. $row['e_at'].'hrs</td><td><input type="image" src="../images/cross.png" onclick="delete();" value=""></td></tr>';
}
echo "</tbody></table>";
mysql_close(); //connection closed
?>
It isn't entirely clear what you're trying to do. If you want to take data from an HTML table row and send it to a PHP array after a click then you'll need to use javascript.
Keep it simple. Create a link that sends the data to whatever URL/file does the processing:
while ($row = mysql_fetch_array($reslt)) {
?>
<tr>
<td><?php echo $row['room_name'] ?></td>
<td><?php echo $row['date'] ?></td>
<td><?php echo $row['s_at'] ?>hrs</td>
<td><?php echo $row['e_at'] ?>hrs</td>
<td><a id="my_link" href="some_file.php?room_name=<?php echo $row['room_name'] ?>&date=<?php echo $row['date'] ?>&s_at=<?php echo $row['s_at'] ?>&e_at=<?php echo $row['e_at'] ?>"><input type="image" src="../images/cross.png" value=""><a/></td>
</tr>
<?php
}
The data will then be available to some_file.php in $_GET.
Note that you can still use javascript to process this dynamically. You could add a click function to the link, so that when it is clicked, it does an AJAX call using the href value. For example:
$('#my_link').click(function() {
$.ajax({
url: this.href
});
});

Categories