After struggling with this for a few days now and countless hours of searching I am gonna have to ask for a bit of advice.
What I have is a table with a column of customer names that I am fetching with a query to populate a drop down menu. I just cant seem to get anything other than the first row to show up in the list.
Here is the bit of code that is giving me the issues. As you will notice I have another drop down with the option values defind and it is working flawlessly.
function edit_sales() {
global $lang_sales, $lang_global, $output, $dcdms_db;
$sql = new SQL;
$sql->connect($dcdms_db['addr'], $dcdms_db['user'], $dcdms_db['pass'], $dcdms_db['name']);
if(isset($_GET['id'])) $id = $sql->quote_smart($_GET['id']);
else redirect("sales.php?error=1");
$query = $sql->query("SELECT sales.*, contacts.name, customer.name FROM sales, contacts, customer
WHERE sales.salesman = contacts.id AND sales.cust_id = customer.id AND sales.id = '$id'");
$query_c = $sql->query("SELECT `name` FROM `customer`");
if ($sql->num_rows($query) == 1) {
$item = $sql->fetch_row($query) and
$cust = $sql->fetch_array($query_c);
$output .= "<script type=\"text/javascript\">
answerbox.btn_ok='{$lang_global['yes_low']}';
answerbox.btn_cancel='{$lang_global['no']}';
</script>
<center>
<fieldset class=\"half_frame\">
<legend>{$lang_sales['edit_sales']}</legend>
<form method=\"get\" action=\"sales.php\" name=\"form\">
<input type=\"hidden\" name=\"action\" value=\"do_edit_sales\" />
<input type=\"hidden\" name=\"id\" value=\"$id\" />
<table class=\"flat\">
<tr>
<td>{$lang_sales['job_id']}</td>
<td><input type=\"text\" name=\"new_job_id\" size=\"16\" maxlength=\"12\" value=\"$item[1]\" /></td>
<td>{$lang_sales['id']}</td>
<td>$item[0]</td>
</tr>
<tr>
<td>{$lang_sales['cust_id']}:</td>
<td>
<select name=\"new_cust\" value=\"$item[10]\">
<option value=\"$item[10]\">$item[10]</option>
<option value=\"$cust[0]\">$cust[0]</option>
</select>
</td>
<td>{$lang_sales['subd']}</td>
<td><input type=\"text\" name=\"new_subd\" size=\"16\" maxlength=\"12\" value=\"$item[5]\" /></td>
</tr>
<td>{$lang_sales['address']}</td>
<td><input type=\"text\" name=\"new_addy\" size=\"30\" maxlength=\"30\" value=\"$item[4]\" /></td>
<td>{$lang_sales['lot']}</td>
<td><input type=\"text\" name=\"new_lot\" size=\"8\" maxlength=\"4\" value=\"$item[6]\" /></td>
<tr>
</tr>
<tr>
<td>{$lang_sales['salesman']}:</td>
<td>
<select name=\"new_salesman\" value=\"$item[9]\">
<option value=\"$item[9]\">$item[9]</option>
<option value=\"David Casey\">David Casey</option>
<option value=\"Steve Applebaum\">Steve Applebaum</option>
<option value=\"Mike Ralph\">Mike Ralph</option>
<option value=\"Ronnie Strickland\">Ronnie Strickland</option>
</select>
</td>
</tr>
<tr>
<td>{$lang_sales['date_in']}</td>
<td><input type=\"text\" name=\"new_date_in\" size=\"12\" maxlength=\"10\" value=\"$item[7]\" /></td>
<td>{$lang_sales['date_out']}</td>
<td><input type=\"text\" name=\"new_date_out\" size=\"12\" maxlength=\"10\" value=\"$item[8]\" /></td>
</tr>
<tr>
</tr>
<tr><td>";
makebutton($lang_sales['delete_sales'], "#\" onclick=\"answerBox('{$lang_global['delete']}: <font color=white>{$items[1]}</font> <br /> {$lang_global['are_you_sure']}', 'sales.php?action=del_sales&job_id=$id');\" type=\"wrn",98);
$output .= "</td><td>
<table class=\"hidden\">
<tr><td>";
makebutton($lang_sales['update_sales'], "javascript:do_submit()",120);
$output .= "</td><td>";
makebutton($lang_global['back'], "sales.php\" type=\"def",100);
$output .= "</td></tr>
</table>";
$output .= "</td></tr>
</table>
</form></fieldset><br /><br /></center>";
} else error($lang_global['err_no_records_found']);
$sql->close();
}
I am thinking it has to do with the placement of the >> $cust = $sql->fetch_array($query_c) << but I have tried about everything I can think of to no avail. I do know the result set of $query_c is correct because when I place the fetch_array before the (if) statement I end up displaying the form repeatedly for each result.
I wasn't really sure if I should post this in the code section or here but since I personally am a relative newb when it comes to php I decided to go here. I have picked up this project which was started by a former co-worker and Im trying to get it into a more functional form.
Any help / advice will be greatly appreciated.