aussiefly Posted February 25, 2008 Share Posted February 25, 2008 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 ??? Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 <?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); } ?> Quote Link to comment Share on other sites More sharing options...
Steve Angelis Posted February 25, 2008 Share Posted February 25, 2008 Or this: echo $result['database field here']; Quote Link to comment Share on other sites More sharing options...
aussiefly Posted February 25, 2008 Author Share Posted February 25, 2008 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); } ?> Quote Link to comment Share on other sites More sharing options...
aussiefly Posted February 25, 2008 Author Share Posted February 25, 2008 actually the clearer questions is....is there a way to display the assoc array without it listing the database field or row tags? so that it would just print out the actual field data ??? Quote Link to comment Share on other sites More sharing options...
trq Posted February 25, 2008 Share Posted February 25, 2008 $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>"; } ?> Quote Link to comment Share on other sites More sharing options...
aussiefly Posted February 25, 2008 Author Share Posted February 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 25, 2008 Share Posted February 25, 2008 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). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.