1

I am trying to .load a script called 'refreshImages.php'. Inside that script is a while loop pulling from the database. I have got it to load a single echo function but it wont load anything inside the while loop I have on the script... this is what the php file has...

<?php 
include 'includes/config.php';

$pimages = mysql_query("SELECT * FROM property_images WHERE pid='$pid'");

//Cant Post Images So Leaving The Echo Content Out//
while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    echo "<li>$img</li>";
}?>

I am using .load('refreshImages.php') on the page I need it to show up on. Any explanation I am not seeing?

3
  • you mean echo does work, but image and image_alt are not assigned? Commented Apr 1, 2011 at 2:06
  • echo will work outside the while loop, but anything i try to echo inside the while loop will not work, it will only work outside the while loop. Any help? Commented Apr 1, 2011 at 3:24
  • echo "<li>$img</li>"; , Is this what you want or echo "<li>$image</li>";? Commented Apr 1, 2011 at 4:22

4 Answers 4

1

Your $img is an array, not a string. You will get output like <li>Array</li>, if you have stuff coming from the database. Is that what you mean? Or are you getting an empty result?

If empty - what does your mysql_num_rows tell you when ran against the result resource?

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry had to make it like that for StackOverflow to post the question. This is what my echo is... echo "<li><a class='thumb' href='$image'><img src='$image' width='50px' height='50px' alt='$image_alt'></a></li>"; When it loads, nothing is shown, at all, no empty results or anything, I have no clue why it wont show.
Can you edit your original post, and add what exact HTML you're getting when accessing the URL you're trying to load directly?
1

try changing this:

echo "<li>$img</li>";

to

echo "<li><img src=\"{$image}\" alt=\"{$image_alt}\" /></li>";

1 Comment

Sorry, I had to make it like that for StackOverflow, because of posting images. This is what it looks like... echo "<li><a class='thumb' href='$image'><img src='$image' width='50px' height='50px' alt='$image_alt'></a></li>"; Anything?
0

You may not be getting any results from the database. Try using this code which will display a message if there is something wrong with your sql query.

<?php 
include 'includes/config.php';

$pimages = mysql_query("SELECT * FROM property_images WHERE pid=" . $pid );

if (mysql_num_rows($pimages) > 0) {  // checks to see if you are getting results from db
  while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    echo '<li><a class="thumb" href="{$image}"><img src="{$image}" width="50px" height="50px" alt="{$image_alt}"></a></li>';
  }
} else {
  echo "no results returned from database";
} // end of mysql_num_rows check
?>

Comments

0

You might be better off concatenating all the images and then echo-ing it out rather than echo-ing each one e.g

$htmlOutput = '';

while($img = mysql_fetch_array($pimages)){
    $image = $img['image'];
    $image_alt = $img['image_alt'];
    $htmlOutput .= "<li><img src=\"{$image}\" alt=\"{$image_alt}\" /></li>";
}
 echo $htmlOutput ;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.