Current location: Hot Scripts Forums » Programming Languages » PHP » Displaying default images


Displaying default images

Reply
  #1 (permalink)  
Old 01-15-04, 05:37 AM
galesjam galesjam is offline
New Member
 
Join Date: Jan 2004
Location: UK
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Displaying default images

Hello!

I have just started with PHP and MySQL. I don't have it on my computer and am using my web space proveder (uksecurewebhosting.net). When creating a table it appears like a form with the usual feilds (feild, type, length/set, attributes, null, default, extra) I have an exisitng table that has the following fields:
link, varchar (50), NULL, (Default)image.jpg (name of file not the actual picture)
hotel, varchar (50), NOT NULL,Primary Key
location, varchar (50), NULL,
rating, varchar (10), NULL,
price, varchar (10), NULL,

When I call up the data I wanted the default image (image.jpg) to appear if no other image is stated. But as it runs now, no image appears (just a broken image).
When I enter new data all the fields appear on screen with blank boxes next to them and I just enter the data I want to show (leaving the 'link' field blank if I want the default image to display). My test web page is www.galesjam.co.uk/text/hotels.php where you can see the one image that doesn't display.

The code I am using is (a partialy sortable table - just starting!):
<html>
<head>
</head>

<body bgcolor=#00184A>
<br><br><br><br>
<table align="center" width=60%
border=0 rules=none
bordercolorlight="white" bordercolordark="white"
cellpadding=2>
<tr>
<td colspan=5> <br><br>
</td>
<tr>
<tr>
<td align="Left"width=20%>Link</p>
</td>
<td align="Left"width=30%><A href="hotels.php"><p class="marked">Hotel</p></a>
</td>
<td align="Left"width=30%><p class="marked">Location</p>
</td>
<td align="Left"width=10%><p class="marked">Rating</p>
</td>
<td align="Left"width=10%><p class="marked">Price</p>
</td>
</tr>

<?php

$db_connection = mysql_connect ("localhost","XXXX","XXXX");
mysql_select_db ("XXXX");

$query = "select * from hotels order by hotel";

$query_result = mysql_query($query);

while ($Row = mysql_fetch_array($query_result)) {

Print ("<tr>\n");
Print ("<td align=left><img src=\"$Row[link]\" border=0></td>");
Print ("<td align=left>$Row[hotel]</td>");
Print ("<td align=left>$Row[location]</td>");
Print ("<td align=left>$Row[rating]</td>");
Print ("<td align=left>$Row[price]</td>");
Print ("</tr>");
}


mysql_free_result($query_result);
mysql_close();

?>

</table>
</body>
</html>

Any help/suggestions!?
Reply With Quote
  #2 (permalink)  
Old 01-15-04, 09:04 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

Is it possible that you have your images in a subdirectory such as "images/" and you are supposed to prepend this to the $Row['link']?

To illustrate, this is what you are getting:

PHP Code:

<td align=left><img src="image.jpg" border=0></td
BUT this is what you want:

PHP Code:

<td align=left><img src="images/image.jpg" border=0></td
If this is not the case, check the property of the broken image link on your browser and see what path it is referring to (and see if there is such a file at such a path).

Incidentally, you should quote your array keys like this: $Row['link'] . And for futuer posts, you may want to use the board's [ php ] [ /php ] tags for eye-friendlier code posting.

Cheers.
__________________
Blavv =|
Reply With Quote
  #3 (permalink)  
Old 01-16-04, 09:58 AM
galesjam galesjam is offline
New Member
 
Join Date: Jan 2004
Location: UK
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the reply Blaw.

I do have some images in another folder (called Images), but the default image (image.jpg) is in the same folder as the PHP file (as well as the Images folder).

I was thinking that a way around this would be to use an if statement. The only problem with that is that I am not sure how to!!! (very new to PHP).

How would I write code that said, If no image is shown then show 'image.jpg'
Reply With Quote
  #4 (permalink)  
Old 01-16-04, 12:33 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi again,

So can your default image be displayed without any problem now?

I assume that you want to set a condition (i.e. IF) to see if the file's link exists in MySQL, and if not, show the default image.

IF statement is not difficult to apply, but I think you should make sure that you know how to display the default image and database-link images correctly first (i.e. without the IF condition, separately).

IF statement is one of the language basics that usually appears in a manual or books before MySQL functions you are using in your code, and I encourage you to study it:

http://ca3.php.net/manual/en/control...-structures.if
__________________
Blavv =|
Reply With Quote
  #5 (permalink)  
Old 01-16-04, 04:23 PM
galesjam galesjam is offline
New Member
 
Join Date: Jan 2004
Location: UK
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

Still no luck displaying the default image. It's acting like the entry in the default box is just being ignored. Does it matter what type is for the field (varchar etc)?

Quote:
I assume that you want to set a condition (i.e. IF) to see if the file's link exists in MySQL, and if not, show the default image.
Yep your right there.

Thanks for the link!
Going to pick up a decent PHP book just as soon as I can find enough money, so in the meantime I'm making the most out of the internet and what it has to offer for free.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM
Help with making a installer config script dazz Job Offers & Assistance 3 09-29-03 02:51 AM
Displaying images! boskyvora PHP 4 06-30-03 07:53 AM


All times are GMT -5. The time now is 08:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.