I am looking to create the drop down list based on the "name" field in the "merchandise" table, that will list all of the rows in that
table where the "status" field is NOT equal to 'sold out'. I also need the user to be able to then select one piece of available merchandise and save that selection as a variable that can be written back to the database.
This is my first attempt at doing form fields that call from the database (versus write to it), so I'm working from a book (MySQL/PHP Databse Applications).
It tells me i want to do a db_values_array and then a db_select_field, but I
can't make it work.
Below is the code they suggest. Could someone debugg it for me. Right now it doesn't pull anything from the database.
<?
function db_values_array ($table="merchadise", $value_field="name",
$label_field=""
, $sort_field=""
, $where_field=" status != 'sold out'"
)
{
$values = array();
if (empty($table) || empty($value_field)) {return $values; }
if (empty($label_field)) {$label_field = $value_field; }
if (empty($sort_field)) {$sort_field = $label_field; }
if (empty($where_field)) {$where = "1=1"; }
$query = "select $value_field as value field
, $label_field as label field
from $table where $where
order by $sort_field
";
$result = safe_query($query);
if ($result)
{
while (list($value, $label) = mysql_fetch_array($result))
{
$values[$value] = $label;
}
}
return $label;
}
?>
here I think I need to do the db_select_field(), but I'm not sure what to
put into the fields or where to put it in reference to the above array. Here
is how it's described in my book:
string db_select_field([string name [, string table name [, string value
field [, string label field [, string sort field [, string match text [,
string where clause]]]]]]])
Thanks.