Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Displaying Results on different rows in tables
Old
  (#1)
Dan Shirah
Guest
 
Posts: n/a
Default Displaying Results on different rows in tables - 05-14-2007, 03:35 AM

Hello all,

I am trying to pull data and then loop through the multiple results display
in seperate rows.
My database contains several tables which are all tied together by the
credit_card_id. After running the query, it ties the unique record together
by matching the credit_card_id in both tables. How would I go about
displaying the results of this query in a table with a single row for each
unique record?

Each row of the result will have 5 columns: Request ID, Date/Time Entered,
Status, Payment Type, Last Processed By.

If I ***ign the results of the query to variables (Such as $id =
$row['credit_card_id'] how would I display that data?

Would it be something like this:

foreach($row as $data)
{
echo "<table>
<tr>
<td><a href=$item->link>$id</a></td>
</tr>";
echo "<tr>
<td>$dateTime</td>
</tr>
</table>";
echo "<tr> <td>$Status</td>
</tr>
</table>";

}
Below is the code I have so far.

<?php
$database = "database";
$host = "host";
$user = "username";
$p*** = "p***word";
// Connect to the datbase
$connection = mssql_connect($host, $user, $p***) or die ('server
connection failed');
$database = mssql_select_db("$database", $connection) or die ('DB
selection failed');
// Query the table and load all of the records into an array.
$sql = "SELECT
child_support_payment_request.credit_card_id,
credit_card_payment_request.credit_card_id,
date_request_received
FROM child_support_payment_request,
credit_card_payment_request
WHERE child_support_payment_request.credit_card_id =
credit_card_payment_request.credit_card_id";
$result = mssql_query($sql) or die(mssql_error());
while ($row=mssql_fetch_array($result));
$id = $row['credit_card_id'];
$dateTime = $row['date_request_received'];

?>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] Displaying Results on different rows in tables
Old
  (#2)
Dan Shirah
Guest
 
Posts: n/a
Default Re: [PHP] Displaying Results on different rows in tables - 05-14-2007, 03:35 AM

Ah, I see. In Brad's reply there was two $result = mssql_query($sql) or
die(mssql_error()); in the code. Removed the one from outside of the loop
and it works fine now.



Thanks to both of you for your help!




On 1/18/07, Chris <EMAIL REMOVED> wrote:
>
> Dan Shirah wrote:
> > The code above displays no information at all.
> >
> > What I want to do is:
> >
> > 1. Retrieve my information
> > 2. ***ign it to a variable
> > 3. Output the data into a table with each unique record in a seperate

> row
>
>
> As Brad posted:
>
> echo "<table>";
> while ($row = mssql_fetch_array($result)) {
> $id = $row['credit_card_id'];
> $dateTime = $row['date_request_received'];
> echo "<tr><td>$id</td><td>$dateTime</td></tr>";
> }
> echo "</table>";
>
>
> If that doesn't work, try a print_r($row) inside the loop:
>
> while ($row = mssql_fetch_array($result)) {
> print_r($row);
> }
>
> and make sure you are using the right id's / elements from that array.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top