hi.. I'm new at php.. got stuck wif something.. it's kinda urgent..
the idea:
1) have a form wif a text box.. enter a prod_name ($form[prod_id])
2) then retrieve and display the prod_id of tht prod_name from the database..
I do know how to do a textbox and take the value.. Then here's the prob.. I'm not very good at retrieving from the database..
this i know:
їphp]<?php
$prod = getProd("product"); // this is a function
// how to retrieve the results and display the prod_id of the prod_name/
?>ї/php]
їphp]<?php
//this is the getProd function
function getProd($table)
{
global $prod_link;
$query = "SELECT * from $table ORDER BY prod_name";
$result = mysql_query($query, $prod_link);
if ( ! $result)
{
print "failed to open $table<p>";
return false;
}
$ret=array();
$temp="";
while($row=mysql_fetch_array($result))
{
// if the prod name not blank.. and the prod family is not special
if($rowїprod_name]!=$temp && $rowїprod_family]!="special")
{
$rowїprod_name]=$rowїprod_name];
array_push($ret,$row);
}
$temp=$rowїprod_name];
}
return $ret;
}
?>ї/php]
then I'm not sure on how to retrieve and display the prod_id from the function.. and not sure if this is correct.. Can anyone help? Thanks..
function getProd($table)
{
global $prod_link;
$query = "SELECT prod_id,prod_name,prod_family from $table ORDER BY prod_name";
$result = mysql_query($query, $prod_link);
if ( ! $result)
{
print "failed to open $table<p>";
return false;
}
$ret=array();
$temp="";
while(list($prod_id,$prod_name,$prod_family)=mysql_fetch_array($result))
{
// if the prod name not blank.. and the prod family is not special
if($prod_name!=$temp && $prod_family!="special")
{
array_push($ret,$prod_name.'|'.$prod_id);
}
$temp=$prod_name;
}
return $ret;
}
?>
The | becomes a delimiter.
To split it out, do this:
$prod = getProd("product");
while (list($key,$value) = each($prod )) {
list($name,$id)=split("\|",$value);
echo "Product name: $name Product id:$id<br>";
}