Recently I've set it up so I can update my sites news via my administration panel and now I've been seeking across the web for a solution to print specific lines.
$query = "SELECT * FROM BananzaNews";
$result = mysql_query("SELECT * FROM BananzaNews", $con);
$num_rows = mysql_num_rows($result);
The above tells me how many rows I have and for my five most recent which will be shown on my home page, I want to fetch the data for $num_rows, $num_rows -1, $num_rows -2, $num_rows -3 and $num_rows -4.
The data to fetch;
title
newsDate
imagePath
content
websitePath
My current dummy filled code is the following dubplicated five times;
<div class="Feed">
<div class="Img"><img alt="" src="http://www.davidreneke.com/wp-content/uploads/2013/12/News-Briefs.png"></div>
<div class="Title">My Testing Title</div>
<div class="Date">
<div class="Day">22</div>
<div class="Month">Jan</div>
<div class="Year">2015</div>
</div>
<div class="Brief">Vivamus consectetur et sapien vel rhoncus. Maecenas gravida posuere hendrerit. Duis lobortis justo ac justo malesuada commodo. Proin iaculis, erat ac aliquet eleifend, neque felis tristique turpis, at dictum tellus lectus et lorem. Nunc turpis enim, auctor sed purus nec.</div>
<div class="More"></div>
<div class="Divider"></div>
</div>
My PHP
<?php
$query = 'SELECT title,newsDate,imagePath,content,websitePath FROM BananzaNews ORDER BY id Desc LIMIT 5';
$resultSe = mysql_query($query, $con);
if (mysql_num_rows($result) > 0) {
while($row = $resultSet->fetchRow ( DB_FETCHMODE_OBJECT )){
echo "<div class=\"Feed\">
<div class=\"Img\"><img alt=\"\" src=\"" $row->imagePath "\"></div>
<div class=\"Title\">" $row->title "</div>
<div class=\"Date\">
<div class=\"Day\">" $row->newsDate "</div>
<div class=\"Month\">" $row->newsDate "</div>
<div class=\"Year\">" $row->newsDate "</div>
</div>
<div class=\"Brief\">" $row->content "</div>
<div class=\"More\">" $row->websitePath "</div>
<div class=\"Divider\"></div>
</div>";
}
}
?>
Database View
You want to use MySQL's ORDER BY. You don't need to use num_rows to get the 5 latest posts. Simply order them by their id columns and then LIMIT it to 5. If they don't have id columns, they should have an id column that auto_increments and is a PRIMARY KEY. With that, this code will help you:
//Load your mysql_query into a variable SELECTing not *, but only the rows you need.
$query = mysql_query("SELECT title, newsDate, imagePath, content, websitePath FROM BananzaNews ORDER BY newsid DESC LIMIT 5") or die(mysql_error()); //<- Error handling.
//This loads up each row into an associative array into the variable $row
//So, $row['title'] will be equal to the 'title' column at that row in your database
while($row = mysql_fetch_array($query)){
//Output your repeating code
//Notice how I've used concat operators (dots) to stop the echo and start it again.
//I'd recommend looking those up if you haven't.
echo
'<div class="Feed">
<div class="Img"><img alt="" src="'.$row['imagePath'].'"></div>
<div class="Title">'.$row['title'].'</div>
<div class="Date">
<div class="Day">22</div>
<div class="Month">Jan</div>
<div class="Year">2015</div>
</div>
<div class="Brief">'.$row['content'].'</div>
<div class="More"></div>
<div class="Divider"></div>
</div>';
}
I would actually also use mysqli over mysql, mainly because it's well... mysql-improved. Do look into it, I highly recommend it. Even better, use PDO.
I hope this was helpful!
if you want to get the data to fetch run your query in while loop
$result=mysqli_query("select * from table_name order by id desc limit 0,5")
while($each=mysqli_fetch_array($result ))
{
//your code goes here
}
Use this query it will work for you
$query = 'SELECT title,newsDate,imagePath,content,websitePath FROM BananzaNews ORDER BY id Desc LIMIT 5';
$resultSet = mysql_query($query);
if (mysql_num_rows($query) > 0) {
while($row = mysql_fetch_array($resultSet)){
echo $row['title'];
echo $row['newsDate'];
}
}
You can loop your data like this.
Try this it will work :
1. use mysqli or pdo instead of mysql extension. It already depreciated and will be remove in future.
2. Loop your result set to get all the data from the table.
<?php
$result = mysqli_query($con,"SELECT * FROM BananzaNews LIMIT 0,5");
$rs = mysqli_fetch_array($result);
?>
<table>
<?php
do
{
?>
<tr>
<td><?php echo $rs['title']; ?></td>
<td><?php echo $rs['newsDate']; ?></td>
<td><?php echo $rs['imagePath']; ?></td>
<td><?php echo $rs['content']; ?></td>
<td><?php echo $rs['websitePath']; ?></td>
</tr>
<?php
}while($rs = mysqli_fetch_array($result));
?>
</table>
Related
I am using the code snippet available here
My PHP code is :
<?PHP
/*** This is for bottomless listing of record from a table ****/
$sql = 'SELECT * FROM agency_list ORDER BY id DESC LIMIT 0, 5';
$query = $dbo4->prepare($sql); // dbo4 coming from config.php
$query->execute();
$list = $query->fetchAll();
?>
The relevant css code is:
.content {
padding: 10px;
min-height: 100px;
text-align: center;
}
#loader {
text-align: center;
display: none;
}
#items {
list-style: none;
text-align: left;
}
#items li {
margin: 0 0 10px 0;
background: #FFFFFF; /* original -- f1f0f0*/
border: 1px solid #999999;
border-radius: 5px;
color: #333333;
}
#items li h2 {
font-size: 18px;
padding: 5px;
}
#items li p {
padding: 5px;
}
The java script code (end-less-scroll.js) is as following:
var is_loading = false; // initialize is_loading by false to accept new loading
var limit = 5; // limit items per page
$(function() {
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
if (is_loading == false) { // stop loading many times for the same page
// set is_loading to true to refuse new loading
is_loading = true;
// display the waiting loader
$('#loader').show();
// execute an ajax query to load more statments
$.ajax({
url: 'load_more.php',
type: 'POST',
data: {last_id:last_id, limit:limit},
success:function(data){
// now we have the response, so hide the loader
$('#loader').hide();
// append: add the new statments to the existing data
$('#items').append(data);
// set is_loading to false to accept new loading
is_loading = false;
}
});
}
}
});
});
Above code is invoking load_more.php which has following code:
<?PHP
include 'config.php';
$last_id = $_POST['last_id'];
$limit = 5;
if (isset($_POST['limit']))
{
$limit = intval($_POST['limit']);
}
// selecting the items for page params
try
{
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$query = $dbo4->prepare($sql);
$query->bindParam(':last_id', $last_id, PDO::PARAM_INT);
$query->bindParam(':limit', $limit, PDO::PARAM_INT);
$query->execute();
$list = $query->fetchAll();
}
catch (PDOException $e)
{
echo 'PDOException : '. $e->getMessage();
}
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id'];
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a>
<img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis?
Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis.
Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
if ($last_id != 0)
{
echo '<script type="text/javascript">var last_id = '.$last_id.';</script>';
}
// sleep for 1 second to see loader, it must be deleted in prodection
sleep(1);
?>
And finally the fetched records are being listed in this div (in HTML file)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="js/end-less-scroll.js"></script>
<div class="row">
<div class="twelve columns">
<div class="content">
<ul id="items">
<?PHP
$last_id = 0;
foreach ($list as $rs)
{
$last_id = $rs['id']; // keep the last id for the paging
?>
<li>
<h2> <a href='#'><?PHP echo '[' .$rs['id'] .'] ' . $rs['agency_nm']; ?></a><img height = "32px" width = "32px" src="images/face_smile_1.png"></h2>
<blockquote>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
<BR>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Et non ex maxima parte de tota iudicabis? Item de contrariis, a quibus ad genera formasque generum venerunt. Sit enim idem caecus, debilis. Duo Reges: constructio interrete.
</p>
</blockquote>
<h5> <?PHP echo $rs['agency_addr_landmark']; ?></h5>
<h5> <?PHP echo $rs['agency_city']. ' - ' . $rs['agency_pin'] . ' [' . $rs['agency_state'] . '] ' ; ?></h5>
<h5> <?PHP echo $rs['agency_contact_per_1']; ?></h5>
<h5> <font color = "maroon"><?PHP echo $rs['agency_contact_addr1'];?></font></h5>
<p style="align:right;">
Details
Update
More
</p>
<BR>
</li>
<BR>
<?PHP
}
?>
<script type="text/javascript">var last_id = <?PHP echo $last_id; ?>;</script>
</ul>
<!-- this is the paging loader, now is hidden, it wiil be shown when we scroll to bottom -->
<p id="loader"><img src="images/ajax-loader.gif"></p>
</div><!-- content -->
<hr>
</div>
</div>
My problem is that
(1) The code is working perfectly fine if I sort the records by ASC order in both the MySQL queries given. However, if I change the sorting order from ASC (as given in the linked tutorial) to DESC, the logic only lists for 5 records, then first 4, 3, 2, 1 records again and stops work. I know I am doing something very silly in the logic, but unable to find my mistake. Please help me.
(2) Assume that I need to sort by some other column (which is not the PRIMARY key - id being PRIMARY KEY here) e.g. suppose I want to sort the records by agency_nm and the list them using this in the bottom less listing fashion, am I supposed to make some changes in AJAX part (or load_more.php) as well? Sorry but I am not good in AJAX - hence this silly question.
Thanks / Regards to all for your kind help and suggestions.
Change the line:
$sql = 'SELECT * FROM agency_list WHERE id > :last_id ORDER BY id DESC LIMIT 0, :limit';
$sql = 'SELECT * FROM agency_list WHERE id < :last_id ORDER BY id DESC LIMIT 0, :limit';
All you have to do is change this operator: > to <
I'm a beginner so this may ba a stupid one.
I'm creating simple platform, which uses a database to manage my post stamps collection. I've managed to set up a database and gather new stamps from user. Now I want to create kind of "product page", which will use data from mySQL. You will be able to enter this page through a dynamically generated table, which will contain all stamps in the database.
The code,which generates a simple table is here:
//connect to database
$db = mysqli_connect(database login data);
if(mysqli_connect_errno()){
echo "Jest problem z podłączeniem się do bazy danych. Skontaktuj się z administratorem.";
die();
}
// loop through results of database query, displaying them in the table
$result = mysqli_query($db,"SELECT * FROM stamps");
?>
</head>
<body>
<?php include "navbar.php" ?>
<h1>Przeglądaj swoją kolekcję.</h1>
<?php
echo "<p><b>View All</b>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Nazwa</th> <th>Kraj</th> <th>Wartość nominalna</th> <th>Wartość rynkowa</th> <th>Klaser</th> <th>More info</th> <th>Edytuj</th> <th>Usuń</th></tr>";
while($row = mysqli_fetch_object($result)) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row->id . '</td>';
echo '<td>' . $row->name . '</td>';
echo '<td>' . $row->country . '</td>';
echo '<td>' . $row->price . '</td>';
echo '<td>' . $row->estimated . '</td>';
echo '<td>' . $row->album . '</td>';
echo "<td>More info.</td>";
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo "</tr>";
}
// close table>
echo "</table>";
?>
Now, I'd like to post database values to another page, after clicking "More info" and just view it something like that:
<body>
<?php include "navbar.php" ?>
<div class="jumbotron">
<img class="photo" src="http://placehold.it/250x250">
<h1>Znaczek z XIX wieku</h1> <!-- database data goes here -->
<h3>Informacje:</h3> <!-- database data goes here -->
<h5>Numer katalogowy:</h5> <!-- database data goes here -->
<h5>Rok wydania:</h5> <!-- database data goes here -->
<h5>Kraj:</h5> <!-- database data goes here -->
<h5>Wartość nominalna:</h5> <!-- database data goes here -->
<h5>Wartość rynkowa:</h5> <!-- database data goes here -->
<h5>Klaser:</h5> <!-- database data goes here -->
<h3>Opis:</h3> <!-- database data goes here -->
<h5><div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa, aliquam, tenetur voluptatibus veritatis numquam expedita nesciunt quos repudiandae similique atque provident ipsam dolorem recusandae id possimus minus ea eum cupiditate!</div>
<div>Sint, debitis, saepe repellendus commodi recusandae error architecto voluptates soluta ipsa facere perferendis aspernatur quo atque fugiat consequatur! Assumenda necessitatibus dolorem esse distinctio incidunt pariatur praesentium veniam voluptate quae quaerat!</div>></h5>
<p><a class="btn btn-primary btn-lg" role="button">Edytuj</a></p>
</div>
<?php include "footer.php" ?>
</body>
The question is: what is the best way to do it ?
Thanks in advance !
For generating page dynamically you can use $_GET['id'] for getting the id of the table, from where you are gonna fetch the data. Now put a get query after the link you wanna use,
It should look like this
Index.php?id=2
It is gonna fetch all the data from the second row.
But if you are like making a admin board or anything that is gonna modify the database do not use this, use secure login with user password verification,
Be sure to sanitize the id as this is going to used for getting the data in the database.
Hello I'm new to php development... I want to understand how to get details from database and display on HTML CSS... I have a database i'm saving hotel data... Now I want to pull these data and display it on website.. please find below html codes design...
<div class="offset-2">
<div class="col-md-4 offset-0">
<div class="listitem2">
<img src="images/items/item7.jpg" alt=""/>
<div class="liover"></div>
<a class="fav-icon" href="#"></a>
<a class="book-icon" href="details.html"></a>
</div>
</div>
<div class="col-md-8 offset-0">
<div class="itemlabel3">
<div class="labelright">
<img src="images/filter-rating-5.png" width="60" alt=""/><br/><br/><br/>
<img src="images/user-rating-5.png" width="60" alt=""/><br/>
<span class="size11 grey">18 Reviews</span><br/><br/>
<span class="green size18"><b>$36.00</b></span><br/>
<span class="size11 grey">avg/night</span><br/><br/><br/>
<form action="http://demo.titanicthemes.com/travel/details.html">
<button class="bookbtn mt1" type="submit">Book</button>
</form>
</div>
<div class="labelleft2">
<b>Mabely Grand Hotel</b><br/><br/><br/>
<p class="grey">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum nec semper lectus. Suspendisse placerat enim mauris, eget lobortis nisi egestas et.
Donec elementum metus et mi aliquam eleifend. Suspendisse volutpat egestas rhoncus.</p><br/>
<ul class="hotelpreferences">
<li class="icohp-internet"></li>
<li class="icohp-air"></li>
<li class="icohp-pool"></li>
<li class="icohp-childcare"></li>
<li class="icohp-fitness"></li>
<li class="icohp-breakfast"></li>
<li class="icohp-parking"></li>
<li class="icohp-pets"></li>
<li class="icohp-spa"></li>
</ul>
</div>
</div>
</div>
</div>
Please Suggest at the earliest
Example:
<?php
$database_data = array(
array(
'name' => 'A', 'age' => 28, 'email' => 'a#abc.com'
),
array(
'name' => 'B', 'age' => 27, 'email' => 'b#abc.com'
),
array(
'name' => 'C', 'age' => 26, 'email' => 'c#abc.com'
),
);
?>
Now loop through data and echo your value
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php foreach($database_data as $data): ?>
<tr>
<td><?php echo $data['name']; ?></td>
<td><?php echo $data['age']; ?></td>
<td><?php echo $data['email']; ?></td>
</tr>
<?php endforeach ; ?>
</tbody>
</table>
There are so many tutorials available online around pagination with PHP and database (for example MySQL). Follow some of the below and you will understand the concept and be able to apply to your page easily.
http://www.tutorialspoint.com/php/mysql_paging_php.htm
http://php.about.com/od/phpwithmysql/ss/php_pagination.htm
http://www.developphp.com/view_lesson.php?v=289
plz use limit tag of mysql to display the as your required data ..
I want ot provide some link
1). if i use LIMIT on a mysql query, should the result set be equal to the limit?
2). Limit
and then you should set the next button which tag a parameter as Start like index.php?start=20&limit=20 and then get on your query page like
$start=isset($_GET['start'])?$_GET['start']:0;
$limit=isset($_GET['limit'])?$_GET['limit']:20;
$query = mysql_query("select * from table limit $start,$limit ");
i Hope this help ful and if you want to set the pagination in your page then follow follow links
1). Pagination of MySQL Query Results
2). Simple Pagination With PHP & MYSQL
3). PHP Pagination
hope you get solution ...
I create a simple backed area for my client to post new job openings and was wanting to give them the ability to format the text a little by adding line breaks in the job description text that will be visible on the front end.
The job openings are stored in a MySQL database.
Example of what I'm talking about:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis quam sollicitudin, bibendum enim a, vulputate turpis.
Nullam urna purus, varius eget purus quis, facilisis lacinia nibh. Ut in blandit erat.
I've would like the breaks to happen when my client hits enter / return on the keyboard.
Any help on this matter would be appreciated.
------------UPDATE------------
okay so after much trial and error I got it somewhat working.
I added this line in my upload / action code.
$description = nl2br(htmlspecialchars($_POST['description']));
Full upload code is:
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
$date = mysql_real_escape_string($_POST["date"]);
$title = mysql_real_escape_string($_POST["title"]);
$description = mysql_real_escape_string($_POST["description"]);
$description = nl2br(htmlspecialchars($_POST['description']));
// Insert record into database by executing the following query:
$sql="INSERT INTO hire (title, description, date) "."VALUES('$title','$description','$date')";
$retval = mysql_query($sql);
echo "The position was added to employment page.<br />
<a href='employment.php'>Post another position.</a><br />";
?>
Then on my form I added this to the textarea, but I get an error.
FYI that is line 80 the error is refering to.
Position Details:<br />
<textarea name="description" rows="8"><?php echo str_replace("<br />","",$description); ?></textarea>
</div>
Here is what the error looks like.
Here is my results page code:
<?php
$images = mysql_query("SELECT * FROM hire ORDER BY ID DESC LIMIT 10");
while ($image=mysql_fetch_array($images))
{
?>
<li data-id="id-<?=$image["id"] ?>">
<div class="box white-bg">
<h2 class="red3-tx"><?=$image["title"] ?> <span class="date-posted blue2-tx"><?=$image["date"] ?></span></h2>
<div class="dotline"></div>
<article class="blue3-tx"><?=$image["description"] ?><br />
<br />
For more information please call ###-###-####.</article>
</div>
</li>
<?php
}
?>
If I delete all that error copy and write out a real position with line breaks it works.
I have no idea how to fix the error though.
Again any help would be appreciated.
Thanks!
you can use str_replace
$statement = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla quis quam sollicitudin, bibendum enim a, vulputate turpis.
Nullam urna purus, varius eget purus quis, facilisis lacinia nibh. Ut in blandit erat."
$statement = str_replace(chr(13),"<br/>", $statement);
query example : INSERT INTO table (statement) VALUES ('$statement');
hope this can help you
EDIT :
if you want display the result at textarea from database u can using this code
$des = $row['description'] //my assumption that your feild name at table inside mySQL is description
Position Details:<br />
<textarea name="description" rows="8"><?php echo str_replace("<br />",chr(13),$des); ?></textarea>
</div>
hope this edit can help your second problem
I would start by answering a couple of questions first
Do I want my database to store html-formatted user input?
Is the data going to be editable afterwards?
Since you seem to want only nl2br, a simple approach would be to save the content as is in the database, then use nl2br() on the output side as Marcin Orlowski suggested.
I am trying to do something easy I am sure but I have looked and tested and I am not doing something right.
I have a DB that stores the image file name, I need to get the file name based on the ID in the HTML , let me explain:
<div class="slide">
<div class="image-holder">
<img src="img/asoft_table.jpg" alt="" />
</div>
<div class="info">
<p>Morbi a tellus lorem, id scelerisque ligula. Maecenas vitae turpis et.</p>
</div>
</div>
<div class="slide">
<div class="image-holder">
<img src="img/soft_table.jpg" alt="" />
</div>
<div class="info">
<p>Sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p>
</div>
</div>
<div class="slide">
<div class="image-holder">
<img src="img/living_room2.jpg" alt="" />
</div>
in each instance of an img tag, I need to insert the filename from the DB. so, first image tag would be primary key 1, second primary key 2 and so forth.
Here is the PHP script I am using to retrieve the filename, which works, but I am unsure how to send the ID of the image to the script and then return it properly.
<?php
$hote = 'localhost';
$base = '*****';
$user = '*****';
$pass = '*****';
$cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$image_id = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT image FROM image_upload WHERE ID ='$image_id'";
$result = mysql_query($sql);
$image = mysql_result($result, 0);
header('Content-Type: text/html');
echo '<img src="' . $image . '"/>';
exit;
?>
any help would be appreciated, thanks a heap
From what it looks your trying too hard to separate the PHP from HTML.
// File: index.php
<?php
$hote = 'localhost';
$base = '*****';
$user = '*****';
$pass = '*****';
$cnx = mysql_connect ($hote, $user, $pass) or die(mysql_error ());
$ret = mysql_select_db ($base) or die (mysql_error ());
$image_id = mysql_real_escape_string($_GET['ID']);
$sql = "SELECT image FROM image_upload WHERE ID ='$image_id'";
$result = mysql_query($sql);
//$image = mysql_result($result, 0);
$image = array();
while ($row = mysql_fetch_assoc($result)) {
$image[] = $row["image"];
}
?>
<html>
<head>
</head>
<body>
<div class="slide">
<div class="image-holder">
<img src="<?php echo $image[0];?>" alt="" />
</div>
<div class="info">
<p>Morbi a tellus lorem, id scelerisque ligula. Maecenas vitae turpis et.</p>
</div>
</div>
<div class="slide">
<div class="image-holder">
<img src="<?php echo $image[1];?>" alt="" />
</div>
<div class="info">
<p>Sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p>
</div>
</div>
<div class="slide">
<div class="image-holder">
<img src="<?php echo $image[2];?>" alt="" />
</div>
</body>
</html>
// This is the magic code to get all the rows out of the database :)
// $row[ field_name ];
while ($row = mysql_fetch_assoc($result)) {
$image[] $row["image"];
}
Edit:
I'm not sure if this is what your trying to accomplish, but thought I'd share anyway.
$imageID1 = $_GET['id1'];
$imageID2 = $_GET['id2'];
$imageID3 = $_GET['id3'];
$sql = "SELECT image FROM image_upload ";
$sql = "WHERE ID = $imageID1 OR ID = $imageID2 OR ID = $imageID3";
//The rest of your code can remain the same.
Or if one id relates to 3 images.
$sql = "SELECT * FROM image_upload WHERE ID ='$image_id'";
$result = mysql_query($sql);
$image = array();
$row = mysql_fetch_assoc($result);
$image1 = $row["image1"];
$image2 = $row["image2"];
$image3 = $row["image3"];
I've you give me more info on what your trying to do, I'd be happy to give you a better example.
Make sure your HTML file is actually a php file. Put the PHP code at the top of it then put your HTML below it. You can use
<?php echo $image; ?>
to put the variable in like this:
<div class="slide">
<div class="image-holder">
<img src="<?php echo $image; ?>" alt="" />
</div>
<div class="info">
<p>Sed semper, lorem ac lobortis bibendum, magna neque varius augue, vel accumsan.</p>
</div>
</div>
It's always a good idea to use htmlentities for security (avoids javascript injection):
<img src="<?php echo htmlentities($image, ENT_QUOTES, "UTF-8"); ?>" alt="" />
Since you are using the $_GET array, you will want to send the ID through the URL, for instance:
http://www.example.com/image.php?ID=5
That is assuming you want to continue using $_GET for this script.