snewpers Posted March 20, 2007 Share Posted March 20, 2007 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] Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 U cud use the str_replace function for this search if the string has y and if so replace the letter with the image if(strstr($str,"y")) { str_replace("y","<img></img>,$str) } Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 20, 2007 Author Share Posted March 20, 2007 thanks, but wouldn't that change all the 'y's into the same icon? I need different icons representing the different answers... Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 diff answers as in the 2 strings? $a1[LakeWaterfront] $a1[NearPark] ? Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 20, 2007 Author Share Posted March 20, 2007 yes, lakewaterfront should display icon1.gif (if it's 'y' only) and nearpark should display icon2.gif (if it's 'y' only) Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 20, 2007 Share Posted March 20, 2007 so use the str_replace for both the strings separately and give diff images for each Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 21, 2007 Author Share Posted March 21, 2007 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"; Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted March 21, 2007 Share Posted March 21, 2007 its str_replace("string to be replaced" , "string to replace" , original string) str_replace("y",<img>,$str Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 21, 2007 Author Share Posted March 21, 2007 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]); ?> Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 21, 2007 Author Share Posted March 21, 2007 bump Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 <?php $icon1 = str_replace("lakewaterfront", "icon1", $a1[LakeWaterfront]); $icon2 = str_replace("nearpark", "icon2", $a1[NearPark]); ?> Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 21, 2007 Author Share Posted March 21, 2007 uhm not sure how that would help me, frost110 Quote Link to comment Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 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. Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 21, 2007 Author Share Posted March 21, 2007 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 :-\ Quote Link to comment Share on other sites More sharing options...
snewpers Posted March 22, 2007 Author Share Posted March 22, 2007 hah! FIXED it myself 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.