...

View Full Version : problem with absolute image path



Cyber_type
08-08-2007, 05:09 PM
Hi all,
i'm trying to develope a little dynamic galery based on mysql but i'm having some problems with the php script.
So her's the code of the table:



create table galerie (
imageid smallint(6) not null auto_increment,
imagename varchar(80) not null,
imagedesc tinytext,
date date default null,
primary key (imageid)
);

for the 'imagename field' i only gave the jpeg's name, who are stocked on a folder in the '.../easyphp/www/photos/' folder.

the script page presents like that:
galerie.php



<?php

$connection = mysql_connect("localhost","root","197676");
$database = mysql_select_db("myodb");

$query = "SELECT count(imageid) AS ImgCount
FROM galerie";
$result = mysql_query($query) or die("ERROR");
$ImgCount = mysql_result($result,0,"ImgCount");
echo "<br/><br/>$ImgCount image(s)<br/><br/>";


// Commence la table dans laquelle sont affichées les imagettes
echo "<table border='0' width='100%'><tr>";

// Récupère la liste des images de la rubrique sélectionnée
$query = "SELECT imageid
FROM galerie";
$result = mysql_query($query);

// On veut afficher 4 images par ligne
$NbrImgParLigne = 4;
$NumImgLigne = 0;

// Traite les images une après les autres
while ($row = mysql_fetch_array($result))
{
// Passe l'affichage des images à la ligne si 4 images affichées
if ($NumImgLigne>=$NbrImgParLigne)
{
echo "</tr><tr>";
$NumImgLigne = 0;
}

$NumImgLigne++;

// Commence une colonne de la grille pour y inclure l'image
echo "<td align='center'>";

// Récupère l'ID et le nom de l'image, en déduit le nom de la miniature
$ImageID = $row['imageid'];
$ImageName = $row['imagename'];
$MinImageName = "min_$ImageName";

// Chemin absolu de l'imagette
$ImagetteAbsolutePath = "/photos/.$MinImageName;

// Récupère les dimentions de l'imagette
$JPEGRes = ImageCreateFromJPEG($ImagetteAbsolutePath);
$xsrc = imagesx($JPEGRes);
$ysrc = imagesy($JPEGRes);

// Affiche le nom de l'image et sa miniature
echo "$ImageName<br/><img src='$ImagetteAbsolutePath'
width='$xsrc' height='$ysrc' border='0' alt='$ImageName'>";

// Termine la colonne de la grille pour cette image
echo "</td>";
}

// Termine la grille
echo "</tr></table>";
mysql_close();
?>


browsing galerie.php i have this error:
'Parse error: parse error, unexpected T_VARIABLE in F:\Program Files\EasyPHP 2.0b1\www\galerie_0.php on line 54'

the error is releationed with the path that i gave on the script? i have the 'photos' folder on the www folder and that's correct '/photos/' ?
Have also a problem with the first "select" request to have the number of pics stocked on the mysql table.....
Appreciate your help on my little project.
Anyways thank you a lot. Best regards Bruno

mcjwb
08-08-2007, 05:18 PM
Missing a quotation mark from this line (added in red):

$ImagetteAbsolutePath = "/photos/".$MinImageName;

StupidRalph
08-08-2007, 05:33 PM
Also, if you were to wrap your code in [ PHP ] tags by clicking the little php icon, it would have highlighted your text for you and you may have detected this yourself :).

Cyber_type
08-08-2007, 09:05 PM
@ mcjwb = it solves my first 'select' request (another stupid newbie error:rolleyes: ). Thanks.

I have simplified my script (get ridde of the image size funtions, later :cool: ):


<?php

$connection = mysql_connect("localhost","root","197676");
$database = mysql_select_db("myodb");

$query = "SELECT count(imageid) AS ImgCount
FROM galerie";
$result = mysql_query($query) or die("ERROR");
$ImgCount = mysql_result($result,0,"ImgCount");
echo "<br/><br/>There are $ImgCount image(s) in database.<br/><br/>";

echo "<table border='0' width='100%'><tr>";
$query = "SELECT imageid
FROM galerie";
$result = mysql_query($query);
$NbrImgParLigne = 4;
$NumImgLigne = 0;
while ($row = mysql_fetch_array($result))
{
if ($NumImgLigne>=$NbrImgParLigne)
{
echo "</tr><tr>";
$NumImgLigne = 0;
}

$NumImgLigne++;
echo "<td align='center'>";
$ImageID = $row['imageid'];
$ImageName = $row['imagename'];
$MinImageName = "min_$ImageName";
$ImagetteAbsolutePath = "/photos/".$MinImageName;

echo "$ImageName<br/><img src='$ImagetteAbsolutePath' border='0' alt='$ImageName'>";

echo "</td>";
}

echo "</tr></table>";
mysql_close();
?>


but another ohmy nasty problem:
"Notice: Undefined index: imagename in F:\Program Files\EasyPHP 2.0b1\www\galerie_.php on line 42"

got some research for the error value, it seems that it could be an error with the name of the field on the database table, but " $ImageName = $row['imagename'];" is on the table.....
@stupidRalph = thanks for the tip

whizard
08-08-2007, 09:07 PM
Try echoing $row['imagename'] to see if that has anything and if not, look at your query, and se if there's a reason that nothing would be returned for that field

HTH
Dan

CFMaBiSmAd
08-08-2007, 09:25 PM
So, how is the following query, supposed to return anything except "imageid" -

$query = "SELECT imageid FROM galerie";

Cyber_type
08-08-2007, 10:13 PM
you're right,


$query = "SELECT imagename
FROM galerie";

no more errors but only the name of the picture (.jpg).....
one question does the variable '$ImageAbsolutePath = "/photos/";' gives the path or must i insert it into the mysql table?
i feel that i am almost there but lots of studying php books are on my way....
thanks everybody

Cyber_type
08-09-2007, 03:47 PM
found it! i'm a happy newbie:p :p



<?php

$connection = mysql_connect("localhost","root","197676");
$database = mysql_select_db("myodb");

$query = "SELECT count(imageid) AS ImgCount
FROM galerie";
$result = mysql_query($query) or die("ERROR");
$ImgCount = mysql_result($result,0,"ImgCount");
echo "<br/><br/>There are $ImgCount image(s) in database.<br/><br/>";

echo "<table border='0' width='100%'><tr>";

$query = "SELECT imagename, imagedesc
FROM galerie
ORDER BY ImageName";
$result = mysql_query($query) or die("ERROR");
// $result = mysql_query($query);

$NbrImgParLigne = 4;
$NumImgLigne = 0;

while ($row = mysql_fetch_array($result))
{
if ($NumImgLigne>=$NbrImgParLigne)
{
echo "</tr><tr>";
$NumImgLigne = 0;
}

$NumImgLigne++;

echo "<td align='center'>";

$ImageName = $row['imagename'];
$ImageDesc = $row['imagedesc'];

echo "<br/><img src='$ImageName' border='0' <a href='$ImageName' target='blank'>
<br/><img src='$ImageDesc'border='0' alt='$ImageDesc'></a>";

echo "</td>";
}
echo "</tr></table>";
mysql_close();
?>


so i put the /photos/image.jpg on the mysql and that's it....now it seems so easy:cool:
also this code portion gives a way to click on the description and you have a new window with the pic but with the same size of the miniature:(



echo "<br/><img src='$ImageName' border='0' <a href='$ImageName' target='blank'>
<br/><img src='$ImageDesc'border='0' alt='$ImageDesc'></a>";

it works for me but it seems to be poor coding, ithink so....
so i would appreciate to have a large window on click the little one on a precise size (800*600)...PHP either javascript?
appreciate your advises or some tutorials or article that could solve my problem...
best regards bruno



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum