TechMistress Posted October 23, 2008 Share Posted October 23, 2008 Hello All... I have a script that includes a 'showbanner.php' file on a page. It's pretty straight forward. When I duplicate the file, changing the type of banner and include that also, the page just mixes up all of the banner types, rather than keeping just the type I want in the place I want. Here's the code: $qsb = "select BannerID from banners where BannerType = 'Top' "; $rsb = mysql_query($qsb) or die(mysql_error()); if(mysql_num_rows($rsb) > '0') { while($asb = mysql_fetch_array($rsb)) { $NewBannersArray[] = $asb[bannerID]; } $DisplayBannerID = array_rand($NewBannersArray); $BannerID = $NewBannersArray[$DisplayBannerID]; //get the selected banner info $qsb2 = "select * from banners where BannerID = '$BannerID' "; $rsb2 = mysql_query($qsb2) or die(mysql_error()); $asb2 = mysql_fetch_array($rsb2); echo "<A href=\"re_counter.php?BannerID=$BannerID\"><img src=\"/directory/banner_images/$asb2[bannerFile]\" alt=\"$asb2[bannerAlt]\" border=0></a>"; $date_now = time(); $this_ip = $_SERVER[REMOTE_ADDR]; $qsb3 = "insert into banner_stats set BannerID = '$BannerID', impressions = '1', mydate = '$date_now', ip = '$this_ip' "; mysql_query($qsb3) or die(mysql_error()); } I thought I could create another showbanner file. (showbannerbottom.php), let's say and just change the tupe at the top. Didn't work. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/ Share on other sites More sharing options...
Barand Posted October 23, 2008 Share Posted October 23, 2008 It could be a clash of variable names if both files are included. eg $BannerID will be used twice. Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673181 Share on other sites More sharing options...
Alt_F4 Posted October 23, 2008 Share Posted October 23, 2008 Have you tried running the second file independently of the first? Does it work in that situation? Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673189 Share on other sites More sharing options...
TechMistress Posted October 23, 2008 Author Share Posted October 23, 2008 Sorry I wasn't clear... Yes, each file will run independently just fine. It is exactly as you said, because the variables are named the same in each file, the banners just show up randomly, instead of with the correct 'type' in the correct place. I wanted to know if anyone knew how to write it so either it's just one file (instead of include bannertop, include bannerbottom, etc. on the page) - or how to change the variable in each file. Is it as simple as renaming qsb/rsb to asb/bsb/csb, etc? - although that seems awfully messy. As you can tell, I'm learning php! Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673203 Share on other sites More sharing options...
Barand Posted October 23, 2008 Share Posted October 23, 2008 Search and replace - change "$" to, say, "$x" Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673206 Share on other sites More sharing options...
TechMistress Posted October 23, 2008 Author Share Posted October 23, 2008 Great, that did it! I went through each of my banner files and just added a unique letter for each file after the $. It's probably messy programming, but it works. Someday I'll brilliantly produce a sing, 2-line piece of code that will solve all of the world's web problems... until then, thanks for the feedback everyone! Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673278 Share on other sites More sharing options...
.josh Posted October 23, 2008 Share Posted October 23, 2008 Someday I'll brilliantly produce a sing, 2-line piece of code that will solve all of the world's web problems... until then, thanks for the feedback everyone! die("Goodbye, cruel world!"); Quote Link to comment https://forums.phpfreaks.com/topic/129836-need-help-duplicating-code-without-duplicating-results/#findComment-673285 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.