Jump to content

displaying multiple records


aussiefly

Recommended Posts

hey guys,

 

I'm still coming to grips with some fo the php basics and although I have queries down and am able to grab details from the database...i need some help on grabbing multiple data.

 

So say I have a transaction table with data in it...lets say 7 different fields etc and I want to select whole rows when it relates to my userid and then display it how would i go about it?

 

$normal_query = "SELECT * FROM `transactions` where `user_id` = '415'";
$result = mysql_fetch_array($normal_query);

php?>
<?php echo $result; php?>

 

So pretty much I want to see al the transactions from a specific user etc and then display them on a page...Now I was sticking it into an array but how then do i display it all without having to name each field from the table???

 

Any ideas for a complete newb ???

Link to comment
https://forums.phpfreaks.com/topic/92837-displaying-multiple-records/
Share on other sites

Ok that seems to work really well without having to specify the databse fields :)

 

It's displaying:

 

Array ( [trans_id] => 22 [user_id] => 415 [amount] => 125.00 [acc] => 2456743 [type] => withdrawal [date] => Sun, 24 Feb 2008 21:32:43 -0600 [status] => pending )

 

Any idea how I can format that to look good and without the [] => symbols etc?

 

Thanks again

aussie

 

<?php
$normal_query = "SELECT * FROM `transactions` where `user_id` = '415'";
$result = mysql_query($normal_query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{
     print_r($row);
}
?>

$row is an array, indexed just like any other. eg;

 

<?php
$normal_query = "SELECT * FROM `transactions` where `user_id` = '415'";
$result = mysql_query($normal_query) or die(mysql_error());

while ($row = mysql_fetch_assoc($result))
{
    echo "<p>" . $row['fld1'] . "</p>";
    echo "<p>" . $row['fld2'] . "</p>";
}
?>

ahhh thats it...now i'm getting it!!!

 

Thanks guys...this place is an awesome resource...btw i looked up print_r in the php manual and me using it was why it was printing out all the extra data :)

 

cheers again

aussie

Yes, that was supposed to be just a reference to get you started, not a method for you to copy and paste ;) (not that you were, I'm just saying).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.