fareforce Posted September 8, 2008 Share Posted September 8, 2008 I will start off by saying that I am not very good at php, but I know enough to break things. lol Anyways on to my problem. I have two files properties.php, and propcontrol.php. Right now it is setup so when you view properties.php if pulls information from propcontrol.php to display pictures of different properties. To display the pictures I am currently using the following: <a href="<?php print "$pic1a"; ?>" rel="lightbox[<?php print "$prop_code1" ?>]"><img src="<?php print "$pic1a"; ?>" width="32" height="32" /></a> This is what propcontrol.php looks like: // Property #1 $prop_code1 = "GN110"; $sqft1 = "1520"; $txt1 = "Very nice property"; $pic1a = "/images/properties/1a.jpg"; $pic1b = "/images/properties/1b.jpg"; $pic1c = "/images/properties/1c.jpg"; $pic1d = "/images/properties/1d.jpg"; $pic1e = "/images/properties/1e.jpg"; $pic1f = "/images/properties/1f.jpg"; $pic1g = "/images/properties/1g.jpg"; The for the second property the format would be: ]// Property #2 $prop_code1 = "WBP210"; $sqft1 = "2150"; $txt1 = "Very nice property"; $pic2a = "/images/properties/2a.jpg"; $pic2b = "/images/properties/2b.jpg"; $pic2c = "/images/properties/2c.jpg"; $pic2d = "/images/properties/2d.jpg"; The problem with all of this is it makes the code very messy, and it is very time consuming to add new properties. I would like to make it so if $pic1a = ""; it will display /images/nopic.jpg, and it will automatically see how many properties there are total, and how many photos there are for each and display them. I have never done looping satements before, and I can't get this one to work. The closest I can get (although it doesn't loop) was: <?php If ( $pic1b = "" ) { echo'<a href="/images/nopic.gif" rel="lightbox['; print "$prop_code1"; echo']"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href="'; print "$pic1b"; echo'" rel="lightbox['; print "$prop_code1"; echo']"><img src="'; print "$pic1b"; echo'" width="32" height="32" /></a>'; }; ?> But that doesn't work correctly as it outputs: <a href="" rel="lightbox[GN110]"><img src="" width="32" height="32" /></a> Please help! Quote Link to comment https://forums.phpfreaks.com/topic/123324-solved-looping-an-ifthen-statement-help/ Share on other sites More sharing options...
Maq Posted September 8, 2008 Share Posted September 8, 2008 should be: [code] And this: [code]{ echo''; }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/123324-solved-looping-an-ifthen-statement-help/#findComment-636939 Share on other sites More sharing options...
fareforce Posted September 8, 2008 Author Share Posted September 8, 2008 Thank you! What about the looping statement part? How would I go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/123324-solved-looping-an-ifthen-statement-help/#findComment-636990 Share on other sites More sharing options...
fareforce Posted September 8, 2008 Author Share Posted September 8, 2008 [code]Ok. So I am working on trying to get the above code to be a lot more simple. I basically need it to count how many properties need to be displayed (ie. prop_code1. prop_code2, etc.) I tried using this to figure it out, but it is far from working [code]<?php preg_match ('@^(?:prop_code)?([^/]+)@i', "propcontrol.php", $propnum); print_r($propnum); ?> It just returns back Array ( [0] => propcontrol.php [1] => propcontrol.php ) . So i need to figure out a way to count the properties, then get the information from propcontrol.php (which looks like this) // Property #1 $prop_code1 = "GN110"; $sqft1 = "1520"; $txt1 = "Very nice property"; // (ie. $pic1a = "images/properties/1a.jpg" $pic1a = "images/properties/1a.gif"; $pic1b = "images/properties/1b.gif"; $pic1c = "images/properties/1c.gif"; $pic1d = "images/properties/1d.jpg"; $pic1e = "images/properties/1e.jpg"; $pic1f = ""; $pic1g = ""; into this format, and automatically repeat for each property in propcontrol.php: <div class="row_top" style="padding-left:0;"> <div class="col_1 maxheight"> <div class="indent_left text text_lin"> <b> Property Code: GN110</b><br /> <table width="250" border="0"> <tr> <td width="114"> <a href=images/properties/1a.gif rel="lightbox["GN110"]"><img src="images/properties/1a.gif" height="100" /></a></td> <td width="10"></td> <td width="112"> <div align="left"> <a href=images/properties/1b.gif rel="lightbox["GN110"]"><img src="images/properties/1b.gif" width="32" height="32" /></a> <a href=images/properties/1c.gif rel="lightbox["GN110"]"><img src="images/properties/1c.gif" width="32" height="32" /></a> <a href=images/properties/1d.jpg rel="lightbox["GN110"]"><img src="images/properties/1d.jpg" width="32" height="32" /></a> <a href=images/properties/1e.jpg rel="lightbox["GN110"]"><img src="images/properties/1e.jpg" width="32" height="32" /></a> <a href="/images/nopic.gif" rel="lightbox["GN110"]"><img src="/images/nopic.gif" width="32" height="32" /></a> <a href="/images/nopic.gif" rel="lightbox["GN110"]"><img src="/images/nopic.gif" width="32" height="32" /></a> Here is what I am currently doing to display each property, and it works, but adding a new property takes awhile as this code only does one property: <div class="row_top" style="padding-left:0;"> <div class="col_1 maxheight"> <div class="indent_left text text_lin"> <b> Property Code: <?php print "$prop_code1"; ?></b><br /> <table width="250" border="0"> <tr> <td width="114"> <?php If ( $pic1a == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" height="100" /></a>'; } else { echo'<a href=' . $pic1a . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1a . '" height="100" /></a>'; }; echo'</td><td width="10"></td><td width="112"><div align="left">'; If ( $pic1b == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1b . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1b . '" width="32" height="32" /></a>'; }; If ( $pic1c == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1c . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1c . '" width="32" height="32" /></a>'; }; If ( $pic1d == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1d . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1d . '" width="32" height="32" /></a>'; }; If ( $pic1e == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1e . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1e . '" width="32" height="32" /></a>'; }; If ( $pic1f == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1f . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1f . '" width="32" height="32" /></a>'; }; If ( $pic1g == "" ) { echo'<a href="/images/nopic.gif" rel="lightbox["' . $prop_code1 . '"]"><img src="/images/nopic.gif" width="32" height="32" /></a>'; } else { echo'<a href=' . $pic1g . ' rel="lightbox["' . $prop_code1 . '"]"><img src="' . $pic1g . '" width="32" height="32" /></a>'; }; ?> Any pointers or help would be greatly appriciated! Am I even heading in the right direction?[/code][/code] Quote Link to comment https://forums.phpfreaks.com/topic/123324-solved-looping-an-ifthen-statement-help/#findComment-637048 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.