illegal string offset with while loop [closed] - php

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="" />

Related

Cannot load a base64 encoded image from mysql database using php [closed]

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));

Show image only if jsonObj has a value [closed]

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 2 years ago.
Improve this question
If <?php echo $jsonObj->data->image; ?> has a value, like 1234.jpg I want to show this:
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
If <?php echo $jsonObj->data->image; ?> has no value, then <img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" /> should remain hidden.
Any help please?
Use php if-else statement for that.
<?php
if(!empty($jsonObj->data->image)) {
?>
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
<?php
}
?>
You can add else part and do whatever you want.

How to echo a clickable href to another file in php [closed]

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>
";
}

Can someone explain this PHP code? [closed]

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 7 years ago.
Improve this question
<h1 class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?>
</a>
</h1>
if (is_category('Ponies')) { ?>
// overlay a pretty rainbow on the logo for the ponies category
<img id="rainbow"
src='<?php bloiginfo('template_directory');?>/img/rainbow.png"
alt="OMG! Ponies! " />
<?php } ?>
I'm having trouble matching the PHP tags. The comment for the code says "Now any time the category of the content is Ponies, your header also includes the rainbow.png." But it's clear how that is happening. The actual code is on p245 of WordPress Design and Developement by Williams. Thanks for putting another pair of eyes on it.
"If" is not inside <?php ... ?>. Must be:
<?php if (is_category('Ponies')) { ?>
I prefer to use <?php if (condition): ?> when there's HTML in-between.
But anyhow...
1) The if() statement needs to be inside php tags.
2) You don't need echo to retrieve the bloginfo.
bloginfo() documentation
3) You've misspelled bloginfo at the bottom...
My code:
<h1 class="site-title">
<a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
<?php $bloginfo('name'); ?>
</a>
</h1>
<?php if (is_category('Ponies')) : ?>
<img id="rainbow"
src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
alt="OMG! Ponies!" />
<?php endif; ?>

fetch & show images from database with break [closed]

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>";
?>

Categories