how to display images whose names are stored in database - mysql

I had created a table in mysql database. I am using php One column was for images, but it only stored images name. I wanted to print the whole table so did the coding but got got only the name of the images in the table.
Please explain how can I display images on the webpage that are stored in my PC. I don't want to save images in the database.
I used this code to print the table :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$query="SELECT * FROM images LIMIT 0,5";
$result = #mysql_query($query);
echo "<table border='1'>
<tr>
<th>S.No.</th>
<th>Image</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['image_id'] . "</td>";
echo "<td>" . $row['filename'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Hope you got some answer....

All your code is doing is sending the filename to the screen as a string. You need to the use image tags.
You may find this page useful, http://www.htmlcodetutorial.com/images/_IMG.html

Related

Create a div on my website that shows database information with php

I need to create a div that only shows the information of the database, how should i connect the div to mysql so it only shows my database information?
I'm not sure I'm understanding your question... but I'll give it a try. The code below this will select whatever you tell it to from the database and echo it into a table.
<?php
$db = mysqli_connect('host', 'username', 'password', 'database');
$sql = "SELECT * FROM database"
mysqli_stmt_bind_param($db, "params here", your info here);
$res = mysqli_stmt_execute($sql);
mysqli_stmt_close($sql);
mysqli_close($db);
echo "<table>";
while($row = mysqli_fetch_array($res)){ //Creates a loop to loop through results
echo "<tr><td>" . $row[''] . "</td><td>" . $row[''] . "</td></tr>"; //$row['index'] the index here is a field name
}
echo "</table>";
?>

Having trouble using result of mysql Min() in php

$minTime = "Select MIN(categoryTime) FROM List WHERE personStatus='Atendiendo' AND depName='Admisiones'";
$Time = mysqli_query($con,$minTime);
echo "<table>
<tr>
<th>Main Record</th>
<th>Tiempo Categoria</th>
<th>Tiempo Estimando</th>
<th>Time IN </th>
</tr>";
while($min = mysqli_fetch_array($Time))
{
echo "<tr>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "<td>" . $min['categoryTime'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
If I delete the MIN() function the query works perfectly...
The query work if I delete the Min() fuction. I tried Least() with no success.
Several issues here.
I think the snippet is missing:
$Time =mysqli_query($con,$minTime);
where $con is the connection.
When you add the MIN function around the categoryTime field, the label of the column in the resultset changes, so the reference to $min['categoryTime'] no longer returns anything. Try changing query to
SELECT MIN(categoryTime) as minCat ...
then change the php array column reference to $min['minCat']
HTH

How to repeat different pic?

I wan to always display the different pic. So there's a problem with looping the different pic. How do i do that?
index.php:
<?php
$result = mysql_query("SELECT * FROM table2", $connection );
echo '<ul>';
while($row = mysql_fetch_array($result)) {
if ($row)
echo "<li>";
echo "<img src='code.php?id=3'>";
echo "&nbsp";
echo "</p>";
echo "</li>";
echo "<br/>" ;
}
echo '</ul>';
mysql_close($connection);
?>
You need to pull the id value from the database. If you have a column called, maybe id you would want to put:
while($row = mysql_fetch_array($result)){
if ($row){
echo "<li>";
echo "<img src='code.php?id=".$row['id']."'/>"; // see what I did there?
echo "&nbsp";
echo "</p>"; // take this out
echo "</li>";
echo "<br/>"; // take this out
}
}
P.S. - don't write new code using the deprecated mysql extension. Use PDO or mysqli at least. And don't put <br />s between your <li>s, or close unopened <p>s. And, generally speaking, don't store your images in your database - just store the path to the image and put the images themselves in a folder on the server where they belong.
And please format your code - it is hard to read with no indentation or separation of files (your if statement was not properly enclosing what should have been conditioned statements). And mysql_real_escape_string is not as cool as you think it is.
Hope this helps.

Present data from a MySQL view into HTML using PHP [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I am trying to simply show a view in MySQL using PHP but I keep getting and error. Any advice on what the T_STRING error might be? Thanks.
Parse error: syntax error, unexpected T_STRING in
/home/theaudit/public_html/_sandbox/index.php on line 14
<?php
// connection parameters
$db_host="a";
$username="b";
$password="c";
$db_name="d";
// connection variables
$db_con=mysql_connect($db_host,$username,$password);
$connection_string=mysql_select_db($db_name);
// page variables
$query = SELECT * FROM a_aif_remaining;
$result = mysql_query($query);
// connection to mysql and db
mysql_connect($db_con) or die("Unable to connect to MySQL");
mysql_select_db($db_name) or die("Unable to select database");
// successful result
echo "<table border=1>
<tr>
<th>aif</th>
<th>fee_source</th>
<th>company_screename</th>
<th>filing_date</th>
<th>document_subtype</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['aif_id'] . "</td>";
echo "<td>" . $row['fee_source_id'] . "</td>";
echo "<td>" . $row['company_name_per_sedar'] . "</td>";
echo "<td>" . $row['document_filing_date'] . "</td>";
echo "<td>" . $row['document_subtype'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
$query = SELECT * FROM a_aif_remaining;
needs to be:
$query = "SELECT * FROM a_aif_remaining";
Get yourself a better editor and you can fix and improve your code in no time:
<?php
// connection parameters
$db_host = "a";
$username = "b";
$password = "c";
$db_name = "d";
// connection variables + connection to mysql and db
$db_con = mysql_connect($db_host, $username, $password);
$result = mysql_select_db($db_name, $db_con);
// page variables
$query = 'SELECT * FROM a_aif_remaining';
$result = mysql_query($query, $db_con);
// successful result
echo '<table border=1>
<tr>
<th>aif</th>
<th>fee_source</th>
<th>company_screename</th>
<th>filing_date</th>
<th>document_subtype</th>
</tr>';
while ($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['aif_id'] . "</td>";
echo "<td>" . $row['fee_source_id'] . "</td>";
echo "<td>" . $row['company_name_per_sedar'] . "</td>";
echo "<td>" . $row['document_filing_date'] . "</td>";
echo "<td>" . $row['document_subtype'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($db_con);
?>

retrieve two database table values in a single html table

I have a table(webmeasurementsuite) in my database(probe_config).I have written an php coding to retrieve the datas from the database and display it in the html table.Can anyone correct my errors please.when I load the php page to the browser,I am getting a blank page.
<?php
$con = mysql_connect("localhost","root","mysql");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM webmeasurementsuite");
echo "<table border='1'>
<tr>
<th>replication</th>
<th>wait</th>
<th>timeout</th>
<th>clearcache</th>
<th>name</th>
<th>wms</th>
</tr>;
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['replication'] . "</td>";
echo "<td>" . $row['wait'] . "</td>";
echo "<td>" . $row['timeout'] . "</td>";
echo "<td>" . $row['clearcache'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['wms'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
I think you need to learn more about Web Development.
HTML is used only for rendering the information in an appropriate format. For accessing the database records, we got to use server side Scripting Languages or Web Technologies(J2EE, JSP, ASP, and more) to access the database. That one can not be done with HTML alone.
If am wrong, please brief your question bit more.