I have a PHP loop where i output some stuff from my database to my page but i have a problem, when runing the code it ends up on different lines like example 1 When i want it to be on the came line line example 2, i have tried usiv div, floating the container and using CSS to make it inline but it just end up like example 1 all the time, why?
Example 1:
1
2
3
4
5
Examle 2:
1,2,3,4,5
<?php
$getquery=mysql_query("SELECT * FROM dogs ORDER by ID LIMIT 5");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
echo '<br>';
echo '<div id="block" border="1" width="200" style="float:center">';
echo '
<a href="mypage.com/index.php?dog=', $id, '">
<img src="/thumb/', $id, '.jpg" alt="dogs!" />
</a>';
echo '</div>';
}
?>
Take line break out of the loop. Each time there is a result, you print <br> that's why it's on new line
echo '<br />';
echo '<div id="block" border="1" width="200" style="float:center">';
$getquery=mysql_query("SELECT * FROM dogs ORDER by ID LIMIT 5");
while($rows=mysql_fetch_assoc($getquery)){
$id=$rows['id'];
echo '<a href="mypage.com/index.php?dog='. $id .'">
<img src="/thumb/'. $id .'.jpg" alt="dogs!" />
</a>';
}
echo '</div>';
and yes to the comments - please look into using mysqli
with counter:
echo '<div id="block" border="1" width="200" style="float:center">';
$i = 0;
$getquery=mysql_query("SELECT * FROM dogs ORDER by ID LIMIT 5");
while($rows=mysql_fetch_assoc($getquery)){
$id=$rows['id'];
echo '<a href="mypage.com/index.php?dog='. $id .'">
<img src="/thumb/'. $id .'.jpg" alt="dogs!" />
</a>';
$i++;
if($i == 5) {
echo '<br />';
$i = 0;
}
}
echo '</div>';
It looks like your concatenation is wrong.
<a href="mypage.com/index.php?dog='. $id . '">
<img src="/thumb/'. $id . '.jpg" alt="dogs!" />
Related
Right now I have this program that echoes out an image and a text ten times. It does so all in one column. I want to make it so that it fills up one whole page by going horizontally after it hits the end of the page in one column. After all the columns fill up, then it can go to the next page. Here is my code:
while($row = mysqli_fetch_array($result)) {
echo '<div>';
echo "<p style='font-size:1.05em;color:#0e3c68;font-weight:bold;'>" . $row['question'] . "</p>";
<img src="data:image/jpeg;base64,'.$row['imagename'] .'" height="125" width="125" class="img-thumnail" />
echo '<div>';
Just your code as following.
echo '<div style="text-align: center;display: inline-block;">';
echo "<p style='font-size:1.05em;color:#0e3c68;font-weight:bold;'>" . $row['question'] . "</p>";
<img src="data:image/jpeg;base64,'.$row['imagename'] .'" height="125" width="125" class="img-thumnail" />
echo '<div>';
I have been trying to set up a page that lists prices of items from a table in a database. Here is my code:
<?php
$querylist = mysql_query("SELECT item_name,image,price,added_by FROM values");
while($row = mysql_fetch_array($querylist))
{
echo '<div class="post rareitem" style="margin-right: 15px;float: left;">
<div class="rarename">
<strong>';
// Shows Item Name
echo $row['item_name'];
echo '</strong>
</div>';
// Shows Item Image
echo '<div class="rareimage" style="background-image: url(/app/tpl/skins/Mango/images/values/rares/';
echo $row['image'];
echo ');"></div>';
// Shows Item Price
echo '<div class="rarecontrols">
<div class="coinsbox"></div>
<span>
<b> <b>Credits: </b> </b> ';
echo $row['price'];
echo '</span>';
// Shows Who Added the Item
echo '<div class="addedbox"></div><b><b><span><font color="#c93734"><font color="#c93734">Added By: </font> </font>';
echo $row['added_by'];
echo '</span></b></b>
</div>
<div class="clear"></div>
</div>';
}
?>
There is another chunk of code (shown below) that I have based this off of, and it works perfectly fine. I can't seem to get this to work though. I believe it has something to do with the SQL, the syntax, or something. No matter what I do, it produces absolutely no results, yet the code below results exactly as planned. I know for a fact it is not a connection issue because the below code can be placed on the same exact page as the above one and it works fine, however the above does not.
<?php
$querylist = mysql_query("SELECT id,username,motto,country,look,rank,account_created,role,account_created,online,last_online FROM users WHERE rank='9' ORDER BY ID LIMIT 20");
while($row = mysql_fetch_array($querylist))
{
echo '
<div class="team">';
// Showing Avatar
echo '<div style="float: left; margin-top:-1px;height: 60px; width: 64px; background: url(http://www.habbo.nl/habbo-imaging/avatarimage?figure=';
echo $row['look'];echo "&action=wav&direction=3&head_direction=3&gesture=sml&size=m) no-repeat 0px -10px";
echo "\"/>";
echo "<img alt=\"badge\" src=\"/app/tpl/skins/habbo/images/icons/";
echo $row['online'];echo ".gif\"></div>";
// Flags
echo "<br/><img src=\"/app/tpl/skins/habbo/images/icons/flags/";
echo $row['country'];echo ".png";
echo '" style="float:right;" /> <b><uf>';
echo $row['username'];echo "</u></b>";
// Bans & Ticket Count
$Bans = mysql_query("SELECT * FROM `bans` WHERE `added_by` = '" . $row['username'] . "'");
$BanCount = mysql_num_rows($Bans);
$Tickets = mysql_query("SELECT * FROM `moderation_tickets` WHERE `moderator_id` = '" . $row['id'] . "'");
$TicketCount = mysql_num_rows($Tickets);
//Role
echo "<br/><gb>Role: </b><fi> ";
echo $row['role'];echo "";
echo "</i>";
// Echoing bans & Tickets
echo "<br/><gb>Bans: </b><fi> ";
; echo $BanCount;
echo "</i>";
echo " <gb>Tickets: </b><if>";
; echo $TicketCount;
echo "</i>";
echo "</div>";
}
?>
Thanks in advanced, any assistance will be greatly appreciated!
values is Reserved Words in mysql it should be on backtick
SELECT item_name,image,price,added_by FROM `values`
And stop using mysql it is deprecated. Instead use mysqli or PDO
What I want to do is that, It should display 3 images on every line and along with their captions.And their could be many rows. How can do that ? here is my code..
while($info=mysql_fetch_array($query))
{
$image=$info['image'];
$cap=$info['caption'];
echo '<img src="'.$image.'" />';
echo $cap;
}
I got the answer.
I don't know hows its working . But it is ....
<table>
<?php
$i=1;
$query=mysql_query("SELECT * FROM publish");
while($info=mysql_fetch_array($query))
{
$inq=$info['ref'];
$imagesrc=$info['image'];
$ti=$info['title'];
if($i%3==1 || $info['id']==1 )
{
echo "<tr></tr>";
}
?>
<td>
<a href="movieview.php?ref=<?php echo $info['ref']; ?>">
<?php
echo '<img src="admin/'.$imagesrc.'" style="width:138px;height:200px;" />';
echo '</a><br />';
echo $ti;
$i++;
}
?>
</td>
</table>
i have a pagination code in php ,i tried to show images post_images from my sql to this table in my code but nothing happen ,i tried echo '<img src= images/$post_image />';
,can you tell me please what i can do ?
my code :
<table height="200px" style="border:3px black solid;border-radius:5px" width="550px">
<tr>
<th colspan="2" height="40px" style="border-bottom:3px black solid">posts in this site</th>
</tr>
<?php
$link=mysql_connect("localhost","username","pass");
mysql_select_db("itstuff_paging",$link);
$q="select count(*) \"total\" from posts";
$ros=mysql_query($q,$link) or die(mysql_error());
$row=mysql_fetch_array($ros);
$total=$row['total'];
$dis=4;
$total_page=ceil($total/$dis);
$page_cur=(isset($_GET['page']))?$_GET['page']:1;
$k=($page_cur-1)*$dis;
$q="select * from posts limit $k,$dis";
$ros=mysql_query($q,$link);
while($row=mysql_fetch_array($ros))
{
echo '<tr>';
echo '<td width="10px" style="border-bottom:1px #a1a1a1 solid">'.$row
['post_id'].'.';
echo '<br/>';
echo '<td style="border-bottom:1px #a1a1a1 solid">'.$row['post_title'];
echo '<br/>';
echo ($row['post_content']);
echo '<br/>';
echo '<img src= images/$post_image />';
echo '</tr>';
}
echo '</table>';
echo '<br/>';
if($page_cur>1)
{
echo '<a href="index.php?page='.($page_cur-1).'"
style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:120px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Previous ">';
}
for($i=1;$i<$total_page;$i++)
{
if($page_cur==$i)
{
echo ' <input style="background-color:green;border:2px black
solid;border-radius:5px;width:30px;height:30px;color:black;font-size:15px;font-weight:bold;"
type="button" value="'.$i.'"> ';
}
else
{
echo '<a href="index.php?page='.$i.'"> <input style="cursor:pointer;background-
color:green;border:1px black solid;border-radius:5px;width:30px;height:30px;color:white;font-
size:15px;font-weight:bold;" type="button" value="'.$i.'"> </a>';
}
}
if($page_cur<$total_page)
{
echo '<a href="index.php?page='.($page_cur+1).'"><input
style="cursor:pointer;background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button"
value=" Next "></a>';
}
else
{
echo '<input style="background-color:green;border:1px black solid;border-
radius:5px;width:90px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button"
value=" Next ">';
}
?>
</table>
You never define $post_image before you use it, so you're generating <img src="" />. Perhaps you meant:
echo "<img src=images/{$row['post_image']} />";
instead?
Your code is malformed. Please try:
echo '<img src="images/'.$post_image.'" />';
I have a web page with images and when user clicks on any of the image, it has to derive data of that particular image from MYSQL database. What I am doing is using a simple JavaScript popup and putting the data from database. However I am just getting the first item from database on all images.
This is the code:
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($colCnt%4==0)
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
$colCnt++;
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
$row['name'] is just giving out the first name as it is in a while loop. I am not being able to get other names for other images. How can this be done. Any help would be appreciated.
Does one iteration in your while fetch single image data? And what I can understand according to your code is that you are displaying 4 image in a row.
Can you please format your code a bit..its looking too ugly.
I need to know which statement is calling your modal window.
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
echo '<tr>';
while($row = mysql_fetch_array($result))
{
$num = $files[$i];
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br>
<div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow"><div><p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>Ok</div>
</div></td>';
$colCnt++;
if ($colCnt % 4 == 0)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
Try this.
Also see how beautiful the code looks if its properly formatted..
try this
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=4;
while($row = mysql_fetch_array($result))
{
for ($i = 0; $i < $colCnt; $i++) {
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
}
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
}
mysql_close($con);
include 'footer.php';
?>