Page 1 of 1

problem returning int values from table

Posted: Mon Feb 16, 2009 4:22 pm
by neridaj
Hello,

I'm trying to return some invoice numbers (int) from a table to populate a select list but for some reason the values are coming back as as '' i.e., the correct number of select options are populated but with no data. When I try the same script on any other column (varchar or decimal) the data is returned correctly but var_dump returns null for all.

Here is my function:

Code: Select all

 
function display_update_invoice($result)
{
?>
<form method='post' action='invoice.php'>
<table align='center' bgcolor='#4E4D4D'>
    <tr>
    <th colspan='2'>Update Invoice</th>
    </tr>
<?php
  $info = mysqli_fetch_array($result);
  printf ("<tr><td>Description:&nbsp;</td><td><input type='textarea' rows='3' name='description' value='%s' /></td></tr>
            <tr><td>Amount Due:&nbsp;$</td><td class='alignright'><input type='text' name='amt_due' value='%s' /></td></tr>
            <tr><td>Amount Paid:&nbsp;$</td><td class='alignright'><input type='text' name='amt_paid' value='%s' /></td></tr>
            <tr><td>Balance:&nbsp;$</td><td class='alignright'><h3>%s</h3></td></tr>
            <tr><td colspan='2'><input type='submit' value='Update' /></td></tr>",
    $info['inv_description'], $info['inv_amt_due'], $info['inv_amt_paid'], $info['inv_amt_balance']);
    echo "<tr><td><select>";
  while ($obj = mysqli_fetch_array($result)) {
  printf("<option value='inv_num'>'%s'</option>", $obj['inv_number']);
    }
    echo "</select></td></tr></table></form>";
    var_dump($obj['inv_number']);
    mysqli_free_result($result);
}
?>
 
Thanks for any help,

J

Re: problem returning int values from table

Posted: Mon Feb 16, 2009 4:40 pm
by Weirdan
We would need to see sql query the $result was populated from.

Re: problem returning int values from table

Posted: Mon Feb 16, 2009 4:50 pm
by neridaj
Here is the SQL query:

Code: Select all

 
function get_invoice_info($user)
{
  //get invoice form data
  $conn = db_connect();
  $result = $conn->query( "SELECT user.inv_number, user.username, user.first_name, user.last_name, user.agent_name, invoice.inv_amt_due, invoice.inv_amt_paid, invoice.inv_amt_balance, invoice.inv_description FROM user INNER JOIN invoice ON user.username = invoice.username WHERE user.username = '$user'");
  if (!$result)
    return false; 
  else
    return $result;
}