Post Code Search

5 posts by 2 authors in: Forums > CMS Builder
Last Post: December 6, 2010   (RSS)

By KCMedia - December 5, 2010

Hi

I have setup a multi section in CMS Builder with all the fields that are needed for the search but now i need some help as to how to get a search working and to display the results.

I have attached the main search page and also the results page i want to be able to have users search for a post code and then it will display any matching results for that post code.

thanks

Craig
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] Post Code Search

By Jason - December 6, 2010

Hi Craig,

There are a couple things you'll need to change. First, on your search page, you'll want to give your text field the same name as the field in the database. In this example, the field in probably called "post_code" but you can change this if necessary:

<form action="postcode-searchResults.php" method="POST">
<p>
<input name="post_code" type="text" id="Pcode" />
</p>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
<label>
<input type="reset" name="button2" id="button2" value="Reset" />
</label>
</form>


Next, on postcode-searchResults.php, you'll need to change your query. You're not going to want to use whereRecordNumberInUrl(1) and you're not going to want to set you're limit to 1 if you want to display all results. Try this instead:
// load records
list($post_code_searchRecords, $post_code_searchMetaData) = getRecords(array(
'tableName' => 'post_code_search',

));


The variable $post_code_searchRecords will be an array with all the records from post_code_search where the field "post_code" is equal to the value typed in the text box.

Give this a try and let me know if you run into any problems.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Post Code Search

By KCMedia - December 6, 2010

hi Jason

I sort of got it working

If i search for a post code say 2234 it will show just one result but i know that there are more results than just that why is it only showing 1 result.

here is the link to the site page http://www.afft.com.au/newsite/postcode-search.php

and also the page codes for each page.

thanks

Craig
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] Post Code Search

By Jason - December 6, 2010

Hi Craig,

You're query is probably returning more than 1 result, but you're only displaying one. You need to make two changes.
1) remove the "get first record" line:
// load records
list($post_code_searchRecords, $post_code_searchMetaData) = getRecords(array(
'tableName' => 'post_code_search',
));
$post_code_searchRecord = @$post_code_searchRecords[0]; // get first record


Next, you'll need to use a foreach loop to display all the records that were returned:

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<?php foreach($$post_code_searchRecords as $post_code_searchRecord):?>
Pcode: <?php echo $post_code_searchRecord['Pcode'] ?><br/>
Locality: <?php echo $post_code_searchRecord['Locality'] ?><br/>
State: <?php echo $post_code_searchRecord['State'] ?><br/>
Comments: <?php echo $post_code_searchRecord['Comments'] ?><br/>
DeliveryOffice: <?php echo $post_code_searchRecord['DeliveryOffice'] ?><br/>
PresortIndicator: <?php echo $post_code_searchRecord['PresortIndicator'] ?><br/>
ParcelZone: <?php echo $post_code_searchRecord['ParcelZone'] ?><br/>
BSPnumber: <?php echo $post_code_searchRecord['BSPnumber'] ?><br/>
BSPname: <?php echo $post_code_searchRecord['BSPname'] ?><br/>
Category: <?php echo $post_code_searchRecord['Category'] ?><br/>
<hr/>
<?php endforeach ?>
<?php if (!$post_code_searchRecords): ?>
No record found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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