Connecting Tech Pros Worldwide Forums | Help | Site Map

Need help with gallery script I am writing

A
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi everyone

I was working on a php script to display images and I am running into
problems. My problems are when I execute the query to thumb path it won't
display the image/s.

Anyhelp is alway's appreciated

I have a mysql table with the following structure

image_id Integer Auto_increment
title varchar
descript text
thumb_path varchar
imaage_path varchar
category_id Integer

and my script

<html>
<body>


<?php

$link = @mysql_connect("localhost", "myuser", "mypass");

if (!$link) {
print "Could not connect to server";
exit;
}

if (!@mysql_select_db("photos_db")) {
print "Could not select database";
exit;
}

$query1 = "SELECT * FROM categories";
$query2 = "SELECT * FROM images ORDER BY image_id DESC";

$result1 = mysql_query($query1);
$result2 = mysql_query($query2);

?>

<table width="700" bgcolor="#CCCCCC">
<tr>
<td width="700" align="center" valign="middle" height="50">
<?php

if ($result1 && @mysql_num_rows($result1) > 0) {
$data1 = "";
while ($row1 = mysql_fetch_array($result1)) {

$data1 .= '<font color="black" size="14">';
$data1 .= $row1['category_description'];

}
echo $data1;
}

?>
</td>
</tr>


<?php
//here is where I am running into problems
//it does not want to display the image even though I specify the path
if ($result2 && @mysql_num_rows($result2) > 0) {
$data2 = "";
while ($row2 = mysql_fetch_array($result2)) {
$data2 .= $row2['thumb_path'];


?>


<td><img src="<?php echo "$data2";?>"></td>

<?php
}
}
?>
</tr>

</table>

</body>
</html>



Shawn Wilson
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Need help with gallery script I am writing


A wrote:[color=blue]
>
> I was working on a php script to display images and I am running into
> problems. My problems are when I execute the query to thumb path it won't
> display the image/s.
>
> Anyhelp is alway's appreciated
>
> I have a mysql table with the following structure
>
> image_id Integer Auto_increment
> title varchar
> descript text
> thumb_path varchar
> imaage_path varchar
> category_id Integer
>
> and my script
>
> <html>
> <body>
>
> <?php
>
> $link = @mysql_connect("localhost", "myuser", "mypass");
>
> if (!$link) {
> print "Could not connect to server";
> exit;
> }
>
> if (!@mysql_select_db("photos_db")) {
> print "Could not select database";
> exit;
> }
>
> $query1 = "SELECT * FROM categories";
> $query2 = "SELECT * FROM images ORDER BY image_id DESC";
>
> $result1 = mysql_query($query1);
> $result2 = mysql_query($query2);
>
> ?>
>
> <table width="700" bgcolor="#CCCCCC">
> <tr>
> <td width="700" align="center" valign="middle" height="50">
> <?php
>
> if ($result1 && @mysql_num_rows($result1) > 0) {
> $data1 = "";
> while ($row1 = mysql_fetch_array($result1)) {
>
> $data1 .= '<font color="black" size="14">';
> $data1 .= $row1['category_description'];
>
> }
> echo $data1;
> }
>
> ?>
> </td>
> </tr>
>
> <?php
> //here is where I am running into problems
> //it does not want to display the image even though I specify the path
> if ($result2 && @mysql_num_rows($result2) > 0) {
> $data2 = "";
> while ($row2 = mysql_fetch_array($result2)) {
> $data2 .= $row2['thumb_path'];
>
> ?>
>
> <td><img src="<?php echo "$data2";?>"></td>
>
> <?php
> }
> }
> ?>
> </tr>
>
> </table>
>
> </body>
> </html>[/color]

I could be wrong (I just looked at it quickly) but it looks like you're shoving
a bunch of thumb_paths for multiple images into a singe <IMG> tag without even
specifying an image name. Check the resulting html code. I'm guessing you get
something like:

<img src="images/thumbs/images/thumbs/images/thumbs">

If this is the case, include the image name in $data2 and don't use a while loop
to build data2. Use a while loop to write all your <IMG> tags.

Shawn
--
Shawn Wilson
shawn@glassgiant.com
http://www.glassgiant.com
Closed Thread