Images in a table

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Mon Apr 04, 2011 12:17 pm

A-10 Thunderbolt.. my favorite!

Code: Select all


$maxrow = 5;
$rowcount = 1;

$query = "SELECT src FROM images ORDER BY upload_date";
$result = mysql_query($query);

if (mysql_num_rows($result) > 0) { 
  echo '
  <div>
  <table>
  ';
  while ($row = mysql_fetch_assoc($result)) { 
    if ($rowcount == 1) { 
      echo '<tr>';
    }
    if ($rowcount <= $maxrow) { 
      echo '<td><img src="$row[src]" border="0"></td>';
    }
    if ($rowcount == $maxrow) { 
      echo '</tr>';
    }
    $rowcount++;
    if ($rowcount > $maxrow) { 
      $rowcount = 1;
    }
  }
  if ($rowcount != $maxrow || $rowcount != 1) { 
    for($a = $rowcount; $a <= $maxrow; $a++) { 
      echo '<td>&nbsp;</td>';
    }
    echo '</tr>';
  }
  echo '
  </table>
  </div>
  ';
} else { 
  echo "Search returned 0 results.<br/>";
}
 

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Mon Apr 04, 2011 12:45 pm

add this to the end of the query

$result = mysql_query($query) or die ("Something's wrong with the query: ".mysql_error());

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Mon Apr 04, 2011 12:46 pm

also..
make sure that the images are in the same directory, otherwise you'll have to alter your <img src=*> tag..

ie..
<img src="uploads/$row[src]" border="0">

or even check to see if src is the right table name..

Maybe it's something else?

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2192
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Mon Apr 04, 2011 12:55 pm

Ok..
so I checked your site..
and it's echoing the string data strait to the webserver.

change this..
echo '<td><img src="$row[src]" border="0"></td>';

to this
echo '<td><img src="'.$row['src'].'" border="0"></td>';

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests