Im pretty inexperienced with php and MySQL and have ran into a problem which i hope you can help me with,
i have a select box populated with data from Mysql, heres a look at the code
$query = "SELECT id,output, tempname FROM templates ORDER BY output";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
$value = $row["id"];
$output = $row["output"];
$tempname = $row["tempname"];
$pairs["$value"] = $tempname;
}
echo create_dropdown("create_output", $pairs, "Choose Your Template");
function
create_dropdown($identifier,$pairs,$firstentry)
{
// start dropdown list with the <select> element and title
$dropdown = "<select name=\\"$identifier\\" method=\\"post\\" onchange=\\"showtemplate(this.value)\\">";
$dropdown .= "<option name=\\"\\">$firstentry</option>";
// Create the elements for inside the drop down box
foreach($pairs AS $value => $tempname)
{
$dropdown .="<option name=\\"$value\\">$tempname</option>";
}
//end the dropdown function and return it as html
echo "</select>";
return $dropdown;
}
using ajax i then select from the dropdown and it populates a textarea with the relevant field (name of field is output) contents from the row, anyway it populates the textarea fine but the problem is it is pulling in all rows from the column instead of just the selected row,
heres the code that populates the textarea upon ajax passing the info over
$query = "SELECT output FROM templates";
$result = mysql_query($query);
while ($row = mysql_fetch_object($result))
{
print $row->output;
}
can any of you guys see where i am going wrong, over 2 days trying to get this thing going…thanks