Display Images from Database via PHP - php

I want to display the images, stored in a table, in PHP Database, table name is "bbmp" and the column containing the images is named as, "image"
Please help me in the code in this matter as it shows my output like this
<?php
include("dbconnection.php"); // it contains all the details of the database name, database host and password
$y=$sql = "SELECT * FROM `bbmp`";
$result = mysql_query($y);
echo "<table align='center'> <tr> <td> uid </td> <td> username </td> <td> Address </td> <td> email </td> <td> description </td> <td> status </td> <td> Images </td> </tr>";
if(!$result)
{
echo "not run ($y) from: ".mysql_error();
exit;
}
while($pat=mysql_fetch_assoc($result))
{
$uid=$pat['uid'];
$username=$pat['username'];
$address=$pat['address'];
$email=$pat['email'];
$description=$pat['description'];
$status=$pat['status'];
$image=$pat['image'];
echo "<tr> <td> $uid </td> <td> $username </td> <td> $address </td> <td> $email </td> <td> $description </td> <td> $status </td> <td> $image </td> </tr>";
}
echo "</table>";
?>
<html>
<body>
Go Back
</body>
</html>
All the field is viewed except image. It shows image in some uni-code. Please help

i dont see your output, i hope this will help you..
if your image column contains image path, you must write
<img src="$image">
but
your column contains image as binary you can write
<img src="data:image/png;base64,$image">
if your image data is base64 encoded
also, if your image saved binary data, you can show it like below;
<img src="image.php?data=xxxxx">
your image.php header must be image/jpg etc...

Related

How to make sum of all rows in mysql OR how to show show data in following way using mysql

This data is showing in MySql Database
<table>
<tr>
<td>
Team
</td>
<td>
Score
</td>
</tr>
<tr>
<td>
New Zealand
</td>
<td>
10
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Australia
</td>
<td>
5
</td>
</tr>
<tr>
<td>
New Zealand
</td>
<td>
5
</td>
</tr>
</table>
and I want to show data on webpage like this
<table>
<tr>
<td>
Team
</td>
<td>
Score
</td>
</tr>
<tr>
<td>
New Zealand
</td>
<td>
15
</td>
</tr>
<tr>
<td>
2
</td>
<td>
Australia
</td>
<td>
5
</td>
</tr>
</table>
Note that in database "New Zealand" showing 2 time in Database but on webpage it showing 1 time and also its score in sum
please tell me how can I do this using mysqli
Thanks in Advance.
Without your query I can't use your table or field names, but it would look something like this:
SELECT `team`, SUM(`score`) AS `score_sum` FROM `teams` GROUP BY `team`
This groups the rows by team and for each group, the scores are summed for that team. You would then access the team name using team and the total score for each team using score_sum in your PHP code. You'll have to provide more details like your query and code if this doesn't help.
I'll give a suggestion for your table , considering that you have already created soccer table with three columns ID,Team,Score . regardless a way you insert a data in this table , here how to get it properly
<?php
include("connection.php");
$team = "select distinct team from soccer";
$team2 = mysqli_query($mysqli,$team);
$up = "0";
$id ="1";
echo "<table><tr><td>ID</td><td>TEAM</td><td>SCORE</td></tr><tr>";
while ($teamres = $team2->fetch_array()){
echo "<td>".$id."</td><td>".$teamres['team']."</td>";
$score = mysqli_query($mysqli,"SELECT sum(score) FROM soccer where team ='".$teamres['team']."'");
$score2 = mysqli_fetch_row($score);
$scorere = $score2[0];
echo "<td>".$scorere."</td>";
echo "</tr>";
$id++;
$up++;
}
echo "</table>";
?>

MYSQL/PHP Where can i insert

Is it possible somehow to color "company_owner" by the code which user_color holds? That when you open select list, for the sample: Richerson, Rick would be colored by the code which user table has user_color.
$q->addQuery('user_id');
$q->addQuery('user_color');
$q->addQuery('CONCAT_WS(", ",contact_last_name,contact_first_name)');
<tr>
<tr>
<td align="right">
<?php echo $AppUI->_('Kompanijos savininkas'); ?>:
</td>
<td>
<?php
echo arraySelect($owners, 'company_owner', 'size="1" class="text"',
((#$obj->company_owner) ? $obj->company_owner : $AppUI->user_id));
?>
</td>
</tr>
Fetch the content in user_table, register it into a var and parse it in html or in css, don't know how do that in mysqli but if you want I can write it in mysql

How to parse data from a xml into a table and make it update changes live

I have stumbled upon a bit of a issue and I'm hoping that I can get some help/pointer here how to overcome it.
I have an external xml file that I need to parse and display in the table. I did this.
The issue is that the file is updating every second, so I would like the data in the cells to update "live" as well, according to the changes in xml file.
The problem is that I don't know what should I use to do it. Can anyone please point me into right direction.
<?php
require('simple_html_dom.php');
$html = file_get_html('http://admin:admin#192.168.1.108/status.xml');
foreach($html->find('response') as $row) {
$frontdoorlock = $row->find('led1',0)->plaintext;
$reardoorlock = $row->find('led2',0)->plaintext;
$fronthandle = $row->find('btn0',0)->plaintext;
$frontdoor = $row->find('btn1',0)->plaintext;
$rearhandle = $row->find('btn2',0)->plaintext;
$reardoor = $row->find('btn3',0)->plaintext;
$temperature = $row->find('temp0',0)->plaintext;
$humidity = $row->find('humid0',0)->plaintext;
$currentdate = $row->find('temp2',0)->plaintext;
$lastpowered = $row->find('temp3',0)->plaintext;
}
?>
<div>
<table>
<tr>
<td>
Cabinet Name
</td>
<td >
Front Door Lock
</td>
<td>
Front Handle
</td>
<td>
Front Door
</td>
<td>
Rear Door Lock
</td>
<td>
Rear Handle
</td>
<td>
Rear Door
</td>
<td>
Temperature
</td>
<td>
Humidity
</td>
<td>
Current Date
</td>
<td>
System Last Powered
</td>
</tr>
<tr>
<td>
Cab1
</td>
<td >
<?php if($frontdoorlock == "0") echo "CLOSED";
else echo "OPEN";
?>
</td>
<td>
<?php if($fronthandle == "0") echo "CLOSED";
else echo "OPEN";
?>
</td>
<td>
<?php if($frontdoor == "0") echo "OPEN";
else echo "CLOSED";
?>
</td>
<td>
<?php if($reardoorlock == "0") echo "CLOSED";
else echo "OPEN";
?>
</td>
<td>
<?php if($rearhandle == "0") echo "CLOSED";
else echo "OPEN";
?>
</td>
<td>
<?php if($reardoor == "0") echo "OPEN";
else echo "CLOSED";
?>
</td>
<td>
<?php echo $temperature; ?>
</td>
<td>
<?php echo $humidity; ?>
</td>
<td>
<?php echo $currentdate ?>
</td>
<td>
<?php echo $lastpowered ?>
</td>
</tr>
If you don't wan't to change the logic of the page itself ... like doing everything with javascript. You can simply put a:
<META HTTP-EQUIV="refresh" CONTENT="15">
meta tag in your HTML ... then the browser will update the page every X seconds (being the CONTENT value).
This being the simplest solution for the current situation.
But I would highly suggest to do this with JavaScript. There a tons of frameworks that will do the hard stuff for you.
My personal favourite: VueJS
Have you considered a front-end framework like angularJs that supports data binding? Data-binding is incredibly powerful and I feel like it would be the perfect solution for your problem. Here's a quick video demonstrating it.
You can bind your output table to a variable that represents that data, which updates each second according to the XML.

How to display pictures to a Gallery from references of filenames with PHP

I must be doing something wrong here. It doesn't work like it should but its a simple task that serves only one purpose, display the photos from my ./images and ./thumbnails folder to my PHP web form. It is not fully finished but I would just like to get the functionality of being able to see my displayed photos on my page.
Image name are the same in both folders, size is different. Here are some sample photo names in the two folders. IMG786_3, IMG3413, IMG31.
Here is the query to my database in which it retrieves all the title, description, and file name of all photos stored in my database. I put them into an array so I can access them based on an index.
$imgQuery = "SELECT FileName, Title, Description FROM PICTURE WHERE OwnerID='$id' LIMIT 0,7";
if($imgResult = mysqli_query($link, $imgQuery))
{
while($imgRow = mysqli_fetch_row($imgResult))
{
$filename[] = $imgRow[0];
$title[] = $imgRow[1];
$description[] = $imgRow[2];
}
}
Below is the code that is supposed to display these strings of photos from the two folders I have. When I click on a thumbnail, it is suppose to bring that full size image from the ./images folder and the entire index of the filename, description, and title will change.
print <<<photo
<body>
<span> <?php echo $error; ?> </span>
<form action='MyAlbum.php' method='post'>
<table>
<tr><td colspan='7' ><h2 align='center'>$name's Album</h2></td>
</tr>
<tr><td colspan='7' >$title[$i]</td>
</tr>
<tr><td colspan='5' ><img src="./images/$filename[$i]" /></td><td colspan='2'>$description[$i] </td>
</tr>
<tr>
<td><img src="./thumbnails/$filename[0]" /></td> <td><img src="./thumbnails/$filename[1]" /></td> <td><img src="./thumbnails/$filename[2]" /></td>
<td><img src="./thumbnails/$filename[3]" /></td><td><img src="./thumbnails/$filename[4]" /></td> <td><img src="./thumbnails/$filename[5]" /></td>
<td><img src="./thumbnails/$filename[6]" /></td>
</tr>
</table>
</form>
</body>
</html>
photo;
Your heredoc is wrong.
1st - You should iterate over file name to get the thumbnails.
2nd - you are getting images with variable $i which looks like an iterator but no for loop present.
I have modified the heredoc into html which works. You will still need javascript/jquery(i prefer) to achieve your image replacement to work. By default when the page loads the first image is displayed.
<html>
<body>
<span> <?php //echo $error; ?> </span>
<form action='MyAlbum.php' method='post'>
<table border="1">
<tr><td colspan='7' ><h2 align='center'><?php echo $name ?>'s Album</h2></td>
</tr>
<tr><td colspan='7' >
<?php echo $title[0]; ?></td>
</tr>
<tr>
<td colspan='5' ><img src="./images/<?php echo $filename[0] ?>" /></td>
<td colspan='2' ><?php echo $description[0]; ?></td>
</tr>
<tr>
<?php foreach($filename as $f): ?>
<td><img src="./thumbnails/<?php echo $f ?>" /></td>
<?php endforeach; ?>
</tr>
</table>
</form>
</body>
</html>
One more thing. using 3 different arrays is not efficient. 1 associative array can achieve this work fine. Lemme know if you have doubts.
Dins

PHP MySQL populating values from database

lets say i retrieve all of the values where their position belongs to top8.I populate them out in a table and instead of displaying different kinds of values , it displays 3 tables with 3 different values, how is this so? any help so that different values belonging to certain values will all be displayed out? i only need one table with 3 different values.
<?
$facebookID = "top8";
mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("schoutweet") or ie(mysql_error());
$data= mysql_query("SELECT schInitial FROM matchTable WHERE position='".$facebookID."'")
or die(mysql_error());
while($row = mysql_fetch_array($data))
{
?>
<center>
<table border="0" cellspacing="0" cellpadding="0" class="tbl_bracket">
<tr>
<td class="brack_under cell_1"><a href="www.facebook.com"/>team 1.1><?= $row['schInitial']?><a/></td>
<td class="cell_2"> </td>
<td class="cell_3"> </td>
<td class="cell_4"> </td>
<td class="cell_5"> </td>
<td class="cell_6"> </td>
</tr>
<tr>
<td class="brack_under_right_up">team 1.2><?= $row['schInitial']?></</td>
<td class="brack_right"><!--1.2.1--></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="brack_right"><!--2.1--></td>
<td class="brack_under"><!--3.1--></td>
<td><!--here?--></td>
<td><!--there?--></td>
<td><!--everywhere?--></td>
</tr>
</table>
</center>
<?
}
?>
</body>
That's because your <table> tag is within the loop! Place the <table> tag outside the while loop.
place your table tags outside the while loop
Because your writing the table tag inside the while loop. Everything inside the loop is done each loop cycle. If you only want to have one table in the output, you'll have to open and close the table outside of the loop, like this:
$data= mysql_query("SELECT schInitial FROM matchTable WHERE position='".$facebookID."'")
or die(mysql_error());
?>
<center>
<table border="0" cellspacing="0" cellpadding="0" class="tbl_bracket">
<?
while($row = mysql_fetch_array($data))
{
?>
<tr>
<td class="brack_under cell_1"><a href="www.facebook.com"/>team 1.1><?= $row['schInitial']?><a/></td>
<td class="cell_2"> </td>
<td class="cell_3"> </td>
<td class="cell_4"> </td>
<td class="cell_5"> </td>
<td class="cell_6"> </td>
</tr>
<tr>
<td class="brack_under_right_up">team 1.2><?= $row['schInitial']?></</td>
<td class="brack_right"><!--1.2.1--></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td class="brack_right"><!--2.1--></td>
<td class="brack_under"><!--3.1--></td>
<td><!--here?--></td>
<td><!--there?--></td>
<td><!--everywhere?--></td>
</tr>
<?
}
?>
</table>
</center>
That will, however, print three rows per loop and therefore per record (but you have references to the table contents in two of them, so I suppose that's what you want?).
Also take care about some not well-formed HTML you have there (e.g. the > character in the expression team 1.1> / team 1.2>. If you want to print the > character to the browser, encode it as HTML entity (> for this case). You also have a probably superfluous </ in the first column of the second row (</</td>).
you need to echo the HTML part as well in the while loop like
echo '<table>';

Categories