Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
If i ve inserted images in database in this format
But i want to show the results like this if i m selecting all the images at a time
<?php
$s=mysql_query("SELECT * FROM portfolio");
while($row=mysql_fetch_array($s))
{
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></a></td>
After 3 images it should take a break & show in another column ..
any help here.. thankss
I certainly don't recommend you to use mysql* functions. Your HTML had errors too. Why is there "a" close tag when there is no opening tag of a ? I removed it from my answer. Also you didn't had any opeining tr tag or table tag. I added them to the answer.
<?php
echo"<table><tbody><tr>";
$s=mysql_query("SELECT * FROM portfolio");
$k=0;
while($row=mysql_fetch_array($s)){
$k++;
if($k==4){
echo"</tr><tr>";
$k=0;
}
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></td>
<?
}
echo"</tr></tbody></table>";
?>
Here's how you do it in PDO :
<?php
echo"<table><tbody><tr>";
$sql=$dbh->prepare("SELECT * FROM portfolio");
$sql->execute();
$k=0;
while($row=$sql->fetch()){
$k++;
if($k==4){
echo"</tr><tr>";
$k=0;
}
?>
<td><img src="portfolio/<?php echo $row['image'];?>" height='100px' width='150px' /></td>
<?
}
echo"</tr></tbody></table>";
?>
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I have a longblob field in mysql database that stores a binary value for a image that i uploaded through my webpage.
I am trying to get the image using
<?php while( $record = mysqli_fetch_assoc( $result ) ): ?>
<div>
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($record['image']).'"height="300" width="300"/>'?>
<br/>
<?php echo "Title:".htmlentities( $record['title'] ); ?>
<br/>
<?php echo "Genre:".htmlentities($record['genre']); ?>
<br/>
<?php echo "Author:".htmlentities( $record['author'] ); ?>
<br/>
Edit</i>
<br/>
<a href="books.php?delete=<?php echo $record['id']; ?>"
onclick="javascript:confirm('Are you sure you want to delete this project?');" style="color:#1217b3">Delete</i></a>
</div>
<?php endwhile; ?>
and img tag looks like this in html
<img src="data:image/jpeg;base64,MlN0YXRlLmpwZw==" height="300" width="300">
You have base64 encoded the image file name not the file contents
MlN0YXRlLmpwZw==
actually outputs:
2State.jpg
When storing it in the database you need to do
$imageContent = base64_encode(file_get_contents($file));
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Im new to php and i am trying study how to design web page, the code is not mine. My problem is , i have some clickable done using a table for that i have an array
$buttons=array('Home'=>'home.php',
'Contact'=>'contact.php',
'Services'=>'service.php',
'Site map'=> 'map.php');
and there is a function
function DisplayMenu($buttons)
{
echo "<table width='100%' bgcolor
='white' cellpadding='4'
cellspacing='4'\n";
echo "<tr>\n";
$width =100/count($buttons);
while (list($name, $url)=each ($buttons))
{
$this-> DisplayButton($width, $name,
$url);
}
echo "</tr>\n";
echo "</table>\n";
}
and for displaying the button there is also a function
function DisplayButton($width, $name, $url)
{
echo " <td width='$width%'>
<a herf ='".$url."'>
<img src= 'ab.jpg' alt='$name'
border='0'>
</a> <a herf='".$url."'><span
class ='menu'>
".$name."</span></a></td>";
}
My problem is when i click for example the home button its not taking me to the home.php page , can someone help me ?
Just a typo (herf to href)
function DisplayButton($width, $name, $url)
{
echo "
<td width='{$width}%'>
<a href='{$url}'>
<img src='ab.jpg' alt='{$name}' border='0'>
</a>
<a href='{$url}'>
<span class='menu'>{$name}</span>
</a>
</td>
";
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
<?php
include 'inc/connect.php';
if ($_GET['id'] )
{
$p_id = $_GET["id"];
$query = "SELECT * FROM products WHERE p_id= '$p_id'";
//var_dump($query);
$resu = mysqli_query($con, $query);
while($rs = mysqli_fetch_assoc($resu))
{
?> <img src="<?php echo $p_id['p_image']; ?>" alt="" /> <?php
//var_dump($query);
}
}
?>
this is my code and this is showing me error on my browser what can i do..?
image cant load
Replace this
<img src="<?php echo $rs['p_image']; ?>" alt="" />
to
<img src="<?php echo $p_id['p_image']; ?>" alt="" />
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to hide element in my website. I have 2 level access (ad,op). If I logged as sp I can acces Buy, Try, List Upload, and Upload. If I logged as ad, I can access Buy, Try, and List Upload. and not logged, can access Buy and Try.
My code : http://pastebin.com/SvZmzmxK
<p style="text-align:justify;"> </p>
<strong>Buy </strong> <strong> Try</strong>
<?php if ($level=='super_admin') {?>
<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>
<?php } elseif($level=='admin') {?>
<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>
<?php } ?>
Looking at your code, this is probably just what you are looking for:
<?php
if ($level=='super_admin')
echo "<strong> List Upload</strong>";
else if elseif($level=='admin')
echo "<strong> List Upload</strong></br></p>
<strong> Upload</strong></br></p>";
?>
I would recommend putting your php in a format like this (using echo) since it keeps your code easier to read and maintain.
I also advice you to look at your html knowledge: </br> and </p> can't just be used liked that.
You can try like this:
<p style="text-align:justify;"> </p>
<strong>Buy </strong> <?php //Buy for all; ?>
<strong> Try</strong> <?php //Try for all; ?>
<?php if( in_array($level,array('super_admin','admin')) ){ ?>
<strong> List Upload</strong> <?php //Buy|Try|List Upload for ad+sp; ?>
<?php if($level=='admin'): ?>
<strong> Upload</strong> <?php //Upload is only for admin(ad); ?>
<?php endif; ?>
<?php } ?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create table inside php script .. Is there any way that i could create table inside php script.?
<?php html code to create table ?>
You can do like
HTML in PHP :
<?php
echo "<table>";
echo "<tr>";
echo "<td>Name</td>";
echo "<td>".$name."</td>";
echo "</tr>";
echo "</table>";
?>
Or You can write like.
PHP in HTML :
<?php /*Do some PHP calculation or something*/ ?>
<table>
<tr>
<td>Name</td>
<td><?php echo $name;?></td>
</tr>
</table>
<?php /*Do some PHP calculation or something*/ ?>
Means: You can open a PHP tag with <?php, now add your PHP code, then close the tag with ?> and then write your html code. When needed to add more PHP, just open another PHP tag with <?php.
You can drop in and out of the PHP context using the <?php and ?> tags. For example...
<?php
$array = array(1, 2, 3, 4);
?>
<table>
<thead><tr><th>Number</th></tr></thead>
<tbody>
<?php foreach ($array as $num) : ?>
<tr><td><?= htmlspecialchars($num) ?></td></tr>
<?php endforeach ?>
</tbody>
</table>
Also see Alternative syntax for control structures
Try it like,
<?php
$name='your name';
echo '<table>
<tr><th>Name</th></tr>
<tr><td>'.$name.'</td></tr>
</table>';
?>
Updated
<?php
echo '<table>
<tr><th>Rst</th><th>Marks</th></tr>
<tr><td>'.$rst4.'</td><td>'.$marks4.'</td></tr>
</table>';
?>
Can place code anywhere
<input class="my_<? print 'test' ?>" />