Main
Index
Search
Posts
Who's
Online
Log
In

Home: Discontinued/Classic Products: Instant Website: Realty/Listings/Auto:
Order Results using dropdown

 

 


Pixels & Beats
User

Nov 26, 2009, 8:07 AM

Post #1 of 10 (16937 views)
Shortcut
Order Results using dropdown Can't Post

Is it possible to order the results using a drop down menu? If so are there any guides on how to do this? I seem unable to find any but it has been a long day Crazy

Thanks! :)


Chris
Staff


Nov 26, 2009, 4:02 PM

Post #2 of 10 (16927 views)
Shortcut
Re: [8bit Gamer] Order Results using dropdown [In reply to] Can't Post

Hi 8bit Gamer,

Anything is possible with a little bit of PHP. First you'll want to create your dropdown, supplying the orderBy strings you want to use as <option value>s. Then, on your search results page, simply pass the selected field into getRecords():


Code
  $orderBy = @$_REQUEST['orderBy']; 
list($productsRecords, $productsMetaData) = getRecords(array(
'tableName' => 'products',
'orderBy' => $orderBy,
));


The code above assumes your <select name="orderBy">. You'll also need to change the names of the variables and the tableName to match how you've got your sections configured.

I hope this helps! Please let me know if you have any questions.
Chris


(This post was edited by chris on Nov 26, 2009, 4:03 PM)


Pixels & Beats
User

Nov 27, 2009, 5:56 AM

Post #3 of 10 (16909 views)
Shortcut
Re: [chris] Order Results using dropdown [In reply to] Can't Post

Hi Chris,

I got the dropdowns working great. However there is one question which I have been asking myself.

Is it possible to 'populate' the drop downs with the content that is available in the database?

The reason I ask is that there are a lot of variables, which also change frequently. To me the logical solution rather than going through and updating the dropdown lists everyday, is to have a self populating list. This also avoids giving the impression to the user that there are 'options' available when really they might not be in the database at that time.

Does this make sense and is it possible?

Many thanks

8bit


(This post was edited by 8bit Gamer on Nov 27, 2009, 5:58 AM)


Chris
Staff


Nov 27, 2009, 11:27 AM

Post #4 of 10 (16884 views)
Shortcut
Re: [8bit Gamer] Order Results using dropdown [In reply to] Can't Post

Hi 8bit Gamer,

You certainly don't want to be updating things by hand!

Can you attach the full PHP source code for the page with the dropdown which you want to have updated?
Chris


Pixels & Beats
User

Nov 30, 2009, 1:40 AM

Post #5 of 10 (16793 views)
Shortcut
Re: [chris] Order Results using dropdown [In reply to] Can't Post

Hi Chris,

Below is the requested code. I have removed non essential elements to keep it simple, but all CMS Admin code that is used should be there! Thanks for helping out :)


<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'adverts',
'perPage' => '12',
'orderBy' => 'PRICE',
));

?>

<span class="sectionheading">Quality Used Bikes</span>
<div class="search">

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">

<span class="newsheading">You can search on specific aspects of the bike you are looking for using the drop down menus below.</span><br /><br />
Make:
<select name="MAKE">
<option value="">All</option>
<option>Triumph</option>
<option>Peugeot</option>
<option>Yamaha</option>
<option>Ducati</option>
<option>Morini</option>
<option>Enfield</option>
<option>BMW</option>
<option>Kawasaki</option>
<option>Piaggio</option>
<option>Aprilia</option>
<option>Honda</option>
<option>MV Agusta</option>
</select>
&nbsp;&nbsp;&nbsp;
Model:
<select name="MODEL">
<option value="">All</option>
<option>Monster</option>
</select>
&nbsp;&nbsp;&nbsp;
Colour:
<select name="COLOUR">
<option value="">All</option>
<option>Multi </option>
<option>Red</option>
<option>Blue</option>
<option>Black</option>
<option>Green</option>
<option>Yellow</option>
<option>Silver</option>
</select>
&nbsp;&nbsp;&nbsp;
Min Price:
<select name="PRICE_min">
<option value="">All</option>
<option value="1000">&pound;1000</option>
<option value="2000">&pound;2000</option>
<option value="3000">&pound;3000</option>
<option value="4000">&pound;4000</option>
<option value="5000">&pound;5000</option>
<option value="6000">&pound;6000</option>
<option value="7000">&pound;7000</option>
<option value="8000">&pound;8000</option>
<option value="9000">&pound;9000</option>
<option value="10000">&pound;10000</option>
</select>
&nbsp;&nbsp;&nbsp;
Max Price:
<select name="PRICE_max">
<option value="">All</option>
<option value="1000">&pound;1000</option>
<option value="2000">&pound;2000</option>
<option value="3000">&pound;3000</option>
<option value="4000">&pound;4000</option>
<option value="5000">&pound;5000</option>
<option value="6000">&pound;6000</option>
<option value="7000">&pound;7000</option>
<option value="8000">&pound;8000</option>
<option value="9000">&pound;9000</option>
<option value="10000">&pound;10000</option>
</select>
&nbsp;&nbsp;&nbsp;
Min CC:
<select name="ENGINECC_min">
<option value="">All</option>
<option value="50">50cc</option>
<option value="125">125cc</option>
<option value="250">600cc</option>
<option value="600">600cc</option>
<option value="1000">1000cc</option>
</select>
&nbsp;&nbsp;&nbsp;
Max CC:
<select name="ENGINECC_max">
<option value="">All</option>
<option value="50">50cc</option>
<option value="125">125cc</option>
<option value="250">600cc</option>
<option value="600">600cc</option>
<option value="1000">1000cc</option>
</select>
&nbsp;&nbsp;&nbsp;
<input type="submit" value="&nbsp;&nbsp;Search&nbsp;&nbsp;" />
</form>
</div>

<!-- show listings -->
<?php foreach ($listingRecords as $listing): ?>
<div class="usedbikeblock">
<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $listing['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info2'] ?>" /></a><br/>
<?php break /* only show one image */ ?>
<?php endif; ?>
<?php endforeach ?>
<?php if (!$listing['uploads']): /* if no uploads show this: */ ?>

<div class="bikeimage"><br /><br /><b>Photo<br/>Not<br/>Available</b></div>

<?php endif; ?>

<b><a href="<?php echo $listing['_link'] ?>" class="title"><?php echo $listing['MAKE'] ?>&nbsp;&nbsp;-&nbsp;&nbsp;<?php echo $listing['MODEL'] ?></a>
</b><br/>
Price: &pound;<?php echo number_format($listing['PRICE']); ?><br/>
Year: <?php echo $listing['YEAR'] ?><br/>
Miles: <?php echo $listing['MILEAGE'] ?><br/>
Color: <?php echo $listing['COLOUR'] ?><br/>
</div>
<?php endforeach ?>
<br/>
<!-- /show listings -->

<div class="navigation">
<!-- show errors -->
<?php if ($listingDetails['invalidPageNum']): ?>
Results page '<?php echo $listingDetails['page']?>' not found, <a href="<?php echo $listingDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/><br/>
<?php elseif (!$listingRecords): ?>
No listings were found!<br/><br/>
<?php endif ?>
</div>
<!-- /show errors -->

<br/>

<!-- show prev/next page links -->
<div class="navigation">

<?php if ($listingDetails['prevPage']): ?>
<a href="<?php echo $listingDetails['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $listingDetails['page'] ?> of <?php echo $listingDetails['totalPages'] ?> -

<?php if ($listingDetails['nextPage']): ?>
<a href="<?php echo $listingDetails['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
</div>
<!-- /show prev/next page links -->


(This post was edited by 8bit Gamer on Nov 30, 2009, 1:43 AM)


Chris
Staff


Nov 30, 2009, 12:11 PM

Post #6 of 10 (16772 views)
Shortcut
Re: [8bit Gamer] Order Results using dropdown [In reply to] Can't Post

Hi 8bit Gamer,

So I'll assume you have a section with a list of all the "makes" (eg. Triumph, Peugeot, Yamaha, etc.) You would then add this code in the "STEP 1" PHP code at the top of the page:


Code
list($makeRecords,) = getRecords(array( 
'tableName' => 'bike_makes',
));


...then replace your <select name="MAKE" /> with:


Code
<select name="MAKE"> 
<option value="">All</option>
<?php foreach($makeRecords as $record): ?>
<option><?php echo htmlspecialchars($record['title']) ?></option>
<?php endforeach ?>
</select>


Please note that you'll probably need to change the names of the section and field (in red above) to match your own configuration.

You can then apply this same approach to colours and anything else you want automatically generated from your database.

I hope this helps! Please let me know if you have any questions.
Chris


Pixels & Beats
User

Dec 1, 2009, 3:05 AM

Post #7 of 10 (16742 views)
Shortcut
Re: [chris] Order Results using dropdown [In reply to] Can't Post

Hi Chris,

Got it all working OK except that I used a different method/code, as I was getting multiple entries for the same make (not your fault as you gave me exactly what I asked for lol!). It took me ages to work out how to do it, but with the help of other posts here on the forum, and your previous reply, I got there :)

There is however there is one usability issue I am trying to work round.

Make - Model - Colour are all now dynamically populated. However, combinations may not work as each option is not necessarily related to the other. For example there are no Peugeot bikes with the model name of 1098 (that is a Ducati model)

Is there a way to populate a list depending on the selection made in the first one. For example if I choose Peugeot then the model list would show only Peugeot models.

Here is a copy of the current code I am using.

------------------------------------------------------------------

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'adverts',
'orderBy' => 'PRICE',
));
?>
<?php foreach ($listingRecords as $record):
$makeRecords[] = $record['MAKE'];
$makeRecords = array_unique($makeRecords);
$modelRecords[] = $record['MODEL'];
$modelRecords = array_unique($modelRecords);
$colourRecords[] = $record['COLOUR'];
$colourRecords = array_unique($colourRecords);
endforeach;
?>

------------------------------------------------------------------

<select name="MAKE">
<option value="">All</option>
<?php foreach ($makeRecords as $record): ?>
<option value="<?php echo htmlspecialchars($record) ?>"><?php echo htmlspecialchars($record) ?></option>
<?php endforeach; ?>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Model:</span>
<select name="MODEL">
<option value="">All</option>
<?php foreach ($modelRecords as $record): ?>
<option value="<?php echo htmlspecialchars($record) ?>"><?php echo htmlspecialchars($record) ?></option>
<?php endforeach; ?>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Colour:</span>
<select name="COLOUR">
<option value="">All</option>
<?php foreach ($colourRecords as $record): ?>
<option value="<?php echo htmlspecialchars($record) ?>"><?php echo htmlspecialchars($record) ?></option>
<?php endforeach; ?>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Min Price:</span>
<select name="PRICE_min">
<option value="">All</option>
<option value="1000">&pound;1000</option>
<option value="2000">&pound;2000</option>
<option value="3000">&pound;3000</option>
<option value="4000">&pound;4000</option>
<option value="5000">&pound;5000</option>
<option value="6000">&pound;6000</option>
<option value="7000">&pound;7000</option>
<option value="8000">&pound;8000</option>
<option value="9000">&pound;9000</option>
<option value="10000">&pound;10000</option>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Max Price:</span>
<select name="PRICE_max">
<option value="">All</option>
<option value="1000">&pound;1000</option>
<option value="2000">&pound;2000</option>
<option value="3000">&pound;3000</option>
<option value="4000">&pound;4000</option>
<option value="5000">&pound;5000</option>
<option value="6000">&pound;6000</option>
<option value="7000">&pound;7000</option>
<option value="8000">&pound;8000</option>
<option value="9000">&pound;9000</option>
<option value="10000">&pound;10000</option>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Min CC:</span>
<select name="ENGINECC_min">
<option value="">All</option>
<option value="50">50cc</option>
<option value="125">125cc</option>
<option value="250">600cc</option>
<option value="600">600cc</option>
<option value="1000">1000cc</option>
</select>
&nbsp;&nbsp;&nbsp;
<span class="redhighlight">Max CC:</span>
<select name="ENGINECC_max">
<option value="">All</option>
<option value="50">50cc</option>
<option value="125">125cc</option>
<option value="250">600cc</option>
<option value="600">600cc</option>
<option value="1000">1000cc</option>
</select>
</div>
<div class="searchbutton">
<input type="submit" class="searchbutton2" value="" />
</div>
</form>


<!-- show listings -->
<?php foreach ($listingRecords as $listing): ?>
<div class="usedbikeblock">
<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $listing['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info2'] ?>" /></a><br/>
<?php break /* only show one image */ ?>
<?php endif; ?>
<?php endforeach ?>
<?php if (!$listing['uploads']): /* if no uploads show this: */ ?>

<div class="bikeimage"><br /><br /><b>Photo<br/>Not<br/>Available</b></div>

<?php endif; ?>

<b><a href="<?php echo $listing['_link'] ?>" class="title"><?php echo $listing['MAKE'] ?>&nbsp;&nbsp;-&nbsp;&nbsp;<?php echo $listing['MODEL'] ?></a></b><br/>
<span class="newsheading">Price:</span> &pound;<?php echo number_format($listing['PRICE']); ?><br/>
<span class="newsheading">Year:</span> <?php echo $listing['YEAR'] ?><br/>
<span class="newsheading">Miles:</span> <?php echo $listing['MILEAGE'] ?><br/>
<span class="newsheading">Color:</span> <?php echo $listing['COLOUR'] ?><br/>
<span class="newsheading">Engine:</span> <?php echo $listing['ENGINECC'] ?>cc<br/>
</div>
<?php endforeach ?>
<br/>
<!-- /show listings -->

------------------------------------------------------------------

Thanks for your help on this. It is very much appreciated :)


(This post was edited by 8bit Gamer on Dec 1, 2009, 8:55 AM)


Chris
Staff


Dec 1, 2009, 12:22 PM

Post #8 of 10 (16726 views)
Shortcut
Re: [8bit Gamer] Order Results using dropdown [In reply to] Can't Post

Hi 8bit Gamer,

Yes, you can do this with some custom Javascript programming, but I'm afraid it's a little complicated and we can't offer support for that.

One option would be to have us build you this feature through our consulting service. Please let me know if you're interested in that.
Chris


Pixels & Beats
User

Dec 2, 2009, 3:35 AM

Post #9 of 10 (16693 views)
Shortcut
Re: [chris] Order Results using dropdown [In reply to] Can't Post

Hi Chris,

Yes, please PM me the costs involved. I can then speak to the relevant people my end :)

For the moment I will just use the (less elegant):

onchange="this.form.submit()"

Function to update the lists.

Thanks

8BG


Damon
Staff / Moderator


Dec 3, 2009, 1:02 PM

Post #10 of 10 (16664 views)
Shortcut
Re: [8bit Gamer] Order Results using dropdown [In reply to] Can't Post

Hi,

Can you email us at consulting@interactivetools.com with a link to the page your working on and reference to this thread. http://www.interactivetools.com/forum/gforum.cgi?post=76146#76146

We can then take a look at what programming is required and send you a quote.

--------------------------------------------------- 
Cheers
Damon Edis
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/