How to I display image from mysql PHP - 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.

Related

CSS Data-Badge, Value not appearing from database

I have this list in welcome.php
<li>
<img src="images/referral.png" > Referral
</li>
Here I am trying to populate the circle with value from database. I am getting the right value, but its not appearing in the circle. Pardon my CSS please.
Copied this code from here http://www.cssportal.com/blog/create-css-notification-badge/
In the same welcome.php, CSS code is
.badge1 {
position:relative;
}
.badge1[data-badge]:before {
content:attr(data-badge);
position:absolute;
top:0px;
right:0px;
font-size:.7em;
background:green;
color:white;
width:18px;height:18px;
text-align:center;
line-height:18px;
border-radius:50%;
box-shadow:0 0 1px #211;
}
The php value I am trying to echo here comes from a php block after this code.
Code is:
<html><li>
<a href="#" class="badge1" data-badge="<?php echo "$row_cnt"; ?>" value = "
<?php echo "$row_cnt"; ?>"><img src="images/referral.png" > Referral</a>
</li>
</html>
<?php
// Get $row_cnt
?>
So how do I access this $row_cnt value above?
Any help would be helpful.
Remove quotation marks:
<?php echo $row_cnt; ?>
or even
<?=$row_cnt?>
You can not put " inside " so use the escape \ before it
or remove it in echo before the variable

Dynamically increment width of css element in a for loop

EDIT: i found out, itsin my other answer below.
I want to present a graph in php and can create the columns, but when i try to increment the percentage to correspond with the css width of the .inner class it wont increment for each element in he array. How can I increment the width for each element in the array?
$percentage = array(0.2,0.4,0.5,0.6,0.7,0.8);
for($i=0;$i<6;$i++){
echo "<div class='outter'>
<div class='inner'>"; echo $percentage[$i]; echo "
</div>
</div>";
echo "<style type='text/css'>";
echo ".outter{height:25px;width:500%;border-right:solid 1px #000;}";
echo ".inner{height:25px;width:";echo $percentage[i]; echo "%;border-right:solid 1px #000;background-color:#02abff;}";
echo "</style>";
}
i can do it in html and css but i want to do it php. Thanks.
Not sure if you have noticed, but the actual values you have there are 0.X%, and this is not exactly a valid width. You might want to multiply that value by 10 (or by 100) to get to 2% (or 20%).
$percentage = array(0.2,0.4,0.5,0.6,0.7,0.8);
foreach ($percentage as $key => $val) {
echo "<div class='outter'>
<div class='inner'>";
echo $val;
echo "</div>
</div>";
echo "<style type='text/css'>";
echo ".outter{height:25px;width:500%;border-right:solid 1px #000;}";
echo ".inner{height:25px;width:";
echo $val * 10;
echo "%;border-right:solid 1px #000;background-color:#02abff;}";
echo "</style>";
}
I also changed the for loop that you had there to foreach loop, which makes more sense when working with arrays.
I found out. I had to put the styling inside the html tag:
foreach($percentage as $percent){
echo "<div class='outter' style='height:25px;width:500%;border-right:solid 1px #000;'>
<div class='inner' style='height:25px;width:"; echo $percent; echo "%;border-right:solid 1px #000;background-color:#02abff;'>"; echo $percent; echo "
</div>
</div>";
}

Cannot start with new line in html

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

CSS form border formatting inside PHP file

I'm trying to embed some CSS into my PHP file. How can I properly add my CSS so that each called form will be rendered inside a black border? This is what I tried so far.
while ($ratings = mysql_fetch_array($q))
{
//This outputs the doctors's name
echo "Doctor's name:" . $ratings['doctor_name'] ."<br />";
// Retrieve the id of the doctor which was posted on
$id = $_POST['id'];
echo "<style> form { border-style: solid; border-color: #ffffff}";
//This outputs a textarea for the user to submit comments
echo "<b>Your Experience: </b>";
echo "<form method='post' action='review_doctors.php'>
<textarea name='body'></textarea>
<input type='submit' name='submit' value='Send'/>
<input type='hidden' name='id' value='$ratings[id]' />
</style>
</form>
";
echo "<br />";
}
As mentioned in the comments: "The style tag should only include styles".
?>
<style>
form {
border: 3px solid black;
}
</style>
<?php
while ($ratings = mysql_fetch_array($q)) {
echo "<form>...</form>"
}
If you would like to reuse styles you can put them in their own file and then include them on each page:
?>
<link rel="stylesheet" type="text/css" href="/path/to/mystyle.css">
<?php
// ...

Filepath from SQL database not looping a BG image

I have an Image uploaded to a folder with the filepath stored in a table along with other info (title, description). I would like this info looping inside a repeated div. Both other variables loop correctly, however the filepath variable needs to be used in a background URL and at the moment only echos the value of the last row. Thank you very much for your help, there has got to be a simple solution! -Sean
<?php
$result = mysql_query("SELECT * FROM `program`");
$values = mysql_fetch_array($result);
$globals['filepath'] = $row['filepath'];
echo "<div>"; // start a table tag in the HTML
while($row = mysql_fetch_array($result)){ //Creates a loop to loop through results
echo "<div class=wrapper3 >
<h2>" . $row['program_name'] . "</h2>
<p>" . $row['program_description'] . "</p>
</div>
<p> </br> </p>";
$globals['bgimage'] = $row['filepath'];
}
echo "</div>";
?>
<style type="text/css">
.wrapper3{
width:85%;
margin:0 auto;
padding:20px;
height:auto;
color:#FFF;
background: url(/SMLC/<?php while ($row = mysql_fetch_array($result)){ echo $globals['bgimage'];} ?>
) no-repeat;
background-size:cover;
color:#000;
height:250px;
text-align:center;
background-color:#fff;
border-radius:6px;
border:1px solid #0FF;
}
</style>
<?php mysql_close();?>
Remove the background from the .wrapper3 in css, and add it to the element as an inline style.
<?php
$result = mysql_query("SELECT * FROM `program`");
echo "<div>"; // start a table tag in the HTML
while ($row = mysql_fetch_array($result)) { //Creates a loop to loop through results
$globals['filepath'] = $row['filepath'];
echo "<div class='wrapper3' style=\"background: url('/SMLC/".$row["filepath"]."');\">
<h2>" . $row['program_name'] . "</h2>
<p>" . $row['program_description'] . "</p>
</div>
<p></br></p>";
}
echo "</div>";
?>
NOTE: Use mysqli functions or PDO instead of mysql functions, since, mysql functions are deprecated.

Categories