select command not working in php/mysql

69 views Asked by At

In the below code, I am getting invoice_id, but its gives the 1st record Invoice_id of INVOICE table.

$invoicenum = $form['invoice'][$i]['inv_id']['#value'];
$invoiceid = db_query('SELECT invoice_id FROM invoice WHERE invoice_number= %d', $invoicenum);
$invoiceid1 =  db_fetch_object($invoiceid);

print $invoiceid1->invoice_id;
1

There are 1 answers

1
Simranjeet On

Hello Alex Gittemeier,

If you want invoice ids than use this code

$invoicenum=$form['invoice'][$i]['inv_id']['#value'];
$invoiceid=db_query('select invoice_id from invoice'. 
                     'where invoice_number= %d',$invoicenum);
$invoiceid1=  db_fetch_array($invoiceid);

print_r($invoiceid1);

you can get invoice ids from array with help of loop.

Regards Simranjeet singh