samoht Posted August 28, 2007 Share Posted August 28, 2007 Hello again, I have run into a situation and was hoping someone here could help. I have a little box on the right column of my site that displays the current seasons. It knows which ones to display based on my seasons table that has the season info plus a start and a end date for the season. Included in the info is a image url. My code to populate the box: <?php //Check What Season Should display $q = "SELECT Name, ImageURL FROM seasons WHERE NOW() > DateStart AND NOW() < DateEnd"; $result = dbQuery($q); while ($row = dbFetchAssoc($result)) { extract($row); echo "<img src=\"images/seasons/".$ImageURL."\" /><p><a href=\"catalog.php?g=144&season=$Name\">-$Name-</a><br />"; } My CSS to display the img proper: #seasonal img {position:absolute; bottom:0; right:0;} The quandary is "What to do if there are overlapping seasons"? - This is because holidays are also being considered in my seasons table (e.g. Halloween, Thanksgiving, Christmas, fall etc.) This is because the purpose of my seasonal box is not to display the 4 seasons per say but the products that are unique or associated with seasonal events Any ideas on the display of the picture problem? how can I display just the first img from the loop? Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/ Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 If you put an "ORDER BY DateStart DESC LIMIT 1", it should return the "embedded" season. So, if it is in Christmas season and winter, it should return christmas up util christmas DateEnd, then it should return winter. Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336309 Share on other sites More sharing options...
samoht Posted August 28, 2007 Author Share Posted August 28, 2007 Yes, but the purpose of my box is to display all the current seasonal links. So if it's November 28th and the client has set Thanksgiving to end on Nov. 31 - because he wants to run a sale on Thanksgiving Items after the holiday - but Christmas starts on Nov. 25 - they should both display in the link list - but the img for Thanksgiving should be the only one that displays. FYI - the img is a background img Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336333 Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 From your code, it looks like you are putting a new image next to each item. Is it returning duplicate items, one for each season that is overlapping? Can you post an example of the output and what you want to change it to? Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336384 Share on other sites More sharing options...
samoht Posted August 28, 2007 Author Share Posted August 28, 2007 currently I don't need to change the output because there are no over lapping seasonal links. I am worried though that my client may want to over lap them here is a screen shot of what I have [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336414 Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 You could just check if the image has already been printed in the while loop. If it has, don't print another one. Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336435 Share on other sites More sharing options...
samoht Posted August 28, 2007 Author Share Posted August 28, 2007 "The" image or "an" image? Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336537 Share on other sites More sharing options...
lemmin Posted August 28, 2007 Share Posted August 28, 2007 I guess, any image. You could count the rows to see if there is more than one season and if not, you don't even need a loop. If there is, only do the links in the loop. Something like: $q = "SELECT Name, ImageURL FROM seasons WHERE NOW() > DateStart AND NOW() < DateEnd"; $result = dbQuery($q); $row = dbFetchAssoc($result); extract($row); echo "<img src=\"images/seasons/".$ImageURL."\" /><p><a href=\"catalog.php?g=144&season=$Name\">-$Name-</a><br />"; if (dbNumRows($result) > 1) { while ($row = dbFetchAssoc($result)) { extract($row); echo "<p><a href=\"catalog.php?g=144&season=$Name\">-$Name-</a><br />"; } } I'm not familiar with the database functions you are using so I made up the dbNumRows() function. Switch that with whatever you would use to count how many rows are in the result. Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-336569 Share on other sites More sharing options...
samoht Posted August 30, 2007 Author Share Posted August 30, 2007 Why dose this throw 1 warning (Warning extract() should be in an array) and 3 notices (Undefined variable:) When there is more than 1 link?? Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-337709 Share on other sites More sharing options...
samoht Posted August 30, 2007 Author Share Posted August 30, 2007 Nevermind, as long as the query turns up more than 1 or at least 1 - I'm ok. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/67066-solved-set-img-display-quandary/#findComment-337727 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.