Jump to content

Replace found results with images


snewpers

Recommended Posts

Hi,

I'm a beginner with php and I'm trying to figure this out, but I can't figure out what I'm doing wrong...

 

The situation so far:

I have a searchpage that functions properly with results that show the correct data. The are two (for now) fields that show selections:

 

$a1[LakeWaterfront]
$a1[NearPark]

 

Options for the above are yes or no ( 'y' or 'n'). In the search results they show up correct in each row (variations are 'yy', 'ny', 'yn', 'nn' but thats obvious). What I would like to do is save some space and replace the ones that are 'y' with an icon. I have an includescript that says:

 

<?
if( $a1[LakeWaterfront] == 'y' )
    {
        $icons .= "<img src=images/icons/1.gif>";
        }

if( $a1[NearPark] == 'y')
    {
        $icons .= "<img src=images/icons/2.gif>";
    }    
?>

 

The $icons is inserted in the searchresults.

The results however are weird (to me anyway). The first resultpage (1-5) shows the following:

 

row 1 - where result = 'yy'  it shows both icons (thats correct, might be coincidence?)

row 2 - where result = 'yn' it shows the same as row 1 (2 icons) PLUS an additional 1

row 3 - where result = 'nn' is shows the same as row 2

row 4 - where result = 'nn' is shows the same as row 2

row 5 - where result = 'nn' is shows the same as row 2

 

seems like it keeps adding iconlinks ontop of the previous result (image is attached to make things clear). I'm puzzled as how to prevent loading the $icons with too much data.

 

I've searched here and in google, tried all sorts of combinations but nothing works...

 

TIA,

JP

 

[attachment deleted by admin]

Link to comment
Share on other sites

It's not working  ???

 

the code now (after trying a few times)

 

<?

if(strstr($a1[LakeWaterfront],"y"))
{  str_replace("y","icon1",$icon1);
}

if(strstr($a1[NearPark],"y"))
{  str_replace("y","icon2",$icon2);
}


?>

 

i've include the $icon1 and $icon2 in the script:

 

$ListingTable .= "<td width=305>$a1[city], $a1[state], $a1[address] $sub $icon1 $a1[LakeWaterfront] $a1[NearPark]</td>\n\t";

Link to comment
Share on other sites

thanks suzzane2020,

 

I've included the next lines and it outputs the icontext correctly, but when its not a match it'll show the 'n' anyway.

 

result = y + n    it outputs 'icon1' and 'n'

result = n + n    it outputs 'n' and 'n'

 

I've tried an IF statement but that didn't work...

 

geez I'm a n00b!

 

<?
$icon1 = str_replace("y", "icon1", $a1[LakeWaterfront]);

$icon2 = str_replace("y", "icon2", $a1[NearPark]);

?>

Link to comment
Share on other sites

Nope, probably not. Sorry about that.

 

I would look into Regular Expressions. Or this:

 

<?php
/*
row 1 - where result = 'yy'  it shows both icons (thats correct, might be coincidence?)
row 2 - where result = 'yn' it shows the same as row 1 (2 icons) PLUS an additional 1
row 3 - where result = 'nn' is shows the same as row 2
row 4 - where result = 'nn' is shows the same as row 2
row 5 - where result = 'nn' is shows the same as row 2*/

$icon = str_replace("yy", $icon1 . $icon1, $al[LakeWaterfront]);
$icon = str_replace("yn", $icon1 . "n", $icon);
$icon = str_replace("nn", "nn", $icon);

?>

 

As long as those are the only options just manually hard code them in.

Link to comment
Share on other sites

hmmm I think I should try to explain better :)

 

I have multipe options in a signup form, like 'fireplace' 'nearwater' 'microwave' etc etc.

 

Users can choose between Yes or NO on those options (the 'y' and 'n' part).

 

I want to represent EVERY 'y' with an icon and show nothing from that option when it's 'n'.

 

So basicaly, I want to replace ALL 'y's with their corresponding icons and omit all 'n's. So if someone would look at their profile it would only show the icons of the things they said 'yes' to.

 

Something like the ICQ and MSN icons that show up here, at this board, when you actually put something there when you signup.

 

The list of optins will grow, so hardcoding it could be problematic, I'd rather end up with just one $ICONSET of all the icons that were 'yes'. Not sure if that can be done...

 

I hope it more clear now, excuse me if it's not  :-\

Link to comment
Share on other sites

hah!

 

FIXED it myself  ;D

 

the code is:

 

<?
if ($a1[LakeWaterfront] === 'n'){
$icon1="";} // text voor als het nee is
else{
$icon1="<img src=images/icons/1.gif height=20>";
}
if ($a1[NearPark] === 'n'){
$icon2="";} // text voor als het nee is
else{
$icon2="<img src=images/icons/2.gif height=20>";
}
?>

 

all i need to do to add another icon is copy/paste the if's, edit the tags and upload a new icon!

 

Thanks anyway

 

JP

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.