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
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);
}
?>

Link to comment
Share on other sites

$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>";
}
?>

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.