Cannot start with new line in html - php

if(!empty($interest)){
foreach ($interest as $key => $value) {
echo "<div style='float:left; height:130px; width:100px; margin-left:10px; border:solid #f8f8f8; background-color: #f8f8f8;'>";
echo "<a class='avatar' href='#'><img width='90' height='40' src=".$value['item_image']."></a>";
echo "<div><i>".$value['item_name']."</i></div>";
echo "<a href='#' style='text-decoration: none; outline: none;'><span class='label label-success' value=".$value['item_id']." id=".$value['item_id']." onClick='reply_click1(this.id)'>Added</span></a>";
echo " </div>";
}
}
this is my code I'm printing images horizontally here but i need to print two images per line !
this is my output .
I need two items per row
i tried to put <hr> and <br> it did not help me ! is there any way to do this?

$counter = 0;
foreach ($interest as $key => $value) {
$counter++;
if($counter%2==0){
echo '<div style="clear:both;"></div>';
}
echo "<div style='float:left; height:130px; width:100px; margin-left:10px; border:solid #f8f8f8; background-color: #f8f8f8;'>";
echo "<a class='avatar' href='#'><img width='90' height='40' src=".$value['item_image']."></a>";
echo "<div><i>".$value['item_name']."</i></div>";
echo "<a href='#' style='text-decoration: none; outline: none;'><span class='label label-success' value=".$value['item_id']." id=".$value['item_id']." onClick='reply_click1(this.id)'>Added</span></a>";
echo " </div>";
}
}

Because you have float:left css property, you must write a <br style="clear:both" />

easy way to define your div width:50% in style or use clear:both in br

Related

PHP pagination page list adjustment using CSS

I have created following pagination (see image);
here I want to display "Next>>" and "Last" at the end of 28. I cannot change the code to achieve that order because I am using if else block in my PHP code;
Here is the code part;
echo "<ul class='pagination'>";
echo "Page: $page of $last <br>";
echo "Record count: ". $rec_count. "<br>";
echo "Left count: ". $left_rec. "<br>";
echo "Record limit: ". $rec_limit. "<br>";
if( ($page==1) && ($left_rec>0) ){ //this is first page
echo '<li> Next >> <br> </li>';
echo "<li> Last </li>";
}
else if( ($page>1) && ($left_rec>0) ){
echo "<li> First <br> </li>";
echo '<li> << Previous <br> </li>';
echo '<li> Next >> <br> </li>';
echo "<li> Last </li>";
}
else if( ($page>1) && ($left_rec<$rec_limit) ){
echo "<li> First </li>";
echo '<li> << Previous <br> </li>';
}
/* Displaying page numbers (optional) */
for( $i=1; $i<=$last; $i++ ){
if( $i==$page ){
echo "<li> <a class=\"current\" href=\"{$_SERVER['PHP_SELF']}?page=$i\"> $i </a> </li>";
}
else{
echo "<li> $i </li>";
}
}
echo "</ul>";
How can I achieve that using CSS? I have my CSS used so far:
<style>
ul.pagination{
text-align:center;
color:#829994;
}
ul.pagination li{
display:inline;
padding: 0px 3px; /* here we cannot specify padding for top and bottom because inline display does not support margins and
paddings top and bottom*/
}
ul.pagination a{
color:#0d7963;
display:inline-block;
border:1px solid #cde0dc;
margin:3px 0;
padding:5px 10px;
text-decoration: none;
}
ul.pagination a:hover,
ul.pagination a.current{
background:#0d7963;
color:#fff;
}
</style>

How to I display image from mysql PHP

Please help. Im trying to display the image of each user using their student ID
BUT it displays unknown characters as image on my page as below
%�S$P��H�~Q��-�}Y>ZTW�)�,G����g�~)�1WN�{�,��!���^j-����9�4���K�����
$sql_up="SELECT content FROM sp_uploads WHERE s_id= 'RC49557'";
$result_set=mysql_query($sql_up);
while($row_up = mysql_fetch_array($result_set))
{
$pp = $row_up['content'];
}
echo "<td>
<img style=\"float:right; margin:5px; width:150px; height:150px; padding:10px; \"
src=\" data:image/jpg;charset=utf8;base64,<?php echo $pp ?> \" /> </td>";
This will do. You don't need to open PHP tags inside PHP tags.
$sql_up="SELECT content FROM sp_uploads WHERE s_id= 'RC49557'";
$result_set=mysql_query($sql_up);
while($row_up = mysql_fetch_array($result_set))
{
$pp = $row_up['content'];
}
echo "<td>
<img style='float:right; margin:5px; width:150px; height:150px; padding:10px;'
src='data:image/jpg;charset=utf8;base64, $pp' /> </td>";
I'm assuming the img data is correct.

<a> Tag inside PHP

I used tag inside php tag. When I run the code it appears as a link. But its not work as a link.It's mean that link is not clickable.
$data1 = mysql_query("SELECT * FROM image_upload INNER JOIN user_table
ON image_upload.user_id=user_table.user_id WHERE flag=1 ORDER BY timestamp DESC;")
or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array($data1)){
//Outputs the image and other data
echo
'<div class="test" id='.$info['ID'].'>';
echo'<div class="username">'.$info['user_name'].'</div>';
echo'<div class="imagedisplay"><img src="uploads/'.$info['image'].'" width="230px" height=auto border="1px solid #"
-webkit-border-radius=" 20px"
-moz-border-radius= "20px"
border-radius="20px"
></div>';
echo'</div>';
}
?>
my css code is
div.test{
margin: 5px;
border: 1px solid #ffffff;
border-radius:8px;
height: auto;
width:250px;
float: left;
text-align: center;
background-color:#ffffff;
}
Can any one help me.
You have forgot to close tag on line #11
CODE
$data1 = mysql_query("SELECT * FROM image_upload INNER JOIN user_table
ON image_upload.user_id=user_table.user_id WHERE flag=1 ORDER BY timestamp DESC; ") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array($data1)){
//Outputs the image and other data
echo '<div class="test" id='.$info['ID'].'>';
echo '<div class="username">'.$info['user_name'].'</div>';
echo '<div class="imagedisplay"><img src="uploads/'.$info['image'].'" style="width:230px; height:auto; border:1px solid #000; border-radius:20px;"></div>';
echo '</div>';
}
?>
try following
while($info = mysql_fetch_array($data1)){
echo " <div class=\"username\"><a href=\"profile.php\" class=\"button\" title=\"\">".$info['user_name']."</div>";
}
It is probably due to the arrangement of your quotes. Try this clean version:
<?php
echo "<div class='username'>";
echo "<a href='profile.php' class='button' title=''>$info['user_name']</a>";
echo "</div>";
?>
echo '<div class="username">'.$info['user_name'].'</div>';
Try this...
Link should be close properly
'<div class="username">'.''.$info['user_name'].'</div>'.

Equals heights of thumbnails with buttons

I have this code:
foreach ($images as $key => $value)
{
$items[$key]['weight'] = $value['fid'].'_'.$value['weight'] ;
$items[$key]['image'] = ''.image_load($value['uri'],array("class"=>"img-thumbnail","thumbs"=>"medium")).'' ;
$items[$key]['title'] = '<span id="title_file_'.$value['fid'].'">'.$value['title'].'</span>' ;
//$cover = "<a href='javascript:void(0);' onclick='javascript:gallery_cover(\"".$value['fid']."\"); return false;' id='gallery_cover_".$value['fid']."' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Top' id='tooltip1'><span class='btn btn-default btn-sm glyphicon glyphicon-eye-".(isset($gallery_cover['value']) && $gallery_cover['value']==$value['fid']?'open':'close')."'></span></a>" ;
$edit = "<a href='javascript:void(0);' onclick='javascript:update_file(\"".$value['fid']."\"); return false;' class='btn btn-info' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Modifier' id='tooltip1'>Modifier</a>" ;
$delete = "<a href='javascript:void(0);' onclick='javascript:delete_added_image(\"".$value['fid'].'_'.$value['weight']."\"); return false;' class='btn btn-default' data-toggle='tooltip' class='data-tooltip' data-placement='top' data-original-title='Supprimer' id='tooltip1'>Supprimer</a>" ;
$items[$key]['actions'] = $edit." ".$delete ;
}
foreach($images as $key => $value)
{
if ($key % 4 == 0)
echo "<div class=\"row\">" ;
echo "<div class=\"col-md-3\">" ;
echo "<div class='thumbnail' style='min-height:280px;height:280px;'>".$items[$key]['image'] ."
<div>
<h4 style='min-height:50px;'>".$items[$key]['title']."</h4>
<p>".$items[$key]['actions']."</p>
</div>
</div>" ;
echo "</div>" ;
}
the result :
I want every thumbnais to have a fixed button and title.
Any solution for that ?
Thanks
Really, you should create thumbnails of specific dimensions then this would never be an issue. If however you can't/wont/whatever, then try some css:
<style>
.crop {
width: 200px;
height: 150px;
overflow: hidden;
}
.crop img {
width: 300px;
height: 225px;
margin: -75px 0 0 -100px;
}
</style>
<div class="crop"><img src="1.jpg"></div>
<div class="crop"><img src="2.jpg"></div>
This will resize and crop.
Good luck :)

Applying css to a php table

I have a generated php table which I would like to apply style in my style sheet, so for example top:15px, left:10px ect..., not sure how call the table and link it with css -
echo "<table border=1>";
for ($i=0;$i<count($calls);$i++){
for ($j=0;$j<count($days);$j++){
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)){
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
}else
echo "<td style='color:gray'>$k</td>";
}
echo "</tr>";
}
echo "</table>";
any help much appreciated, thank you
echo '<table style="top: 15px; left:10px;">';
or
echo '<table class="someClass">';
and then use CSS
.someClass{
top: 15px;
left: 10px;
}
Give the table an id
echo "<table id=\"my_table\" border=1>";
And then use this in the <head> tag of the document:
<style type="text/css">
#my_table {
top: 15px;
...
}
</style>
echo "<table style=\"border: 1px; top:15px; left: 10px;\">";
Is this statement not working?
echo "<table border=1 style=\"top:15px; left:10px\">";
for ($i=0; $i<count($calls); $i++) {
for ($j=0;$j<count($days);$j++) {
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)) {
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
} else {
echo "<td style='color:gray'>$k</td>";
}
}
echo "</tr>";
}
echo "</table>";

Categories