Forum Moderators: coopster

Message Too Old, No Replies

Problem with printing variable

Trying to print $variable if $variable2 == x

         

jarvis

11:32 pm on Nov 10, 2005 (gmt 0)

10+ Year Member



I'm trying to set up a custom search form that substitutes values in an iframe url.

I've been able to get the url to change accordingly but the two problems i'm having are with:
1. print statement to pre-select an option value on submission; and
2. echo statement to output a variable in a sentence.


<?PHP // Set Defaults
if(isset($_GET['used_url'])){
$used_url = strtolower(trim($_GET['used_url']));
} else {
$used_url = 'http://www.carsales.com.au/pls/carsales/!jarvis_content.display_list?';
}
if(isset($_GET['page_url'])){
$page_url = strtolower(trim($_GET['page_url']));
} else {
$page_url = $_SERVER['PHP_SELF'];
}
if(isset($_POST['dealer_id'])){
$dealer_id = strtolower(trim($_POST['dealer_id']));
} else {
$dealer_id = '1486';
}
if(isset($_POST['segment_id'])){
$segment_id = strtolower(trim($_POST['segment_id']));
} else {
$segment_id = '';
}
if(isset($_GET['sort_type'])){
$sort_type = strtolower(trim($_GET['sort_type']));
} else {
$sort_type = '2';
}


if($dealer_id == '1486') {
$carlocation = 'ALL LOCATIONS';
} elseif ($dealer_id == '9379') {
$carlocation = '4X4';
} elseif ($dealer_id == '9181') {
$carlocation = 'CLOVELLY PARK';
} elseif ($dealer_id == '1226') {
$carlocation = 'GEPPS CROSS';
} elseif ($dealer_id == '1225') {
$carlocation = 'HILLCREST';
} elseif ($dealer_id == '1245') {
$carlocation = 'KENSINGTON';
} elseif ($dealer_id == '41') {
$carlocation = 'NORWOOD';
} elseif ($dealer_id == '1806') {
$carlocation = 'SPORTS';
} else {
$carlocation = 'ALL LOCATIONS';
}


if($segment_id == '1,4') {
$cartype = 'LARGE';
} elseif ($segment_id == '2') {
$cartype = 'COMMERCIAL';
} elseif ($segment_id == '3') {
$cartype = 'LUXURY';
} elseif ($segment_id == '5') {
$cartype = '4X4';
} elseif ($segment_id == '8') {
$cartype = 'SMALL';
} elseif ($segment_id == '9') {
$cartype = 'SPORTS';
} elseif ($segment_id == '&price_max=10000') {
$cartype = 'BUDGET';
} elseif ($segment_id == '&cs_body_id=%285%29') {
$cartype = 'WAGON';
} elseif ($segment_id == '&stock_type=X,YX') {
$cartype = 'EXECUTIVE';
} elseif ($segment_id == '&stock_type=D') {
$cartype = 'DEMO';
} else {
$cartype = 'QUALITY';
}


if($make_id == '3') {
$carmake = 'MITSUBISHI';
} elseif ($make_id == '4') {
$carmake = 'VOLVO';
} elseif ($make_id == '5') {
$carmake = 'NISSAN';
} elseif ($make_id == '6') {
$carmake = 'FORD';
} elseif ($make_id == '7') {
$carmake = 'MAZDA';
} elseif ($make_id == '8') {
$carmake = 'TOYOTA';
} elseif ($make_id == '9') {
$carmake = 'DAIHATSU';
} elseif ($make_id == '10') {
$carmake = 'HOLDEN';
} elseif ($make_id == '11') {
$carmake = 'PEUGEOT';
} elseif ($make_id == '12') {
$carmake = 'MERCEDES';
} elseif ($make_id == '13') {
$carmake = 'BMW';
} elseif ($make_id == '14') {
$carmake = 'SUBARU';
} elseif ($make_id == '15') {
$carmake = 'VOLKSWAGEN';
} elseif ($make_id == '16') {
$carmake = 'HYUNDAI';
} elseif ($make_id == '17') {
$carmake = 'KIA';
} elseif ($make_id == '18') {
$carmake = 'LANDROVER';
} elseif ($make_id == '19') {
$carmake = 'HONDA';
} elseif ($make_id == '20') {
$carmake = 'SUZUKI';
} elseif ($make_id == '21') {
$carmake = 'DAEWOO';
} elseif ($make_id == '22') {
$carmake = 'JEEP';
} elseif ($make_id == '23') {
$carmake = 'PROTON';
} elseif ($make_id == '20') {
$carmake = 'CHRYSLER';
} elseif ($make_id == '21') {
$carmake = 'EUNOS';
} elseif ($make_id == '22') {
$carmake = 'HSV';
} elseif ($make_id == '23') {
$carmake = 'FPV';
} else {
$carmake = '';
}?>


<h2>SEARCH<span class="sub"> OUR RANGE OF <?php echo ($cartype);?> <?php echo ($carmake);?> VEHICLES AT <?php echo ($carlocation);?></span></h2>
<form action="<?PHP $_SERVER['PHP_SELF'];?>" method="post" name="usedSearchRefinement" target="_self">
REFINE YOUR SEARCH BY: LOCATION
<select name="dealer_id" id="dealer_id">
<option value="1486"<?php if($dealer_id == '') { print ' Selected'; }?>>Please Select</option>
<option value="1486"<?php if($dealer_id == '1486') { print ' Selected'; }?>>All Dealerships</option>
<option value="9379"<?php if($dealer_id == '9379') { print ' Selected'; }?>>4x4</option>
<option value="9181"<?php if($dealer_id == '9181') { print ' Selected'; }?>>Clovelly Park</option>
<option value="1226"<?php if($dealer_id == '1226') { print ' Selected'; }?>>Gepps Cross</option>
<option value="1225"<?php if($dealer_id == '1225') { print ' Selected'; }?>>Hillcrest</option>
<option value="1245"<?php if($dealer_id == '1245') { print ' Selected'; }?>>Kensington</option>
<option value="41"<?php if($dealer_id == '41') { print ' Selected'; }?>>Norwood</option>
<option value="1806"<?php if($dealer_id == '1806') { print ' Selected'; }?>>Sports</option>
</select>
CAR TYPE
<select name="segment_id" id="segment_id">
<option value=""<?php if($segment_id == '') { print ' Selected'; }?>>Please Select</option>
<option value="8"<?php if($segment_id == '8') { print ' Selected'; }?>>Small Cars</option>
<option value="1,4"<?php if($segment_id == '1,4') { print ' Selected'; }?>>Family Cars</option>
<option value="&cs_body_id=%285%29"<?php if($segment_id == '&cs_body_id=%285%29') { print ' Selected'; }?>>Wagons</option>
<option value="&stock_type=D"<?php if($segment_id == '&stock_type=D') { print ' Selected'; }?>>Demos</option>
<option value="&stock_type=X,YX"<?php if($segment_id == '&stock_type=X,YX') { print ' Selected'; }?>>Executive</option>
<option value="2"<?php if($segment_id == '2') { print ' Selected'; }?>>Commercial</option>
<option value="9"<?php if($segment_id == '9') { print ' Selected'; }?>>Sports</option>
<option value="5"<?php if($segment_id == '5') { print ' Selected'; }?>>4x4</option>
<option value="3"<?php if($segment_id == '3') { print ' Selected'; }?>>Luxury</option>
<option value="&price_max=10000"<?php if($segment_id == '&price_max=10000') { print ' Selected'; }?>>Budget</option>
</select>
MAKE
<select name="make_id" id="make_id">
<option value=""<?php if($make_id == '') { print ' Selected'; }?>>Please Select</option>
<option value="6"<?php if($make_id == '6') { print ' Selected'; }?>>Ford</option>
<option value="8"<?php if($make_id == '8') { print ' Selected'; }?>>Toyota</option>
<option value="10"<?php if($make_id == '10') { print ' Selected'; }?>>Holden</option>
<option value="3"<?php if($make_id == '3') { print ' Selected'; }?>>Mitsubishi</option>
<option value="16"<?php if($make_id == '16') { print ' Selected'; }?>>Hyundai</option>
<option value="22"<?php if($make_id == '22') { print ' Selected'; }?>>Daewoo</option>
<option value="9"<?php if($make_id == '9') { print ' Selected'; }?>>Daihatsu</option>
<option value="14"<?php if($make_id == '14') { print ' Selected'; }?>>Subaru</option>
<option value="649"<?php if($make_id == '649') { print ' Selected'; }?>>FPV</option>
<option value="81"<?php if($make_id == '81') { print ' Selected'; }?>>HSV</option>
<option value="7"<?php if($make_id == '7') { print ' Selected'; }?>>Mazda</option>
<option value="19"<?php if($make_id == '19') { print ' Selected'; }?>>Honda</option>
<option value="5"<?php if($make_id == '5') { print ' Selected'; }?>>Nissan</option>
<option value="34"<?php if($make_id == '34') { print ' Selected'; }?>>Chrysler</option>
<option value="18"<?php if($make_id == '18') { print ' Selected'; }?>>Landrover</option>
<option value="17"<?php if($make_id == '17') { print ' Selected'; }?>>Kia</option>
<option value="23"<?php if($make_id == '23') { print ' Selected'; }?>>Jeep</option>
<option value="12"<?php if($make_id == '12') { print ' Selected'; }?>>Mercedes</option>
<option value="39"<?php if($make_id == '39') { print ' Selected'; }?>>Eunos</option>
<option value="13"<?php if($make_id == '13') { print ' Selected'; }?>>BMW</option>
<option value="21"<?php if($make_id == '21') { print ' Selected'; }?>>Suzuki</option>
<option value="15"<?php if($make_id == '15') { print ' Selected'; }?>>Volkswagen</option>
<option value="4"<?php if($make_id == '4') { print ' Selected'; }?>>Volvo</option>
<option value="28"<?php if($make_id == '28') { print ' Selected'; }?>>Proton</option>
<option value="11"<?php if($make_id == '11') { print ' Selected'; }?>>Peugeot</option>
</select>
<input name="Go" type="submit" id="Go" value="Go">
</form>
<br/><br/>
<iframe name="smallcars" width="100%" height="100%" frameborder="0" src="<?php echo ($used_url . 'dealer_id='.$dealer_id . '&segment_id='.$segment_id . '&make_id='.$make_id . '&sort_type='.$sort_type);?>">Your
browser cannot display this page correctly.<br>
To view this content independantly, please click the link below.<br>
<a href="<?php echo ($used_url . 'dealer_id='.$dealer_id . '&segment_id='.$segment_id . '&make_id='.$make_id . '&sort_type='.$sort_type);?>" target="_blank">Search
for Jarvis Small Cars.</a></iframe>

The iframe includes the correct url's however two of the options for car type do not preselect on submission. (Demo & Executive)

Also, these two do not echo the $cartype in the text near the top.

I've been on this for a day and a half now and can't seem to find the problem.

Any help is greatly appreciated!

IamStang

2:45 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



Well, the first observation I made was that your form is using the POST method and your script does not reflect the use of POST for all your calls.

$make_id = &_POST['make_id'];

IamStang

4:02 am on Nov 13, 2005 (gmt 0)

10+ Year Member



oops....should have read

$make_id = $_POST['make_id'];

jarvis

10:34 pm on Nov 13, 2005 (gmt 0)

10+ Year Member



The $_GET was used as i was including a separate includes file with the $variables set. I've swapped the $_GET occurances with $_POST but that still doesn't affect the output.

Like I said, the URL is being compiled correctly and the iframe shows the correct content. Unfortunately, the $cartype variable doesn't change to DEMO or EXECUTIVE when the form is submitted.

When the form is submitted with the selected values, the $segment_id is defined. The if/else statement then checks that $segment_id = 'some value' and inturn defines $cartype.

It works for all of the $cartype (s) except for DEMO and EXECUTIVE.

[edited by: coopster at 11:57 pm (utc) on Nov. 13, 2005]
[edit reason] removed ulr per TOS [webmasterworld.com] [/edit]

jarvis

10:59 pm on Nov 13, 2005 (gmt 0)

10+ Year Member



Well, I've found the problem....

the following code


if(isset($_POST['segment_id'])){
$segment_id = strtolower(trim($_POST['segment_id']));
} else {
$segment_id = '';
}

was setting the $segment_id as a blank value instead of taking the value assigned by the dropdown list.

Commenting out the code fixed the problem.