i'm currently trying to write some classes however im having problems passing variables
the display_cat_menu calls the get_categories function, both are within the same class
<?php
function get_categories()
{
// query database for a list of categories
$conn = new db();
$conn -> db_conn();
$id = 'catid';
$query = 'select $id, catname
from categories';
$result = @mysql_query($query);
if (!$result)
return false;
$num_cats = @mysql_num_rows($result);
if ($num_cats ==0)
return false;
$result= $conn->db_result_to_array($result);
return $result;
}
function display_category_menu()
{
?>
<form method=get action="show_cat.php">
<select name=catid>
<?php
// list of possible categories comes from database
$cat_array=$this->get_categories();
foreach ($cat_array as $thiscat)
{
echo '<option value="';
echo $thiscat['catid'];
echo '"';
echo '>';
echo $thiscat['catname'];
echo "\n";
}
?>
</select>
<input class="go" type=submit value="Go">
</form>
<?php
}
i have tried this query harcoded which works fine, but many attempts to pass the variable $id have not worked, ive tried passing through the function, using set and get functions etc. Could anyone point me in the right direction
Thanks in advance