Jump to content

How to display sql query results


mjaya

Recommended Posts

hi,

what i want to know is write a code for not repeating td class table1 and td class table2 in every row. since this table is getting about 19 rows of data from SQL server and it is very lengthy.

 

i want to write a code to minimize lines of the code.

can u please help me ???

thanks

maddie

 

$SQLQuery ="Select * from test where ite_id=".$ite_id;

$jewc=db::db(0,$SQLQuery);

if (!$jewc->eof())

{

<fieldset>

<legend> Header Details</legend>

<table width="100%">

<TR>

<td class="table2" style="width: 30%">Id:</td>

<td class="table1">echo $jewc->Id;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">Item Id:</td>

<td class="table1"> echo $jewc->Ite_Id;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">Sta_id:</td>

<td class="table1">echo $jewc->ClientNo;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">Reference:</td>

<td class="table1"> echo $jewc->Reference;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">Complete:</td>

<td class="table1"> echo $jewc->Complete;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">Mode:</td>

<td class="table1"> echo $jewc->Mode;</td>

</tr>

<TR>

<td class="table2" style="width: 30%">PayMh:</td>

<td class="table1"> echo $jewc->PayMh;</td>

</tr>

<TR>

 

Link to comment
https://forums.phpfreaks.com/topic/103822-how-to-display-sql-query-results/
Share on other sites

I assume the code you have works

 

<?php
$SQLQuery ="Select * from test where ite_id=".$ite_id;
$jewc=db::db(0,$SQLQuery);
$id = '<td class="table2" style="width: 30%">Id:</td>';
$itemid = '<td class="table2" style="width: 30%">Item Id:</td>';
$staid = '<td class="table2" style="width: 30%">Sta_id:</td>';
$reference = '<td class="table2" style="width: 30%">Reference:</td>';
$complete = '<td class="table2" style="width: 30%">Complete:</td>';
$mode = '<td class="table2" style="width: 30%">Mode:</td>';
$paymh = '<td class="table2" style="width: 30%">PayMh:</td>';

while(!$jewc->eof())
{
  $class = ($i == 0 ? 1 : 2);
  $id .= "<td class='table{$class}'>{$jewc->Id}</td>";
  $itemid .= "<td class='table{$class}'>{$jewc->Ite_Id}</td>";
  $staid.= "<td class='table{$class}'>{$jewc->ClientNo}</td>";
  $reference.= "<td class='table{$class}'>{$jewc->Reference}</td>";
// Continue for each column

$i++;
if($i==2){
$i = 0;
}
}

echo "<fieldset>
<legend> Header Details</legend>
<table width="100%">
<TR>" . $id . "</tr>
<tr>" . $itemid . "</tr>
<tr>" . $staid  . "</tr>";
// Continue for all columns
echo "</table></fieldset>";
?>

 

Not tested, but that's pretty much how you could do it.

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.