PDA

View Full Version : image only next page - SOLVED



Vidman
06-23-2004, 01:52 PM
I'm having a problem with the listing_browse.php page. When I do a search with image only the first page opens fine, but when I go to the next page I get a (Your search returned no results) error.

The first page url.
listing_browse.php?price-min=&price-max=&imagesOnly=yes&type%5B%5D=Rental

The next page url, missing an "&" between rental and images.
listing_browse.php?cur_page=1&&type[]=RentalimagesOnly=yes&

If I put the "&" in, the url works. I've tried other listings on this topic and the solutions did not work. Please help.

main.php

function next_prev($num_rows, $cur_page, $guidestring)
{ // handles multiple page listings
global $lang, $config, $style;

if ($cur_page == "")
{
$cur_page = 0;
}
$page_num = $cur_page + 1;
$total_num_page = ceil($num_rows/$config[listings_per_page]);
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"$style&#91;admin_table_width&#93;\"><TR><TD align=left>";
if &#40;$num_rows == 1&#41;
&#123;
echo "$lang&#91;there_is_currently&#93; <B>$num_rows</b> $lang&#91;listing&#93;.<BR>";
&#125;
else
&#123;
echo "$lang&#91;there_are_currently&#93; <B>$num_rows</b> $lang&#91;listings&#93; $lang&#91;that_match_search&#93;.<BR>";
&#125;
echo "<Center>";
if &#40;$total_num_page != 0&#41;
&#123;
echo "$lang&#91;this_is_page&#93; $page_num $lang&#91;of&#93; $total_num_page<BR>";
$prevpage = $cur_page-1;
$nextpage = $cur_page+1;
if &#40;$page_num != 1&#41; // previous page
&#123;
echo "<a href=\"$PHP_SELF?cur_page=$prevpage&amp;$guidestring\">$lang&#91;prev_page&#93;</a> ";
&#125; // end if
if &#40;$total_num_page > 2&#41;
&#123;
if &#40;$page_num != 1&#41;
&#123;
echo " | ";
&#125;
echo "Page&#58; ";
if&#40; $total_num_page > 8 &#41;
&#123;
// list first three
for&#40;$i = 1; $i < 4; $i++&#41;
&#123;
if &#40;$i == $cur_page + 1&#41;
&#123;
echo "<b><a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a></b>";
&#125;
else
&#123;
echo "<a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a>";
&#125;
if&#40; $i < 3&#41;
&#123;
echo ", ";
&#125;
else
&#123;
echo "... ";
&#125;
&#125; // end for&#40;$i = 1; $i < $init_page_max + 1; $i++&#41;

// list current +/- 1 OR the middle ones, depending
if &#40;$cur_page < 3 OR $cur_page > &#40;$total_num_page - 4&#41;&#41;
&#123;
// list the middle ones
$middle_page = &#40;$num_rows/$config&#91;listings_per_page&#93;&#41;;
$middle_page = ceil&#40;$middle_page/2&#41;;
for&#40;$i = $middle_page - 1; $i <$middle_page + 2; $i++&#41;
&#123;
if &#40;$i == $cur_page + 1&#41;
&#123;
echo "<b><a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a></b>";
&#125;
else
&#123;
echo "<a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a>";
&#125;
if&#40;$i < $middle_page + 1&#41;
&#123;
echo ", ";
&#125;
else
&#123;
echo "... ";
&#125;
&#125; // end for&#40;$i = 1; $i < $init_page_max + 1; $i++&#41;
&#125; // end if &#40;$cur_page < 4 OR $cur_page > $total_num_page - 2&#41;
else
&#123;
// list the immediately surrounding numbers

// gotta make sure you have the numbers correct
if &#40;$cur_page == 3&#41;
&#123;
$start_page = 4;
&#125;
elseif &#40;$cur_page == $total_num_page - 4&#41;
&#123;
$start_page = $total_num_page - 5;
&#125;
else
&#123;
$start_page = $cur_page;
&#125;
for&#40;$i = $start_page; $i < $start_page + 3; $i++&#41;
&#123;

if &#40;$i == $cur_page + 1&#41;
&#123;
echo "<b><a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a></b>";
&#125;
else
&#123;
echo "<a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a>";
&#125;
if&#40;$i < $start_page + 2&#41;
&#123;
echo ", ";
&#125;
else
&#123;
echo "... ";
&#125;
&#125; // end for&#40;$i = $cur_page - 1; $i < $cur_page + 2; $i++&#41;
&#125; // end else

// list last three
for&#40;$i = $total_num_page - 2; $i < $total_num_page + 1; $i++&#41;
&#123;
if &#40;$i == $cur_page + 1&#41; &#123;echo "<b><a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a></b>";&#125;
else &#123;echo "<a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a>";&#125;
if&#40;$i < $total_num_page&#41; &#123;echo ", ";&#125;
&#125; // end for&#40;$i = 1; $i < $init_page_max + 1; $i++&#41;
&#125; // end if&#40; $total_pages > 8 &#41;
else
&#123;
for&#40;$i = 1; $i < $total_num_page + 1; $i++&#41;
&#123;
if &#40;$i == $cur_page + 1&#41;
&#123;
echo "<b><a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a></b>";
&#125;
else
&#123;
echo "<a href=\"$PHP_SELF?cur_page=".&#40;$i-1&#41;."&amp;$guidestring\">$i</a>";
&#125;
if&#40; $i < $total_num_page&#41;
&#123;
echo ", ";
&#125;
&#125; // end for&#40;$i = 1; $i < $init_page_max + 1; $i++&#41;
&#125; // end else
if &#40;$page_num != $total_num_page&#41;
&#123;
echo " | ";
&#125;
&#125;
if &#40;$page_num != $total_num_page&#41; // next page
&#123;
echo " <a href=\"$PHP_SELF?cur_page=$nextpage&amp;$guidestring\">$lang&#91;next_page&#93;</a> ";
&#125; // end if
&#125; // end if
echo "</center></td></tr></table>";
&#125; // end function next_prev

listing_browse.php

<?php include&#40;"include/common.php"&#41;;
include&#40;"$config&#91;template_path&#93;/user_top.html"&#41;;
?>
<table width="494" cellspacing="0" border="0">
<!--DWLayoutTable-->
<tr>
<td width="492" height="30" valign="top"><img src="images/rental.gif" width="492" height="28"></td>
</tr>
</table>
<?php
global $conn, $lang, $config, $HTTP_GET_VARS;
$debug_GET = True;
$guidestring = "";
$guidestring_with_sort = "";
// Save GET
foreach &#40;$_GET as $k => $v&#41;
&#123;
if &#40;$v &amp;&amp; $k != 'cur_page' &amp;&amp; $k != 'PHPSESSID' &amp;&amp; $k != 'sortby' &amp;&amp; $k != 'sorttype' &amp;&amp; $k != 'imagesOnly'&#41;
&#123;
if &#40;is_array&#40;$v&#41;&#41;
&#123;
foreach &#40;$v as $vitem&#41;
&#123;
$guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '&#91;&#93;=' . urlencode&#40;"$vitem"&#41;;
&#125;
&#125;
else
&#123;
$guidestring .= '&amp;amp;' . urlencode&#40;"$k"&#41; . '=' . urlencode&#40;"$v"&#41;;
&#125;
&#125;
&#125;

// START BY SETTING UP THE TABLE OF ALL POSSIBLE LISTINGS
// while this may seem crazy at first, it actually is reasonably efficient, especially
// considering the limitations of mysql and the lack of subqueries.
// basically, it works by the process of elimination...

$sql = "drop table IF EXISTS " . $config&#91;table_prefix&#93; . "temp";
$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;
$sql = "CREATE TABLE " . $config&#91;table_prefix&#93; . "temp SELECT " . $config&#91;table_prefix&#93; . "listingsDB.ID, " . $config&#91;table_prefix&#93; . "listingsDB.Title, " . $config&#91;table_prefix&#93; . "listingsDB.user_ID, " . $config&#91;table_prefix&#93; . "listingsDBElements.field_name, " . $config&#91;table_prefix&#93; . "listingsDBElements.field_value FROM " . $config&#91;table_prefix&#93; . "listingsDB, " . $config&#91;table_prefix&#93; . "listingsDBElements WHERE &#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.listing_id = " . $config&#91;table_prefix&#93; . "listingsDB.ID&#41; AND ";
if &#40;$config&#91;use_expiration&#93; == "yes"&#41;
&#123;
$sql .= "&#40;" . $config&#91;table_prefix&#93; . "listingsDB.expiration > ".$conn->DBDate&#40;time&#40;&#41;&#41;."&#41; AND ";
&#125;
$sql .= "&#40;" . $config&#91;table_prefix&#93; . "listingsDB.active = 'yes'&#41;";

$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;
// Create Index on temporary table to speed up searching
if &#40;$config&#91;manage_index_permissions&#93; == 'Yes'&#41;
&#123;
//Host Supports Creating Indexes, so create some to speed up searching.
$sql = "create index idx_listingid on " . $config&#91;table_prefix&#93; . "temp &#40;ID&#41;";
$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;
$sql = "create index idx_listingname on " . $config&#91;table_prefix&#93; . "temp &#40;field_name&#40;10&#41;&#41;";
$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;
&#125;
reset &#40;$HTTP_GET_VARS&#41;;
foreach &#40;$_GET as $ElementIndexValue => $ElementContents&#41; &#123;
if &#40;$ElementIndexValue == "sortby"&#41;
&#123;
$guidestring_with_sort = "$ElementIndexValue=$ElementContents";
&#125;
elseif &#40;$ElementIndexValue == "sorttype"&#41;
&#123;
$guidestring_with_sort = "$ElementIndexValue=$ElementContents&amp;amp;";
&#125;
elseif &#40;$ElementIndexValue == "cur_page"&#41;
&#123;
// do nothing
&#125;
elseif &#40;$ElementIndexValue == "PHPSESSID"&#41;
&#123;
// do nothing
&#125;
elseif &#40;$ElementIndexValue == "user_ID"&#41;
&#123;
$sql = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp WHERE User_ID <> $ElementContents";
$recordSet = $conn->Execute&#40;$sql&#41;;

&#125;
elseif &#40;$ElementIndexValue == "imagesOnly"&#41;
&#123;
$guidestring .= "$ElementIndexValue=$ElementContents&amp;amp;";
if &#40;$ElementContents == "yes"&#41;
&#123;
$whilecount = 0;
$delete_string = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp WHERE &#40;1=1&#41;";
// the 1=1 is a dumb sql trick to deal with the code below ... it works, but you can ignore it
$sql = "SELECT " . $config&#91;table_prefix&#93; . "temp.ID, COUNT&#40;" . $config&#91;table_prefix&#93; . "listingsImages.file_name&#41; AS imageCount FROM " . $config&#91;table_prefix&#93; . "listingsImages," . $config&#91;table_prefix&#93; . "temp WHERE &#40;" . $config&#91;table_prefix&#93; . "listingsImages.listing_id = " . $config&#91;table_prefix&#93; . "temp.ID&#41; GROUP BY " . $config&#91;table_prefix&#93; . "listingsImages.listing_id";
$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;
while &#40;!$recordSet->EOF&#41;
&#123;
$whilecount = $whilecount + 1;
$listingID = $recordSet->fields&#91;ID&#93;;
$imageCount = $recordSet->fields&#91;imageCount&#93;;
$delete_string .= " AND ";
$delete_string .= "&#40;ID <> $listingID&#41;";
$recordSet->MoveNext&#40;&#41;;
&#125; // end while
$recordSet = $conn->Execute&#40;$delete_string&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$delete_string&#41;;
&#125;
&#125;

&#125; // end elseif &#40;$ElementIndexValue == "imagesOnly"&#41;
elseif &#40;is_array&#40;$ElementContents&#41;&#41;
&#123;
//echo $ElementIndexValue.'&#58; array found<br>';
//echo count&#40;$ElementContents&#41;.'Elements found in array<br>';
$skip = False;
foreach&#40;$ElementContents as $a&#41;
&#123;
if &#40;!$a&#41;
&#123;
$skip = True;
&#125;
//echo '|'.$a.'|';
&#125;
if &#40;$skip == True&#41;
&#123;
continue;
&#125;

reset&#40;$ElementContents&#41;;
echo '<br><br>';
$sql_ElementIndexValue = make_db_safe&#40;$ElementIndexValue&#41;;

// Arrays can happen for two reasons&#58; 1. multi options like zip code
// 2. multi options like home features. Check the db to see which
// type of field this is and process accordingly
$r = $conn->getOne&#40;"select search_type from " . $config&#91;table_prefix&#93; . "listingsFormElements where field_name = ".$sql_ElementIndexValue&#41;;
if &#40;&#40;$r == 'optionlist'&#41; || &#40;$r == 'fcheckbox'&#41;&#41;
&#123;
$recordSet = $conn->Execute&#40;$sql&#41;;
// Delete all records that don't have any field name by this name
$sql = "select count&#40;t2.field_name&#41; as cnt, t1.id as id from " . $config&#91;table_prefix&#93; . "temp t1 left join " . $config&#91;table_prefix&#93; . "listingsDBElements t2 on t1.id = t2.listing_id and t1.field_name = $sql_ElementIndexValue group by t1.id";
//$sql = " select count&#40;t2.field_name&#41; as cnt, t1.id as id from " . $config&#91;table_prefix&#93; . "temp2 t1 left join " . $config&#91;table_prefix&#93; . "listingsDBElements t2 on t1.id = t2.listing_id group by t1.id";
$res = $conn->Execute&#40;$sql&#41;;
while &#40;!$res->EOF&#41;
&#123;
// Check for no field
if &#40;$res->fields&#91;'cnt'&#93; == 0&#41;
&#123;
$conn->execute&#40;"delete from " . $config&#91;table_prefix&#93; . "temp where id = " . $res->fields&#91;'id'&#93;&#41;;
&#125;
else
&#123;
// for each value, delete those records that don't match it
$value = $conn->getOne&#40;"select field_value from " . $config&#91;table_prefix&#93; . "temp where id = " . $res->fields&#91;'id'&#93; . " and field_name = $sql_ElementIndexValue"&#41;;
$delete = 1;

foreach &#40;$ElementContents as $e&#41;
&#123;
if &#40;!strstr&#40;$value, $e&#41;&#41;
&#123;
$conn->execute&#40;"delete from " . $config&#91;table_prefix&#93; . "temp where id = " . $res->fields&#91;'id'&#93;&#41;;
&#125;
&#125;
&#125;
$res->moveNext&#40;&#41;;
&#125;
&#125;
else
&#123;
// first, we need to see if there's anything that'll meet the criteria
$whilecountTwo = 0;
$select_statement = "SELECT ID FROM " . $config&#91;table_prefix&#93; . "temp WHERE &#40; &#40;field_name=$sql_ElementIndexValue&#41; AND ";
while &#40;list&#40;$featureValue, $feature_item&#41; = each &#40;$ElementContents&#41;&#41;
&#123;
//$guidestring .= "&amp;amp;".&#40;$ElementIndexValue&#41;."%5B%5D=".urlencode&#40;$feature_item&#41;."&amp;amp;";
//$guidestring .= urlencode&#40;$featureValue&#41;."%5B%5D=".urlencode&#40;$feature_item&#41;."&amp;";
$whilecountTwo = $whilecountTwo + 1;
if &#40;$whilecountTwo > 1&#41;
&#123;
$select_statement .= " OR ";
&#125;
$sql_feature_item = make_db_safe&#40;$feature_item&#41;;
$select_statement .= "&#40;field_value = $sql_feature_item&#41;";
&#125;
$select_statement .= "&#41;";
$recordSet = $conn->Execute&#40;$select_statement&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$select_statement&#41;;
&#125;
$save_array = array&#40;&#41;;
while &#40;!$recordSet->EOF&#41;
&#123;
$save_ID = $recordSet->fields&#91;ID&#93;;
$save_array&#91;&#93; = "$save_ID";
$recordSet->MoveNext&#40;&#41;;
&#125; // end while
$num_to_delete = $recordSet->RecordCount&#40;&#41;;

// now, delete everything that we don't want...
if &#40;$num_to_delete > 0&#41;
&#123;
$delete_string = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp WHERE ";
while &#40;list&#40;$IndexValue,$ElementContents&#41; = each&#40;$save_array&#41;&#41;
&#123;
if &#40;$IndexValue > 0&#41;
&#123;
$delete_string .= " AND ";
&#125;
$sql_ElementContents = make_db_safe&#40;$ElementContents&#41;;
$delete_string .= "&#40;ID <> $sql_ElementContents&#41;";
&#125; // end while


$recordSet = $conn->Execute&#40;$delete_string&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$delete_string&#41;;
&#125;
&#125; // &#40;$num_to_delete > 0&#41;
// if there's nothing that matches, delete all the other possibilities...
elseif &#40;$num_to_delete == 0&#41;
&#123;
$delete_string = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp";
$recordSet = $conn->Execute&#40;$delete_string&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$delete_string&#41;;
&#125;
&#125; // end elseif &#40;$num_to_delete = 0&#41;
&#125; // end optionlist check
&#125; // end elseif &#40;is_array&#40;$ElementContents&#41;&#41;
else
&#123;
// Don't process empty searches
if &#40;!$ElementContents&#41; continue;

$val = $ElementContents;
$ElementContents = make_db_safe&#40;$ElementContents&#41;;
// Check for min/max values
$l3 = substr&#40;$ElementIndexValue, strlen&#40;$ElementIndexValue&#41; - 3&#41;;
if &#40;$l3 == 'min' OR $l3 == 'max'&#41;
&#123;
$col = strtok&#40;$ElementIndexValue, '-'&#41;;
// Because mysql 3.x doesn't have cast&#40;&#41;, we must retrieve all records then filter - yuck
$sql = "select id, field_value as v from " . $config&#91;table_prefix&#93; . "temp where field_name = '$col'";
$rs = $conn->Execute&#40;$sql&#41;;
$del_id = array&#40;&#41;;
while &#40;!$rs->EOF&#41; &#123;
if &#40;$l3 == 'min' AND $val&#41;
&#123;
if &#40;$rs->fields&#91;'v'&#93; < $val&#41;
&#123;
$del_id&#91;&#93; = $rs->fields&#91;'id'&#93;;
&#125;
&#125;
if &#40;$l3 == 'max' AND $val&#41;
&#123;
if &#40;$rs->fields&#91;'v'&#93; > $val&#41;
&#123;
$del_id&#91;&#93; = $rs->fields&#91;'id'&#93;;
&#125;
&#125;
$rs->MoveNext&#40;&#41;;
&#125;
$sql = "delete from " . $config&#91;table_prefix&#93; . "temp where id in &#40;" . implode&#40;',', $del_id&#41; . "&#41;";
if &#40;sizeof&#40;$del_id&#41;&#41;
&#123;
$conn->execute&#40;$sql&#41;;
&#125;
continue;
&#125;

// Check for min/max dates
$l7 = substr&#40;$ElementIndexValue, strlen&#40;$ElementIndexValue&#41; - 7&#41;;
if &#40;$l7 == 'mindate' OR $l7 == 'maxdate'&#41;
&#123;
if &#40;&#40;$time = strtotime&#40;$val&#41;&#41; > 1&#41;
&#123;
$col = strtok&#40;$ElementIndexValue, '-'&#41;;
// Because mysql 3.x doesn't have cast&#40;&#41;, we must retrieve all records then filter - yuck
$sql = "select id, field_value as v from " . $config&#91;table_prefix&#93; . "temp where field_name = '$col'";
$rs = $conn->Execute&#40;$sql&#41;;
$del_id = array&#40;&#41;;
while &#40;!$rs->EOF&#41;
&#123;
$db_time = strtotime&#40;$rs->fields&#91;'v'&#93;&#41;;
if &#40;$l7 == 'mindate' AND $val&#41;
&#123;
if &#40;$db_time < $time&#41;
&#123;
$del_id&#91;&#93; = $rs->fields&#91;'id'&#93;;
&#125;
&#125;
if &#40;$l7 == 'maxdate' AND $val&#41;
&#123;
if &#40;$db_time > $time&#41;
&#123;
$del_id&#91;&#93; = $rs->fields&#91;'id'&#93;;
&#125;
&#125;
if &#40;$db_time < 1 or !$val&#41;
&#123;
$del_id&#91;&#93; = $rs->fields&#91;'id'&#93;;
&#125;
$rs->MoveNext&#40;&#41;;
&#125;
$sql = "delete from " . $config&#91;table_prefix&#93; . "temp where id in &#40;" . implode&#40;',', $del_id&#41; . "&#41;";
if &#40;sizeof&#40;$del_id&#41;&#41;
&#123;
$conn->execute&#40;$sql&#41;;
&#125;
continue;
&#125;
&#125;

if &#40;!$ElementContents&#41; continue;
$ElementIndexValue = make_db_safe&#40;$ElementIndexValue&#41;;
$select_statement = "SELECT ID FROM " . $config&#91;table_prefix&#93; . "temp WHERE &#40; &#40;field_name = $ElementIndexValue&#41; AND &#40;field_value = $ElementContents&#41; &#41;";
$recordSet = $conn->Execute&#40;$select_statement&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$select_statement&#41;;
&#125;
$save_array = array&#40;&#41;;
while &#40;!$recordSet->EOF&#41;
&#123;
$save_ID = $recordSet->fields&#91;ID&#93;;
$save_array&#91;&#93; = "$save_ID";
$recordSet->MoveNext&#40;&#41;;
&#125; // end while
$num_to_delete = $recordSet->RecordCount&#40;&#41;;
if &#40;$num_to_delete > 0&#41;
&#123;
$delete_string = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp WHERE ";
while &#40;list&#40;$IndexValue,$ElementContents&#41; = each&#40;$save_array&#41;&#41;
&#123;
if &#40;$IndexValue > 0&#41;
&#123;
$delete_string .= " AND ";
&#125;
$delete_string .= "&#40;ID <> $ElementContents&#41;";
&#125;
$recordSet = $conn->Execute&#40;$delete_string&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$delete_string&#41;;
&#125;
&#125; // end &#40;$num_to_delete > 0&#41;
elseif &#40;$num_to_delete == 0&#41;
&#123;
$delete_string = "DELETE FROM " . $config&#91;table_prefix&#93; . "temp";
$recordSet = $conn->Execute&#40;$delete_string&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$delete_string&#41;;
&#125;
&#125; // end elseif &#40;$num_to_delete = 0&#41;

&#125; // end else
&#125; // end while


// this is the main SQL that grabs the listings
// basic sort by title..
if &#40;$sortby == ""&#41;
&#123;
$sort_text = "";
$order_text = "ORDER BY ID DESC";
&#125;
elseif &#40;$sortby == "listingname"&#41;
&#123;
$sort_text = "";
$order_text = "ORDER BY Title $sorttype";
&#125;
// BEGIN NEW CODE
elseif &#40;$sortby == "price"&#41;
&#123;
$sortby = make_db_extra_safe&#40;$sortby&#41;;
$sort_text = "WHERE &#40;field_name = $sortby&#41;";
$order_text = "ORDER BY field_value +0 $sorttype";
&#125;
// END NEW CODE
else
&#123;
$sortby = make_db_extra_safe&#40;$sortby&#41;;
$sort_text = "WHERE &#40;field_name = $sortby&#41;";
$order_text = "ORDER BY field_value $sorttype";
&#125;
if &#40;&#40;$sorttype == ""&#41; || &#40;$sorttype == "ASC"&#41;&#41;
&#123;
$sorttype = "DESC";
&#125;
else
&#123;
$sorttype = "ASC";
&#125;

$guidestring_with_sort = $guidestring_with_sort.$guidestring;

$sql = "SELECT * from " . $config&#91;table_prefix&#93; . "temp $sort_text GROUP BY ID $order_text";
$recordSet = $conn->Execute&#40;$sql&#41;;
if &#40;$recordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;

$num_rows = $recordSet->RecordCount&#40;&#41;;
if &#40;$num_rows > 0&#41;
&#123;
echo "<BR>";
next_prev&#40;$num_rows, $cur_page, $guidestring_with_sort&#41;; // put in the next/previous stuff

// build the string to select a certain number of listings per page
$limit_str = $cur_page * $config&#91;listings_per_page&#93;;
$resultRecordSet = $conn->SelectLimit&#40;$sql, $config&#91;listings_per_page&#93;, $limit_str &#41;;
if &#40;$resultRecordSet === false&#41;
&#123;
log_error&#40;$sql&#41;;
&#125;

?>

<table border="<?php echo $style&#91;form_border&#93; ?>" cellspacing="<?php echo $style&#91;form_cellspacing&#93; ?>" cellpadding="<?php echo $style&#91;form_cellpadding&#93; ?>" width="<?php echo $style&#91;admin_table_width&#93; ?>" class="form_main" align="center">
<tr>
<?php
if &#40;&#40;$sortby == "listingname"&#41; ||&#40;$sortby == ""&#41;&#41;
&#123;
$sorttypestring = "sorttype=$sorttype&amp;amp;";
&#125;
?>

<?php
// grab browsable fields
$sql = "SELECT field_caption, field_name FROM " . $config&#91;table_prefix&#93; . "listingsFormElements WHERE &#40;display_on_browse = 'Yes'&#41; AND &#40;field_type <> 'textarea'&#41; ORDER BY rank";
$recordSet = $conn->Execute&#40;$sql&#41;;
$num_columns = $recordSet->RecordCount&#40;&#41;;
// Add Title as a search link
$field_caption = "Title";
$field_name = "listingname";
if &#40;$sortby != $field_name&#41;
&#123;
$sorttypestring = "";
&#125;
else
&#123;
$sorttypestring = "sorttype=$sorttype&amp;amp;";
&#125;
echo "<td align=\"center\"><b><a href=\"$PHP_SELF?sortby=$field_name&amp;amp;$sorttypestring$g uidestring\">$field_caption</a></b></td>";

while &#40;!$recordSet->EOF&#41;
&#123;
$field_caption = make_db_unsafe &#40;$recordSet->fields&#91;field_caption&#93;&#41;;
$field_name = make_db_unsafe &#40;$recordSet->fields&#91;field_name&#93;&#41;;
if &#40;$sortby != "'$field_name'"&#41;
&#123;
$sorttypestring = "";
&#125;
else
&#123;
$sorttypestring = "sorttype=$sorttype&amp;amp;";
&#125;
echo "<td align=\"center\"><b><a href=\"$PHP_SELF?sortby=$field_name&amp;amp;$sorttypestring$g uidestring\">$field_caption</a></b></td>";
$recordSet->MoveNext&#40;&#41;;
&#125; // end while
$num_columns = $num_columns + 1; // add one for the image
?>
</tr>
<tr>
<td colspan="<?php echo $num_columns ?>">
<hr>
</td>
</tr>

<?php
$count = 0;
while &#40;!$resultRecordSet->EOF&#41;
&#123;
// alternate the colors
if &#40;$count == 0&#41;
&#123;
$count = $count +1;
&#125;
else
&#123;
$count = 0;
&#125;

$Title = make_db_unsafe &#40;$resultRecordSet->fields&#91;Title&#93;&#41;;
$current_ID = $resultRecordSet->fields&#91;ID&#93;;
echo "<tr><td align=\"left\" class=\"search_row_$count\" colspan=\"$num_columns\"><b><a href=\"listingview.php?listingID=$current_ID\">$Title</a></b></td></tr>";
echo "<tr>";

// grab the listing's image
$sql2 = "SELECT thumb_file_name FROM " . $config&#91;table_prefix&#93; . "listingsImages WHERE listing_id = $current_ID ORDER BY rank";
$recordSet2 = $conn->SelectLimit&#40;$sql2, 1, 0&#41;;
if &#40;$recordSet2 === false&#41;
&#123;
log_error&#40;$sql2&#41;;
&#125;
$num_images = $recordSet2->RecordCount&#40;&#41;;
if &#40;$num_images == 0&#41;
&#123;
if &#40;$config&#91;show_no_photo&#93; == "yes"&#41;
&#123;
//echo "<td class=\"search_row_$count\" align=\"center\"><img src=\"images/nophoto.gif\" border=\"1\" alt=\"no photo\"></td>";
echo "<td class=\"search_row_$count\" align=\"center\"><a href=\"listingview.php?listingID=$current_ID\"><img src=\"images/nophoto.gif\" border=\"1\" alt=\"no photo\"></a></td>";
&#125;
else
&#123;
echo "<td class=\"search_row_$count\">&amp;nbsp;</td>";
&#125;
&#125;
while &#40;!$recordSet2->EOF&#41;
&#123;
$thumb_file_name = make_db_unsafe &#40;$recordSet2->fields&#91;thumb_file_name&#93;&#41;;
if &#40;$thumb_file_name != ""&#41;
&#123;
// gotta grab the image size
$imagedata = GetImageSize&#40;"$config&#91;listings_upload_path&#93;/$thumb_file_name"&#41;;
$imagewidth = $imagedata&#91;0&#93;;
$imageheight = $imagedata&#91;1&#93;;
$shrinkage = $config&#91;thumbnail_width&#93;/$imagewidth;
$displaywidth = $imagewidth * $shrinkage;
$displayheight = $imageheight * $shrinkage;
echo "<td class=\"search_row_$count\" align=\"center\"><a href=\"listingview.php?listingID=$current_ID\">";
echo "<img src=\"$config&#91;listings_view_images_path&#93;/$thumb_file_name\" height=\"$displayheight\" width=\"$displaywidth\" alt=\"$thumb_file_name\" border=\"0\"></a></td>";
&#125; // end if &#40;$thumb_file_name != ""&#41;
$recordSet2->MoveNext&#40;&#41;;
&#125; // end while

// grab the rest of the listing's data
$sql2 = "SELECT " . $config&#91;table_prefix&#93; . "listingsDBElements.field_value, " . $config&#91;table_prefix&#93; . "listingsFormElements.field_type FROM " . $config&#91;table_prefix&#93; . "listingsDBElements, " . $config&#91;table_prefix&#93; . "listingsFormElements WHERE &#40;&#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.listing_id = $current_ID&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsFormElements.display_on_browse = 'Yes'&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsFormElements.field_type <> 'textarea'&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.field_name = " . $config&#91;table_prefix&#93; . "listingsFormElements.field_name&#41;&#41; ORDER BY " . $config&#91;table_prefix&#93; . "listingsFormElements.rank";
$recordSet2 = $conn->Execute&#40;$sql2&#41;;
if &#40;$recordSet2 === false&#41;
&#123;
log_error&#40;$sql2&#41;;
&#125;
while &#40;!$recordSet2->EOF&#41;
&#123;
$field_value = make_db_unsafe &#40;$recordSet2->fields&#91;field_value&#93;&#41;;
$field_type = make_db_unsafe &#40;$recordSet2->fields&#91;field_type&#93;&#41;;
echo "<td align=\"center\" class=\"search_row_$count\">";

if &#40;$field_type == "select-multiple" OR $field_type == "option" OR $field_type == "checkbox"&#41;
&#123;
// handle field types with multiple options

$feature_index_list = explode&#40;"||", $field_value&#41;;
while &#40;list&#40;$feature_list_Value, $feature_list_item&#41; = each &#40;$feature_index_list&#41;&#41;
&#123;
echo "$feature_list_item<br>";
&#125; // end while
&#125; // end if field type is a multiple type

elseif &#40;$field_type == "price"&#41;
&#123;
//$field_value = ereg_replace&#40;'&#91;^0-9&#93;', '', $field_value&#41;;
//echo "$config&#91;money_sign&#93;".number_format&#40;$field_value, 2, '.', ','&#41;;
$sql3 = "SELECT " . $config&#91;table_prefix&#93; . "listingsDBElements.field_value FROM " . $config&#91;table_prefix&#93; . "listingsDBElements, " . $config&#91;table_prefix&#93; . "listingsFormElements WHERE &#40;&#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.listing_id = $current_ID&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsFormElements.field_type <> 'textarea'&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.field_name = " . $config&#91;table_prefix&#93; . "listingsFormElements.field_name&#41;&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.field_name = 'status'&#41; ORDER BY " . $config&#91;table_prefix&#93; . "listingsFormElements.rank";
$recordSet3 = $conn->Execute&#40;$sql3&#41;;
if &#40;$recordSet3 === false&#41;
&#123;
log_error&#40;$sql3&#41;;
&#125;
$status = make_db_unsafe &#40;$recordSet3->fields&#91;field_value&#93;&#41;;
$recordSet3->Close&#40;&#41;;
$money_amount = international_num_format&#40;$field_value&#41;;
if &#40;$status == 'Sold'&#41;
&#123;
echo "<s>";
echo money_formats&#40;$money_amount&#41;;
echo "</s><br><span style=\"color&#58;red;\"><b>SOLD</b></span>";
&#125;
elseif &#40;$status == 'Pending'&#41;
&#123;
echo money_formats&#40;$money_amount&#41;;
echo "<br><span style=\"color&#58;green;\"><b>PENDING</b></span>";
&#125;
else
&#123;
echo money_formats&#40;$money_amount&#41;;
&#125;
&#125; // end elseif
elseif &#40;$field_type == "number"&#41;
&#123;
echo international_num_format&#40;$field_value&#41;;
&#125; // end elseif
elseif &#40;$field_type == "url"&#41;
&#123;
echo "<a href=\"$field_value\" target=\"_new\">$field_value</a>";
&#125;
elseif &#40;$field_type == "email"&#41;
&#123;
echo "<a href=\"mailto&#58;$field_value\">$field_value</a>";
&#125;
else
&#123;
echo "$field_value";
&#125; // end else

echo "</td>";
$recordSet2->MoveNext&#40;&#41;;
&#125; // end while


echo "</tr>";
// deal with text areas, like descriptions
$sql2 = "SELECT " . $config&#91;table_prefix&#93; . "listingsDBElements.field_value, " . $config&#91;table_prefix&#93; . "listingsFormElements.field_type FROM " . $config&#91;table_prefix&#93; . "listingsDBElements, " . $config&#91;table_prefix&#93; . "listingsFormElements WHERE &#40;&#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.listing_id = $current_ID&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsFormElements.display_on_browse = 'Yes'&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsFormElements.field_type = 'textarea'&#41; AND &#40;" . $config&#91;table_prefix&#93; . "listingsDBElements.field_name = " . $config&#91;table_prefix&#93; . "listingsFormElements.field_name&#41;&#41; ORDER BY " . $config&#91;table_prefix&#93; . "listingsFormElements.rank";
$recordSet2 = $conn->Execute&#40;$sql2&#41;;
if &#40;$recordSet2 === false&#41;
&#123;
log_error&#40;$sql2&#41;;
&#125;
while &#40;!$recordSet2->EOF&#41;
&#123;
$field_value = make_db_unsafe &#40;$recordSet2->fields&#91;field_value&#93;&#41;;
$field_caption = make_db_unsafe &#40;$recordSet2->fields&#91;field_caption&#93;&#41;;
echo "<tr><td colspan=\"$num_columns\" class=\"search_row_$count\">$field_value</td></tr>";
$recordSet2->MoveNext&#40;&#41;;
&#125; // end while


$resultRecordSet->MoveNext&#40;&#41;;
&#125; // end while


?>


</table>

<?php
&#125; // end if &#40;$num_rows > 0&#41;
else
&#123;
echo "<p>$lang&#91;search_no_results&#93;</p>";
&#125;


include&#40;"$config&#91;template_path&#93;/user_bottom.html"&#41;;
?>

greengiant
06-24-2004, 09:32 AM
Find this line in the listing_browse.php file. (line 99)


$guidestring .= "$ElementIndexValue=$ElementContents&amp;amp;";

change it to


$guidestring .= "&amp;amp;$ElementIndexValue=$ElementContents&amp;amp;";

Vidman
06-24-2004, 11:27 AM
That was it. Thank you.