Re: Result problem
| From: | Daniel Brown | Date: | Wed, 25 Apr 2007 21:42:14 +0000 |
| Subject: | Re: Result problem | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253780@lists.php.net to get a copy of this message | ||
It looks like it's a combination of what everyone's been suggesting.
Try this rewritten code:
<?
$sql ="SELECT * FROM payment_request WHERE status_code = 'P'";
$result = mssql_query($sql) or die(mssql_error());
while ($row = mssql_fetch_array($result)) {
expand($row);
$all[] = $id;
}
print_r($all);
?>
print_r ($sql_record);
On 4/25/07, Dan Shirah <mrsquash2@gmail.com> wrote:
No, I am trying to figure out why my query is only returning the last record that matches instead of all the records that match. On 4/25/07, Daniel Brown <parasane@gmail.com> wrote:-- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107Are you trying to just print this to the screen? If so, refer tothe modified snippet I sent you a bit ago. On 4/25/07, Dan Shirah < mrsquash2@gmail.com > wrote:I'm sorry, perhaps I confused everyone by including the print_r. My table has 79 records all with a status_code of 'P' that this "should" be returning. But instead of all the results returning, all I am getting back is row 79. On 4/25/07, Richard Lynch < ceo@l-i-e.com> wrote:-- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107On Wed, April 25, 2007 3:56 pm, Dan Shirah wrote:matchesAny ideas why my query only returns the very last record that'P'";the criteria specified?? $sql_record ="SELECT * FROM payment_request WHERE status_code =matches$result_record = mssql_query($sql_record) or die(mssql_error()); if(!empty($result_record)) { while ($row_record = mssql_fetch_array($result_record)) {$id_record = $row_record['id'];} } print_r ($sql_record); The result of the print_r displays only the last record thatluck.the query criteria. I tried a foreach instead of a while with noYou do the 'print_r' *AFTER* you've run through all the records. Move that line *INSIDE* the loop, and it will print each one as it goes through. This will be more clear if you indent better, though that may justbeemail messing up, not your real code. Every time you type a '{', indent by one tab. Stay indented until you type a '}' The "flow" of the program is then seen by skimming with the eyes downward on the left side, and the 'print_r' being outside the loop will be more obvious, with practice. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?