Re: Result problem
| From: | Daniel Brown | Date: | Wed, 25 Apr 2007 22:12:37 +0000 |
| Subject: | Re: Result problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253790@lists.php.net to get a copy of this message | ||
Exactly. And I also wanted to make a note that when I included the
print_r($sql_record); in my last post, it was only because I forgot to
delete it.
I'm so ready to get out of here and grab a beer now!
On 4/25/07, Stut <stuttle@gmail.com> wrote:
Dan Shirah wrote: Any ideas why my query only returns the very last record that matches the criteria specified?? $sql_record ="SELECT * FROM payment_request WHERE status_code = 'P'"; $result_record = mssql_query($sql_record) or die(mssql_error()); if(!empty($result_record)) { while ($row_record = mssql_fetch_array($result_record)) {-- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107$id_record = $row_record['id'];} } print_r ($sql_record); The result of the print_r displays only the last record that matches the query criteria. I tried a foreach instead of a while with no luck. Problem 1: You're calling print_r on $sql_record instead of $id_record. Problem 2: Each iteration of your loop overwrites $id_record so when the last loop happens, i.e. when it's on the last row, it sets it to the value of that row. If you're intention is for $id_record to be an array of the IDs, change the line to... $id_record[] = $row_record['id']; Problem 3: You need to read up on some basic PHP syntax. This is just about the most basic problem you could have. The PHP manual should help you here. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php