Re: Displaying Results on different rows in tables
| From: | Brad Bonkoski | Date: | Thu, 18 Jan 2007 16:51:20 +0000 |
| Subject: | Re: Displaying Results on different rows in tables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247352@lists.php.net to get a copy of this message | ||
Dan Shirah wrote:
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 assign 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>select child_support_payment_request.credit_card_id, <table_name>.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<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"; $pass = "password"; // Connect to the datbase $connection = mssql_connect($host, $user, $pass) 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 = "SELECTchild_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"; First of all, if you are joining on the credit_card_id, you only need to select one of them. So your query would be:
$result = mssql_query($sql) or die(mssql_error()); while ($row=mssql_fetch_array($result)); 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>";
$id = $row['credit_card_id']; $dateTime = $row['date_request_received']; ?>