gckmac Posted May 30, 2009 Share Posted May 30, 2009 I have some php code that works just fine. It queries the database and outputs the results (e.g., a list of vacation rentals). However, when I insert new php code above the working code - and the new code also queries the database - it screws up the working code. So basically I think I need some sort of "reset" function. To see functionality go to, e.g., www.maine.info/cities/newry/vacation_rentals.php. On the far right side of that page is a drop down box that I want to move to the center of the page, meaning that it comes before the php code that populates the page. Here is the code that I want to move from the right and insert to the top center: <select id="scampcity" name="scampcity"> <option value="-1">Select City...</option> <?php $query = "select distinct(city) from maine_hotels where city <> '' and state = 'Maine' and type = 'Vacation Rental' order by city "; $result = mysql_query($query, $link); while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<option value = '$city'"; if ($city == $gcity) echo " selected "; echo ">$city</option>\n" ; } ?> </select> <input type="button" name="campcitychange" id="campcitychange" value="Go" /> Here is the code that works UNTIL I insert the above code above it. Again, I think the issue is so somehow cause a reset before invoking the below code: <?php while ($row = mysql_fetch_assoc($result)) { extract($row); if ($highRate != "" && $lowRate != "") { $range = " Range $" . $highRate . " to $" . $lowRate; } else { $range = ""; } $booking = (substr(trim($bookingurl), 0, 7) != "http://")? "" : "<a href = '$bookingurl' >$bookingtext</a> | "; /* if (substr($imageurl, 0, 7) != "http://") { $imageurl = "http://" . $imageurl; } */ $description = (trim($propertyDescription) == "") ? "": "<p><strong>Description</strong>: $propertyDescription</p>"; $namehtml = (substr(trim($linkurl), 0, 7) != "http://") ? "$name": "<a href = '$linkurl' >$name</a>"; $logo = (substr(trim($smlogo), 0, 7) != "http://") ? "": "<p class = 'propertylogo' style = 'float:right;'><img src = '$smlogo' width = '120px' height = '90' /></p> "; echo <<<ENT $logo <h2>$namehtml</h2> <p><font face="arial" size="2"> $address1 <br /> $city, $state $postalcode <br /> Phone: $phone1 <br /> $booking <a href = "http://www.maine.info/sandbox/maps/map2.php?type=001000000&city=$gcity&zoom=13">Map + Directions</a> </p> $description </font><hr /> ENT; } ?> Would appreciate any thoughts on this. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/ Share on other sites More sharing options...
MadTechie Posted May 30, 2009 Share Posted May 30, 2009 #1 use code tags #2 are you doing another query before the next loop ? if not then you can move internal result pointer like this <?php mysql_data_seek($result, 0);//go back to first records while ($row = mysql_fetch_assoc($result)) { \\... ?> Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/#findComment-845775 Share on other sites More sharing options...
gckmac Posted May 30, 2009 Author Share Posted May 30, 2009 I inserted the reset pointer function. It still mucks up the code below. The result looks like this, meaning that the drop list of cities becomes all that appears in the center box, rather than the specific city result. All Lodging in Newry: Bed & Breakfasts (All Maine) | Campgrounds (All Maine) | Hotels (All Maine) | Vacation Rentals (All Maine) Greenville, Phone: Map + Directions | Report Error Newry, Phone: Map + Directions | Report Error Raymond, Phone: Map + Directions | Report Error This beats me! gckmac Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/#findComment-845784 Share on other sites More sharing options...
gckmac Posted May 30, 2009 Author Share Posted May 30, 2009 Here is the code with Insertion ... the <select id=...> code just takes over: <select id="scampcity" name="scampcity"> <option value="-1">Select City...</option> <?php $query = "select distinct(city) from maine_hotels where city <> '' and state = 'Maine' and type = 'Vacation Rental' order by city "; $result = mysql_query($query, $link); while ($row = mysql_fetch_assoc($result)) { extract($row); echo "<option value = '$city'"; if ($city == $gcity) echo " selected "; echo ">$city</option>\n" ; } ?> </select> <input type="button" name="campcitychange" id="campcitychange" value="Go" /> <?php echo '<hr />'; ?> <?php mysql_data_seek($result, 0);//go back to first records while ($row = mysql_fetch_assoc($result)) { extract($row); ... Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/#findComment-845786 Share on other sites More sharing options...
MadTechie Posted May 30, 2009 Share Posted May 30, 2009 I have no idea what you mean! Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/#findComment-845787 Share on other sites More sharing options...
gckmac Posted May 30, 2009 Author Share Posted May 30, 2009 I tried to send you a PM with my AIM and Skype address. If you can help, great. Thx, gckmac Quote Link to comment https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/#findComment-845791 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.