...

View Full Version : getting the value of a varible to be recognised by a function?



LJackson
09-06-2009, 09:11 PM
Hi All,

i have a form which i have set as a function as i require calling this form in several sections of my code, the problem im having is that one my main page i have a varible which is being used in my form function but it doesnt recognise its value?

here is my function

<?php
function store_filterForm(){
?>
<div class="form">
<form id="filter" action="stores.php" method="get">
<fieldset>
<div>
<div class="label">
<label for="cat_select">Category</label></div>
<select id="cat_select" name="cds">
<?php
print $category;
$options=array('entertainment','computing','electronics','clothing','health','misc');
foreach($options as $option) {
if($category==$option) {
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
}
else {
echo "<option value=\"{$option}\">{$option}</option>";
}
}
?>
</select>
</div>
<div>
<div class="label">
<label for="filter_by">Filter By</label></div>
<select id="filter_by" name="filter_list">
<?php
$options=array('None','Name','Rating');
foreach($options as $option) {
if($b==$option) {
echo "<option value=\"{$option}\" selected=\"selected\">{$option}</option>";
}
else {
echo "<option value=\"{$option}\">{$option}</option>";
}
}
?>
</select>
</div>
<input type="submit" name="submit" id="submit" value="Filter" />
</fieldset>
</form>
</div>
<?php
}
?>


and the varible im trying to use is $category which i have tried printing out but nothing printed proving that the function is having trouble retrieving the value?

i tried adding the varible to the function call like so

store_filterForm($category);

but it said something about argument 1 missing so im assuming i need two arguments but im not sure what :(

any ideas please
Thanks

funnymoney
09-06-2009, 09:13 PM
you need to add variable to function, here


<?php
function store_filterForm($category){

LJackson
09-06-2009, 09:28 PM
hmm ok thats got rid of the error but its still not retaining the combo box value, which it did before i changed it into a function?

this is how i set the $category on the main page

if(isset($_GET['cds'])){
$category = $_GET['cds'];
}
else {
$category = $_SESSION['page_category'];
}


but my print statment in my form doesnt print out any value?

any ideas
thanks
Luke

LJackson
09-06-2009, 11:57 PM
ok got it working :)

had to pass another varible as part of the function as well. its working a treat

thanks mate
Luke



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum