Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-20-2005, 02:25 PM
WebProWorld New Member
 

Join Date: Aug 2003
Location: uk
Posts: 11
armadacomputers RepRank 0
Default Need help with alt tags in Perl

Hi.

We had this code written for us and we want to do some small alterations.

$tmp_alt="";
$tmp_alt=qq| alt=$INSERT{name}| if $row[7];
$INSERT{image} = qq|[img]$image_dir/$row[6][/img]| if $row[6];
$INSERT{image} ="<a href=\"$row[7]\" target=_blank>$INSERT{image}</a>" if $row[7] && $INSERT{image};
$INSERT{id} = "$row[0]";
for(1..$row[9]){$INSERT{rating}.="<img src=\"$img3\" border=0 align=top>";}
$row[12]=~s/,/<option>/ig;
$INSERT{options} = "<font class=price>Option:</font> <select name=options_$row[0]><option>".$row[12]."</select>" if $row[12];

Basically we want the name of the product to appear as the alt tag to the image unfortunetly with the code above only the first word of the name appears rather than the complete description.

We have not been able to work out why this happens so any help would be apprecitated. We are also looking at how we can make a defualt image appear if the image the code points to is not valid any help with this would be appreciated.
Reply With Quote
  #2 (permalink)  
Old 08-21-2005, 06:31 PM
brian.mark's Avatar
Administrator
 

Join Date: Jul 2004
Location: Omaha
Posts: 2,717
brian.mark RepRank 2brian.mark RepRank 2
Default Not enough...

Not enough information here to really tell you. The variable must have had a value assigned (incorrectly) before the code you showed us.

If you want to PM me a bigger snip, I could probably get an answer to you pretty quickly.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #3 (permalink)  
Old 08-22-2005, 03:03 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: uk
Posts: 11
armadacomputers RepRank 0
Default Thanks for the help

Thanks but I managed to sort it out, all I need to do was put "'s around alt=$INSERT{name} so it became alt="$INSERT{name}".
Reply With Quote
  #4 (permalink)  
Old 08-22-2005, 03:05 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: uk
Posts: 11
armadacomputers RepRank 0
Default But would still like to add code for missing image

Heres a bit more of the code, what would I need to add/alter on this to put standard pic if path to image is invalid or missing.

$INSERT{price} = $row[3];
$INSERT{trade_price} =sprintf("%.2F",($row[3]*$coef_trade));
$INSERT{customer_price} =sprintf("%.2F",($row[3]*$coef_web));
if ($row[13]){$INSERT{vat_price} = sprintf("%.2F",($row[3]*$coef_web));}
else{$INSERT{vat_price} = sprintf("%.2F",($row[3]*$coef_web*$coef_vat));}
$INSERT{name} = $row[2];
$INSERT{description} = $row[8];
$INSERT{text} = $row[10];
$INSERT{weight} = $row[11];
$row[16] = sprintf("%.2F",($row[15] - $INSERT{customer_price}));
$INSERT{RRP} = "
<font class=price2>Save &pound; $row[16]</font> <font class=\"cost\">on RRP of &pound; $row[15]

</font>" if $row[15];

$tmp_alt="";
$tmp_alt=qq| alt="$INSERT{name}"| if $row[7];
$INSERT{image} = qq|[img]$image_dir/$row[6][/img]| if $row[6];
$INSERT{image} ="<a href=\"$row[7]\" target=_blank>$INSERT{image}</a>" if $row[7] && $INSERT{image};
$INSERT{id} = "$row[0]";
for(1..$row[9]){$INSERT{rating}.="<img src=\"$img3\" border=0 align=top>";}
$row[12]=~s/,/<option>/ig;
$INSERT{options} = "<font class=price>Option:</font> <select name=options_$row[0]><option>".$row[12]."</select>" if $row[12];

#$p = substr(addslashes($INSERT{name}), 0, 10);
#$INSERT{hash}=md5_hex($secret_key . $p . $INSERT{customer_price} . $INSERT{weight});
$INSERT{free_delivery} = "<img src=\"$imgFree\" border=0 alt=\"FREE DELIVERY WITH THIS PRODUCT!\">" unless $INSERT{weight};
$INSERT{WEB} = qq~[img]$imgWeb[/img]~ if $row[7];

$INSERT{menu} = mmenu($FORM{cat});
$text.=get_record($template);
$INSERT{title} = $INSERT{name};
$INSERT{title} =~s/ /\/g;
Reply With Quote
  #5 (permalink)  
Old 08-22-2005, 03:45 AM
brian.mark's Avatar
Administrator
 

Join Date: Jul 2004
Location: Omaha
Posts: 2,717
brian.mark RepRank 2brian.mark RepRank 2
Default Easy enough...

That'd be easy enough.

After this line:

$INSERT{image} = qq|[img]$image_dir/$row[6][/img]| if $row[6];

Add these:

my $path = qq|/base/path/to/image/dir/|;
$INSERT{image} = qq|[img]$image_dir/coming_soon.gif[/img]| unless (-e "$path/$image_dir/$row[6]");

Before this:

$INSERT{image} ="<a href=\"$row[7]\" target=_blank>$INSERT{image}</a>" if $row[7] && $INSERT{image};


Just set the path correct and you should get a coming soon or whatever image you code in if the image doesn't exist. The path could be absolute (/home/www/site.com/html/) or relative from the script's directory (../html/). Either should work for you.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #6 (permalink)  
Old 08-22-2005, 04:49 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: uk
Posts: 11
armadacomputers RepRank 0
Default okay that worked, but...

Have also triued to alter this similar code but now all images report as missing, I know I have made a schoolboy error but where


$INSERT{name} = $row[2];
$INSERT{description} = $row[8];
$INSERT{weight} = $row[10];
$INSERT{enlarge} = "
<table align=right><tr><td>enlarge</td></tr></table>" if $row[12];
$INSERT{price_down} = qq|<table width=100%><tr><td align=right>[img]$button_dir/price_reduction.gif[/img]</td></tr></table>\n| if $price_down{$row[0]};
$INSERT{thumbnail} = qq|[img]$image_dir/$row[6][/img]| if $row[6];
$INSERT{thumbnail} = qq|| unless (-e "$path/$image_dir/$row[6]");
$INSERT{thumbnail} ="<a href=\"$PROG_NAME?product=$row[0]&cat=$FORM{cat}\">$INSERT{thumbnail}</a>" if $INSERT{thumbnail};
Reply With Quote
  #7 (permalink)  
Old 08-22-2005, 04:54 AM
brian.mark's Avatar
Administrator
 

Join Date: Jul 2004
Location: Omaha
Posts: 2,717
brian.mark RepRank 2brian.mark RepRank 2
Default Where did you define...

Where did you define $path at? It's not in this snippet of code.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #8 (permalink)  
Old 08-22-2005, 04:54 AM
brian.mark's Avatar
Administrator
 

Join Date: Jul 2004
Location: Omaha
Posts: 2,717
brian.mark RepRank 2brian.mark RepRank 2
Default Where did you define...

Where did you define $path at? It's not in this snippet of code.

Brian.
__________________
ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies
Reply With Quote
  #9 (permalink)  
Old 08-22-2005, 05:05 AM
WebProWorld New Member
 

Join Date: Aug 2003
Location: uk
Posts: 11
armadacomputers RepRank 0
Default Cheers, sorted it

Great minds think a like LOL, just noticed that adapted and now works thanks for all your help
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , ,



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

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


Search Engine Optimization by vBSEO 3.2.0