Variables outside the function in function
Posted: Tue Aug 22, 2006 8:17 pm
Hi,
I am making a simple search result page and for some reason, I am having a day long brainfart and I need some help as to why my code isn't working at all. I want first to retrieve the results using a query, and then count them. Then, by setting the variable $display_limit to 20, I want to make it so that only 20 results are shown, and then a link to the next page with the next 20. Next I want to order the results in order of their package number, set in a different table than the one that contains the search results. The two tables are linked by two different id's, labeled PROP_ID ($prop_id) and REGISTRATION_ID ($id, same as $user_id). For some reason I cannot figure out how to do this easily because once I break it down, I realize that the one thing that will make it work will change everything. If you need any more explination as to how it is supposed to work, just ask. Here is the code that contains the function, and any other stuff:
I am making a simple search result page and for some reason, I am having a day long brainfart and I need some help as to why my code isn't working at all. I want first to retrieve the results using a query, and then count them. Then, by setting the variable $display_limit to 20, I want to make it so that only 20 results are shown, and then a link to the next page with the next 20. Next I want to order the results in order of their package number, set in a different table than the one that contains the search results. The two tables are linked by two different id's, labeled PROP_ID ($prop_id) and REGISTRATION_ID ($id, same as $user_id). For some reason I cannot figure out how to do this easily because once I break it down, I realize that the one thing that will make it work will change everything. If you need any more explination as to how it is supposed to work, just ask. Here is the code that contains the function, and any other stuff:
Code: Select all
<?php
if ($_SESSION['PAGE_NAME'] == "searchpage.php") {
$query2 = "SELECT * FROM prop_info WHERE CONTINENTS='North America' AND COUNTRY='United States' AND STATE='$statefull' AND DISPLAY='yes'";
} else {
$query2 = "SELECT * FROM prop_info WHERE CONTINENTS='$con_name' AND COUNTRY='$country_name' $aa AND DISPLAY='yes'";
}
$result2 = mysql_query($query2);
$display_limit = '20';
$items_count = mysql_num_rows($result2);
if(isset($_GET['page_count'])) {
$page_count = $_GET['page_count'];
} else {
if($items_count > $display) {
$page_count = ceil ($items_count/$display_limit);
} else {
$page_count = 1;
}
}
if(isset($_GET['start'])){
$start = $_GET['start'];
} else {
$start = 0;
}
$query = $query2." LIMIT $start,$display_limit";
echo $query;
$result = mysql_query($query);
//------------------- To show Search Result ------------------------------------
function view_property() {
global $query;
$query = $GLOBALS["query"];
$result = mysql_query($query);
$int = 0;
$prop_array = array();
$user_array = array();
while ($rw = mysql_fetch_array($result)) {
$user_array[$int] = $id = $rw[0];
$prop_array[$int] = $prop_id = $rw[17];
$int++;
if ($int != 0) {
$count = count($prop_array);
//=========================== Platinum =================================//
for ($int_1 = 0; $int_1 < $count; $int_1++) {
$query_pay = "SELECT * FROM payment WHERE PROP_ID=$prop_id AND USER_ID=$id AND PAY_STATUS='true' ORDER BY PACKAGE ASC";
$result_pay = mysql_query($query_pay);
while ($rw2 = mysql_fetch_array($result_pay)) {
//$prop_id = $rw[18];
//$id = $rw[0];
$package = $rw2[9];
}
$num_pay = 0;
$query_2 = "SELECT * FROM prop_info WHERE REGISTRATION_ID=$id AND PROP_ID=$prop_id";
$result_2 = mysql_query($query_2);
$int = 0;
while ($row = mysql_fetch_array($result_2)) {
$int++;
$query1 = "SELECT * FROM images_info WHERE REGISTRATION_ID=$id AND PROP_ID=$prop_id";
$result1 = mysql_query($query1);
$a = 0;
while ($row1 = mysql_fetch_array($result1)) {
$a++;
$image_name = $row1[1];
}
if ($a == 0) {
$image_name = "imgnotavailable.jpg";
}
if ($int >= $start && $int <= $display_limit) {
if ($package == "1") {
?>
<tr class="boldrow">
<td width="101" class="first">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name; ?>" width="100" height="63"></a></td>
<td width="111">
<p align="center"><font size="2"><?php echo $row[2]; ?></font></p>
<p align="center"><font size="2">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>">Premium Property Details</a></font></td>
<td width="117">
<p align="center"><font size="2"><?php echo $row[1]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
<td width="55">
<p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
<td width="61" class="last">
<p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
</tr>
<tr>
<td width="100%" height="10" colspan="8">*</td>
</tr>
<?php
//================================== Gold ==================================//
} elseif ($package == "2") {
?>
<tr class="gold">
<td width="101" valign="middle" align="center">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name; ?>" width="100" height="63"></a></td>
<td width="111">
<p align="center"><font size="2"><?php echo $row[2]; ?></font></p>
<p align="center"><font size="2">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>">Gold Property Details</a></font></td>
<td width="117">
<p align="center"><font size="2"><?php echo $row[1]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
<td width="55">
<p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
<td width="61">
<p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
</tr>
<tr>
<td width="100%" height="10" colspan="8">*</td>
</tr>
<?php
//============================== Silver ===================================//
} elseif ($package == "3") {
?>
<tr>
<td width="101">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>"><img border="0" src="photo/<?php echo $image_name; ?>" width="100" height="63"></a></td>
<td width="111">
<p align="center"><font size="2"><?php echo $row[2]; ?></font></p>
<p align="center"><font size="2">
<a href="view_detail_property.php?prop_id=<?php echo $prop_id; ?>&cp=<? echo $c_page;?>">Property Details</a></font></td>
<td width="117">
<p align="center"><font size="2"><?php echo $row[1]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[9]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[10]; ?></font></td>
<td>
<p align="center"><font size="2"><?php echo $row[11]; ?></font></td>
<td width="55">
<p align="center"><font size="2"><?php echo $row[5]; ?></font></td>
<td width="61">
<p align="center"><font size="2"><?php echo $row[7]; ?></font></td>
</tr>
<tr>
<td width="100%" height="10" colspan="8">*</td>
</tr>
<?php
}
}
}
}
}
}
}
//databaseClose();
?>