Question about searching

8 posts by 3 authors in: Forums > CMS Builder
Last Post: June 1, 2010   (RSS)

By andreasml - May 6, 2010

Hi
I would like to make a search option in my website with combo boxes, that will change their content depending on which is the choice on the previous combo box.
For example, you can visit the address to get the idea:http://www.carsdirect.com/used_cars/search

Thanks

Re: [Jason] Question about searching

By jposwald - May 17, 2010

Hello Jason,

I'm searching the forum for a solution for this too.

I have to make a combo search for a car agent website.

Combo Box with Manufacturer and when you choose one, list all Models, I already have it in CMS (with about 1200 records of Models) using the thread and a script that Chris made in other post.

What I need in fact is the whole search page for users.

Combo box with Manufacturer and Models, and then search by Price from and Price To.

How can i make it? What do you need to help me up with this one?

Thank you, Juan.

Re: [jposwald] Question about searching

By Jason - May 17, 2010

Hi Juan,

Have you started to create this search page already? If so, could you attach your .php file. That would help get us started.

Also, could you tell me which section you are trying to perform the search on and what are the names of all the fields in that section.

Let's start there. :)
---------------------------------------------------
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] Question about searching

By jposwald - May 31, 2010

Hey Jay,

I want to be able to have a dependent combo box with 2 levels Manufacturer (Marca) and Model (Model).

I attach my php file for you. You can see here:
http://www.pixalar.com/dev/cassano/usados/index.php
As u can see I have all Manufacturers and Models up in CMS.
Attachments:

index_019.php 4K

Re: [jposwald] Question about searching

By Jason - May 31, 2010

Hi,

So, if I understand correctly, you want to display all of your models in a drop down list, organized by manufacturer. Is that right?

If so, I think this code is what you're looking for:

<td width="890" height="198" valign="top">
<select name="modelos">
<?php foreach ($marcaRecords as $marca): ?>
<optgroup label="<?php echo $marca['nombre']; ?>">
<?php foreach ($marca['modelos'] as $modelo): ?>
<option value="<?php $modelo['num'];?>"><?php echo $modelo['nombre'];?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</td>


Give this a try and let me know if this is what you want.

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] Question about searching

By jposwald - May 31, 2010

Hi Jason, that is great too, but I need 2 select boxes:

One with all Manufacturers and when users select one, list all Models of that Manufacturer.

Re: [jposwald] Question about searching

By Jason - June 1, 2010

Hi,

What you need to do is to select 2 sets of records from the database instead of using the beta_lookupReferringRecords() function.

Your select statements would look something like this:
<?php

list($marcaRecords,$marcaMetaData)=getRecords(array(
'tableName'=>'marca',
));

list($modeloRecords,$modeloMetaData)=getRecords(array(
'tableName' => 'modelo',
'where' => "marca='".mysql_escape(@$_REQUEST['marca'])."'",
))
?>

This loads all of the records from "marca" into $marcaRecords. $modeloRecords will hold all of the records from modelo that have the same marca as the one selected (If none has been selected, it will be blank.).

All that's left after that is to display the select boxes. You could use something like this:

<form name="marca" action="?" method="post">
<select name="marca">
<?php foreach ($marcaRecords as $record): ?>
<option value="<?php echo $record['num'];?>"><?php echo $record['title'];?></option>
<?php endforeach ?>
</select>
<input type="submit" value="Go" />
</form>

<?php if($modeloRecords): ?>
<form name="modelo" action="?" method="post">
<select name="modelo">
<?php foreach($modeloRecords as $record): ?>
<option value="<?php echo $record['num'];?>"><?php echo $record['title'];?></option>
<?php endforeach ?>
</select>
</form>
<?php endif ?>


The code:
<?php if($modeloRecords): ?>
means it will only display the second select box it the first form has been submitted, and there are values in $modeloRecords. You'll have to change the names a bit to match what you have in the database.

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/