This is my code:
echo "<div class=\"panel-body\" style=\"border-top: 1px solid; border-bottom: 1px solid; border-color:#ddd\">";
echo "<div class=\"vidMR\">";
echo"<div><strong>" . $lang['vldMaker'] . "</strong></div>";
echo"<div>";
$maker = "SELECT vidMaker FROM videoinformation WHERE id=".$row['id'];
if ($result1 = mysqli_query($con, $maker)) {
while ($row2 = mysqli_fetch_row($result1)) {
$values = explode(',',$row2[0]);
foreach($values as $v1)
if (!empty($v1)) {
printf ("<img src=\"addVid/maker/%s.jpg\" class=\"makerImg img-circle\" alt=\"%s.jpg\">", $v1, $v1);
}
}
mysqli_free_result($result1);
}
else{
echo $lang['vldErrorMaRo'];
}
echo"</div>";
echo"<div><strong>" . $lang['vldRoles'] . "</strong></div>";
echo"<div>";
$role = "SELECT vidRoles FROM videoinformation WHERE id=".$row['id'];
if ($result2 = mysqli_query($con, $role)) {
while ($row3 = mysqli_fetch_row($result2)) {
$values = explode(',',$row3[0]);
foreach($values as $v2)
if (!empty($v2)) {
printf ("<img src=\"addVid/roles/%s.jpg\" class=\"roleImg img-circle\" alt=\"%s.jpg\">", $v2, $v2);
}
}
mysqli_free_result($result2);
}
else{
echo $lang['vldErrorMaRo'];
}
echo "</div>";
echo"</div></div>";
Problem is that this code working ONLY in chrome and opera, BUT in IE and Mozilla pictures are not displayed...
I tried different ways...like add full path for images and so on... BUT any way it's would not like to work in IE and Mozilla.
This is out put HTML...
<body>
<div class="vidMR">
<div>
<strong>Maker:</strong>
</div>
<div><img alt="Name1.jpg" class="makerImg img-circle" src=
"addVid/maker/Name1.jpg"><img alt="Name2.jpg" class=
"makerImg img-circle" src="addVid/maker/Name2.jpg"></div>
<div>
<strong>Roles:</strong>
</div>
<div><img alt="Name1.jpg" class="roleImg img-circle" src=
"addVid/roles/Name1.jpg"><img alt="Name2.jpg" class=
"roleImg img-circle" src="addVid/roles/Name2.jpg"><img alt="Name3.jpg"
class="roleImg img-circle" src="addVid/roles/Name3.jpg"></div>
</div>
</body>
</html>
Related
I am bit new to php and sql.
I am simply reading from a database table and echoing images to a page. The images are then styled with a text aligned in the middle saying 'Play Video'.
In the table 'adcTable' some entries do not have a video stored.
I would like to have the rows/entries with video say 'Play Video' and the ones without just show the image.
Not to sure how bess to explain. Hope to get some assistance.
<php
$sql = "SELECT client_id, images, video FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["images"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Play Video</div>
</div>
</div>
</td>";
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
echo "</tr></table>";
?>
Thanks guys, I was able to use the example provided by BusinessPlanQuickBuilder to solve.
$sql = "SELECT client_id, files, file FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
if ($row['file'] == "VidUploads/"){
echo "<td>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
</td>";
echo '<script type="text/javascript">',
'$( ".text" ).css( "border", "3px solid red" );',
'</script>';
} else{
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Video</div>
</div>
</div>
</td>";
}
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
}
echo "</tr></table>";
?>
Use if empty condition on video column. This is the fundamental code, add your formatting as required.
<?php
while($row = $result->fetch_assoc()) {
if (empty ($row['video']) ) {
echo $row ["images"];
} else {
echo "Play Video";
}
}
?>
SO reference to related post
I've got a while loop retrieving the information from this statement
$stmt = $conn->prepare("SELECT images.*, users.profile_image, comments.* FROM
images LEFT JOIN users ON images.user_id = users.user_id LEFT JOIN comments ON
comments.user_id = users.user_id AND images.id = comments.image_id WHERE
images.id = :id");
No problems here, but I need to loop the comments again, otherwise the first loop, loops again because there are two rows in the comments table. This displays everything again but with row 2 of the comments. How can I make it only loop the comments. The first loop will only ever retrieve one result since it is always a unique id.
try {
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$stmt->bindParam(':id', $id);
$conn->beginTransaction();
$stmt->execute();
$conn->commit();
while ($row = $stmt->fetch())
{
$comment = $row['comment'];
$title = $row['title'];
$image = $row['image'];
$username = $row['username'];
$category = $row['category'];
$description = $row['description'];
$comments = array($row['comment']);
}
?>
<h1><?php echo"$title"; ?></h1>
<img style="max-width: 100%; max-height:100%; margin-left: auto; margin-
right: auto; display:block;" src="<?php echo "$image" ?>"/>
<?php
echo "<h2><span class='by'>By </span><a
href='users.php/$username.html'>$username </a></h2>";
echo "<h2><span class='by'>In the </span><a href='browse.php?
category=space'>$category </a><span class='by'>category</span></h2>";
echo "<h2><span class='by'>About this image:</span></h2>
$description";
?>
<?php
echo "<h2><span class='by'>Comments</span></h2> $comments";
?>
<?php }
else {
if(!isset($row['id'])){
echo "empty";
}
}
?>
Thanks!
Update
while ($crow = $cstmt->fetch())
{
if($crow == false){
echo "nothing here";
}
else {
$comment = $crow['comment'];
echo "$comment"; ?><br /><br /><?php
}
}
You are probably going to need to split this up into a seperate query or use some logic to establish if it is a new Image or not
EG if split :
<?php
$stmt = $conn->prepare("SELECT images.*, users.profile_image FROM
images LEFT JOIN users ON images.user_id = users.user_id WHERE
images.id = :id");
try {
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$stmt->bindParam(':id', $id);
$conn->beginTransaction();
$stmt->execute();
$conn->commit();
while ($row = $stmt->fetch())
{
$comment = $row['comment'];
$title = $row['title'];
$image = $row['image'];
$username = $row['username'];
$category = $row['category'];
$description = $row['description'];
// $comments = array($row['comment']);
}
?>
<h1><?php echo"$title"; ?></h1>
<img style="max-width: 100%; max-height:100%; margin-left: auto; margin-
right: auto; display:block;" src="<?php echo "$image" ?>"/>
<?php
echo "<h2><span class='by'>By </span><a
href='users.php/$username.html'>$username </a></h2>";
echo "<h2><span class='by'>In the </span><a href='browse.php?
category=space'>$category </a><span class='by'>category</span></h2>";
echo "<h2><span class='by'>About this image:</span></h2>
$description";
?>
<?php
// THIS QUERY WON'T WORK , IT IS FOR CONCEPT ONLY
$CommentsStmt = $conn->prepare("SELECT comments.* FROM comments WHERE comments.user_id = :user_id AND comments.image_id = :image_id");
$CommentsStmt->bindParam(':user_id', $row['user_id'] , ':user_id' , $row['image_id']);
$conn->beginTransaction();
$CommentsStmt->execute();
$CommentsStmt->commit();
// add a check if it is blank
echo "<h2><span class='by'>Comments</span></h2> ";
while ($CommentsRow = $stmt->fetch())
{
echo $CommentsRow['comment'],'<br /><br />';
}
?>
<?php }
else {
if(!isset($row['id'])){
echo "empty";
}
}
?>
a sample for the non-split version
/************
****
******** only output the image details if this is a new image :
****
************/
// NOT SURE WHERE TH IMAGE ID IS COMING FROM SO SUSTITUTE IT HERE:
$current_image_id = $id;
if($previousImageId !== $current_image_id){
?>
<h1><?php echo"$title"; ?></h1>
<img style="max-width: 100%; max-height:100%; margin-left: auto; margin-
right: auto; display:block;" src="<?php echo "$image" ?>"/>
<?php
echo "<h2><span class='by'>By </span><a
href='users.php/$username.html'>$username </a></h2>";
echo "<h2><span class='by'>In the </span><a href='browse.php?
category=space'>$category </a><span class='by'>category</span></h2>";
echo "<h2><span class='by'>About this image:</span></h2>
$description";
}
/************
****
******** END --- only output the image details if this is a new image :
****
************/
I have a problem and needed an answer. How can I automatically put the 2 images horizontally.
I think I will use some if(1 ==%3)?
In the example pic I really like to horizontal the 2 images don't know how to do it ?
Here's what I've done:
for($i=0; $rows = $results->fetch(); $i++){
if($dsds=='Commissoner'){
echo $rows['prog_id'].$rows['prog_id'].' '.$rows['prog_name'].' = '.$rows['votes'];
}else {
//this is the part where I put a css
style='margin-left:44px;'><div class='box_img2' style='margin-right:10px;' >";
echo '<img src="candidates/images/'.$rows['image'].'" width="70" height="80px" />'.', '.'<br>'.$rows['lastname'].', '.$rows['firstname'].'<br>'.' = '.$rows['votes'];
echo '<br>';
}
$sdsd=$dsada
?>
<img src="candidates/images/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>
<?php
if ($rows['votes']==0){
echo "<br>";}
else {
echo(100*round($rows['votes']/($sdsd),2)); ?>%<br>
<?php
}
echo '</div>';
}
?>
Here's my css:
.row:before, .row:after { clear:both; }
.row{
display: block;
}
.box_img2 {
float: left;
/*margin-right:85px;*/
text-align:center;
}
.box_img2 img { /* if you want it centered */
display:block;
display: inline-block;
}
Here's my entire codes:
<?php
include('../connection/connect.php');
$result = $db->prepare("SELECT * FROM candposition ORDER BY posid ASC");
$result->bindParam(':userid', $res);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
$dsds=$row['posid'];
$resulta = $db->prepare("SELECT sum(votes) FROM candidates WHERE posid= :a");
$resulta->bindParam(':a', $dsds);
$resulta->execute();
for($i=0; $rowa = $resulta->fetch(); $i++){
$dsada=$rowa['sum(votes)'];
}
echo '<div style="margin-top: 18px;">';
echo '<strong>'.$row['pos_name'].' '.'</strong><br>';
$results = $db->prepare("SELECT * FROM candidates,student WHERE candidates.idno=student.idno AND candidates.syearid = '$no'AND posid = :a ORDER BY votes DESC");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
if($dsds=='Commissoner'){
echo $rows['prog_id'].$rows['prog_id'].' '.$rows['prog_name'].' = '.$rows['votes'];
}else {
//this is the part
echo'<?php $src=array("candidates/images/".$rows["image"]); for($i=0;$i<3;$i++){ ?>';
echo '<img src="candidates/images<?php echo .$src[$i];?>" class="image-inner" />';}
$sdsd=$dsada
?>
<!-- <img src="candidates/images/percent.gif"width='<?php echo(100*round($rows['votes']/($sdsd),2)); ?>'height='10'>-->
<?php
if ($rows['votes']==0){
echo "<br>";}
else {
// echo(100*round($rows['votes']/($sdsd),2)); /
/*?>%<br>*/
/*<?php
}
echo '</div>';*/
}
}
?>
<?php
}
?>
This is the easiest way i can explain using php. Hopes this will help you to understand
.image-inner {
position: relative;
width: 150px;
display: inline-block;
}
<?php
$src = array(
'http://www.google.com/logos/2008/de_doodle4google08.gif',
'http://www.google.com/logos/2012/d4g_poland12-hp.jpg',
'http://www.google.com/logos/2011/colombia-independenceday11-hp.jpg'
);
for($i = 0; $i < 3; $i++)
{
echo "<img src='{$src[$i]}' class='image-inner' />";
}
?>
Display the divs as inline-block like so :
#christmas_promotion_boxes div {
display: inline-block;
}
jsFiddle
I have this code:
<div style="margin: 0 auto; display:block; width: 916px; overflow: auto;">
<?php echo "";
echo "<i>Owned: $line->phone </i><br><br>";
$query = "SELECT person_id, person.name, person.sex, person.father_id, person.mother_id,PhotosComp.reference as reference
FROM person
WHERE person.id=$currId";
$result = mysql_query($query);
if (mysql_num_rows($result)>0) {
while ($line = mysql_fetch_object($result)) {
echo "<div valign='top'>";
echo "";
echo "<img src=".$line->reference." style=float:left; height='50px' border='1'>";
echo "";
echo "<a href='details.php?id=$line->person_id'>";
echo "<b>";
echo "$line->name</a>";
echo "</b>, <font size='-2'>(";
echo "$line->sex";
echo ", </font><font size='-2'>";
echo "$line->father_id";
echo "<br>";
echo "$line-mother_id";
echo "<br>";
echo "</div>";
}
}echo "";
?>
</div>
The info is shown correctly vertical… but I would like to show lets say 4 results horizontal before it breaks into new line.
So I get this result from the database as it is now:
PICTURE Bob
Mick
Jane
PICTURE Roy
Mack
June
PICTURE Mia
Roy
Jane
PICTURE Lou
Bob
June
PICTURE Bib
Mock
Jine
PICTURE Beb
Muck
Jone
PICTURE Ray
Rob
Mia
And would like it to be shown as this:
PICTURE Bob PICTURE Roy PICTURE Mia PICTURE Lou
Mick Mack Roy Bob
Jane June Jane June
PICTURE Bob PICTURE Roy PICTURE Mia
Mick Mack Roy
Jane June Jane
The results from DB can be 0 to 15–20. I don’t need any upper limit.
Try this , let me know if it works .
if (mysql_num_rows($result)>0)
{
$counter = 0;
while ($line = mysql_fetch_object($result))
{
if($counter %4 != 0)
{
#this will break your div
echo "<div valign='top' style='clear:both;'>";
}
else
{
echo "<div valign='top' style='float:left;display:block;'>";
}
//if ($line->reference = (NULL)) { echo "<img src=".$line->reference." style=float:left; height='50px' border='1'>";
//else echo "<img src='../temp_pic.jpg' style=float:left; height='50px' border='1'>";}
echo "";
echo "<a href='page.php?id=$line->person_id'>";
echo "<b>";
echo "$line->name</a>";
echo "</b><br>";
echo "line->father_id";
echo"<br>";
echo "line->mother_id";
$counter++;
}
echo "</div>";
}
Some scaffolding like this might get you closer to your goal. as #DanFromGermany explained, you need to clear:both underneath your div elements. Try not to put style tags in your markup, unless your page is super optimised or something.
markup
while($result) {
echo "<div class=\"span-3\">";
echo "<div>";
echo "the content father->id line->person_id etc etc";
echo "</div>";
echo "</div>";
}
echo "<div class=\"clear-fix\"></div>";
css
.span-3 {
width:25%;
float:left;
margin:0; padding: 0;
}
.span-3 > div {
margin: 10px; /* or some other value */
}
.clear-fix {
clear:both;
}
Here is a basic bit of code to show pictures in the format you require. You will need to change this to match up with your while loop and also change the clases and css code to match your requirements ie page width etc.
<style>
html {width:100%; background:#ffffff;}
body {max-width: 960px; background:red; margin:0 auto;}
img {max-width: 225px; height: auto;}
.clear {clear:both;}
.no-margin{margin:0 !important;}
.margin-right {margin-right: 20px;}
</style>
<div class="pic-wrap">
<?php
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$pictures[] = 'http://www.canoefoundation.org.uk/cf/assets/Image/Yellow%20Duck.jpg';
$count = count($pictures);
$i=1;
foreach($pictures as $picture)
{
if($i % 4 == 0)
{
echo '<img src="'.$picture.'" class="no-margin four">';
}
elseif($i == $count)
{
echo '<img src="'.$picture.'" class="margin-right">';
echo '<div class="clear"></div>';
}
else
{
echo '<img src="'.$picture.'" class="margin-right">';
}
$i++;
}
?>
</div>
Here is an image of the output
Much like #DanFromGermany mentioned this clears floats and also adds a clear at the end by using a count of the results.
$count = count($pictures);
It then determines the last result form this
elseif($i == $count)
With $i being incremented on each iteration of the loop.
$i++;
Hope this helps.
I have two rank in my forum Admin = 1 and User = 0 Then this code is doing so the admin get red name.
if($info['rank'] == 1) { $x= "<a class='admin'>".$last_user."</a>";
} else { $x= "<a class='user'>".$last_user."</a>"; }
But everyone is getting red name..
use the $x where you want to wish.
<?PHP
if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_assoc($res)) {
if($info[rank] == 1) { $x= "<div class='admin'>".$last_user."</div>"; } else { $x="<div>".$last_user."</div>"; }
$tid = $row['id'];
$cid = $row['category_id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
if ($row['topic_last_user']== "") { $last_user = getusername($row['topic_creator']); } else { $last_user = getusername($row['topic_last_user']); }
if ($row['topic_last_user']== "") { $last2_user = 'Started by'; } else { $last2_user = 'Most recent by'; }
$topics .="
<li class='category'><div class='left_cat'>
<a class='underline' href='view_topic.php?cid=".$cid."&tid=".$tid."'>
<div class='title'><i class='icon-comment'></i> ".$title."</div></a>
<div class='info'><i class='icon-comments icon-1'></i> ".topicreplies($cid, $tid)." Comments <i class='icon-user icon-1'>
</i>".$last2_user."
$x
<i class='icon-calendar'> </i> ".convertdate($date)."</div>
</div>";
$topics .= "<div class='right_cat'>
<div class='face'>
<img class='img_face' src='https://minotar.net/avatar/".getusername($creator)."/40.png'></div>
<div class='comments_cat'>
<div class='comments_top'>Comments</div>
<div class='comments'>".topicreplies($cid, $tid)."</div></div>
<div class='views_cat'>
<div class='views_top'>Views</div>
<div class='views'>".$views."</div></div>
</div></li>";
}
echo $topics;
} else {
echo "<div class='alert alert-danger text5'>There are no topics available yet.</div>";
}
?>
I have make the variable for you in the top.
Hope it work
if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_assoc($res)) {
$tid = $row['id'];
$cid = $row['category_id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
if ($row['topic_last_user']== "") { $last_user = getusername($row['topic_creator']); } else { $last_user = getusername($row['topic_last_user']); }
if ($row['topic_last_user']== "") { $last2_user = 'Started by'; } else { $last2_user = 'Most recent by'; }
$topics .= "<li class='category'><div class='left_cat'>
<a class='underline' href='view_topic.php?cid=".$cid."&tid=".$tid."'><div class='title'><i class='icon-comment'></i> ".$title."</div></a>
<div class='info'><i class='icon-comments icon-1'></i> ".topicreplies($cid, $tid)." Comments <i class='icon-user icon-1'>
</i>".$last2_user." ";
Syntax error is there at last line i.e ".$last2_user."
Just close the quote at " ";
This will solve your problem.
It looks like you are trying to insert an if statement inside the string you are creating. You can't do that as far as I know. However, the solution is easy. You end the string, insert your if statement, then append the rest of what you wanted. Like this:
if (mysql_num_rows($res) > 0) {
while ($row = mysql_fetch_assoc($res))
{
$tid = $row['id'];
$cid = $row['category_id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
if ($row['topic_last_user']== "")
{ $last_user = getusername($row['topic_creator']); }
else
{ $last_user = getusername($row['topic_last_user']); }
if ($row['topic_last_user']== "")
{ $last2_user = 'Started by'; }
else
{ $last2_user = 'Most recent by'; }
$topics .= "<li class='category'><div class='left_cat'>
<a class='underline' href='view_topic.php?cid=".$cid."&tid=".$tid."'>
<div class='title'><i class='icon-comment'></i> ".$title."</div></a>
<div class='info'>
<i class='icon-comments icon-1'></i> ".topicreplies($cid, $tid)."
Comments <i class='icon-user icon-1'>
</i>".$last2_user." ";
// The string above is ended - and you insert your if statement.
// I changed the echo to an append to the string btw.
if ($info['rank'] == 1) { $topics .= "<div class='admin'>".$last_user."</div>"; } else { $topics .= "<div>".$last_user."</div>"; }
// Now you get to continue appending to the string.
$topics .= " <i class='icon-calendar'> </i> ".convertdate($date)."</div>
</div>";
$topics .= "<div class='right_cat'>
<div class='face'>
<img class='img_face' src='https://minotar.net/avatar/".getusername($creator)."/40.png'></div>
<div class='comments_cat'>
<div class='comments_top'>Comments</div>
<div class='comments'>".topicreplies($cid, $tid)."</div></div>
<div class='views_cat'>
<div class='views_top'>Views</div>
<div class='views'>".$views."</div></div>
</div></li>";
}
echo $topics;
} else {
echo "<div class='alert alert-danger text5'>There are no topics available yet.</div>";
}
The following code is what I have in the example provided above, and Here
<style type="text/css">
.user { font-weight:900; color: #000; text-decoration: none !important; }
.admin { font-weight:900; color: #F00; text-decoration: none !important; }
</style>
<form action="" method="POST">
Input number and press enter:
</br>User = 0 Admin = 1</br>
<input name="rank" id="rank" type="text" />
</form>
<?php
if (isset($_POST['rank'])) {
$info['rank'] = $_POST['rank'];
if($info['rank'] == 1) { $x= "<a class='admin'>Admin</a>"; }
else { $x= "<a class='user'>User</a>"; }
echo $x;
}
?>
As I mentioned in my comment above your code works fine, unless there is something going on elsewhere that we cant see with what you have given us.
And without a form.
<style type="text/css">
.user { font-weight:900; color: #000; text-decoration: none !important; }
.admin { font-weight:900; color: #F00; text-decoration: none !important; }
</style>
<?php
$info['rank'] = 1;
if($info['rank'] == 1) { $x= "<a class='admin'>Admin</a>"; }
else { $x= "<a class='user'>User</a>"; }
echo $x;
?>