PDA

View Full Version : Callin Image path & zip file path from Database


srule_
10-12-2007, 07:34 PM
I have a very strange problem. When i call the img and the zip file only the zip file shows. When i call only the image it shows fine.

The Code if I am calling both:

// this is hardcoded or selected from a settings table in the database
$image_path = '/template_site/images/screenshots/';
$zip_path='http://localhost/template_site/zipped_temps/';
// make the query
$query = "SELECT CONCAT(temp_name) AS name, CONCAT(images) AS img, CONCAT(zips) AS zip, DATE_FORMAT(date_added, '%M %d, %Y') AS da FROM template ORDER BY date_added ASC";

//run the query
$result= @mysql_query($query);

//if query went ok
if ($result)
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<p>'.$row['name'].' on <img src="' . $image_path . $row['img'] . '" /></p>';
echo '<p><a href="'.$zip_path . $row['zip'] . ' > download here </a></p>';
}

else {
echo 'it did not work';
}


- This will only output the "download here" part

The code of i am not calling the zip


// this is hardcoded or selected from a settings table in the database
$image_path = '/template_site/images/screenshots/';
$zip_path='http://localhost/template_site/zipped_temps/';
// make the query
$query = "SELECT CONCAT(temp_name) AS name, CONCAT(images) AS img, CONCAT(zips) AS zip, DATE_FORMAT(date_added, '%M %d, %Y') AS da FROM template ORDER BY date_added ASC";

//run the query
$result= @mysql_query($query);

//if query went ok
if ($result)
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<p>'.$row['name'].' on <img src="' . $image_path . $row['img'] . '" /></p>';
}

else {
echo 'it did not work';
}


this works fine, everything that is called is outputed

Inigoesdr
10-12-2007, 07:40 PM
You're missing the brackets for your if/else.
It should be like this:if ($result)
{
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<p>'.$row['name'].' on <img src="' . $image_path . $row['img'] . '" /></p>';
echo '<p><a href="'.$zip_path . $row['zip'] . ' > download here </a></p>';
}
}
else
{
echo 'it did not work';
}
If you get into the habit of indenting your code you will notice things like this right away.

srule_
10-12-2007, 07:51 PM
thx for that tip. I added the bracket and indented my code but it didnt solve the original problem.

Inigoesdr
10-12-2007, 07:54 PM
Ok, post the exact output you're getting.

CFMaBiSmAd
10-12-2007, 08:03 PM
The while(...){...} loop construct is considered a "single" statement following the if(). However, always using {...} around conditional/loop statements, even when you only have a single statement is "best" programming practices.

I for one don't understand what is or is not working and what "shows" means. Post the actual "view source" from the browser for each case.

srule_
10-12-2007, 08:04 PM
when i cal the name,image and zip file i get:



test on

download here


when i cal the name and image everything works ok, the output:

test on NAME, IMAGE


and when i write this statment:

echo '<p>'.$row['name'].' on <img src="' . $image_path . $row['img'] . '" /></p>';
echo '<p><a href="'.$zip_path . $row['zip'] . ' > download here </a></p>';


in reverse like this:

echo '<p><a href="'.$zip_path . $row['zip'] . ' > download here </a></p>';
echo '<p>'.$row['name'].' on <img src="' . $image_path . $row['img'] . '" /></p>';


i get no output

CFMaBiSmAd
10-12-2007, 08:14 PM
The href="..." parameter is missing the closing "