Jump to content

Resettting PHP Database Inquiry?


gckmac

Recommended Posts

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!

 

 

Link to comment
https://forums.phpfreaks.com/topic/160266-resettting-php-database-inquiry/
Share on other sites

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

 

 

 

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);

...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.