Forum Moderators: coopster

Message Too Old, No Replies

mysql results formatting

         

cookie2

6:34 pm on May 11, 2006 (gmt 0)

10+ Year Member



I have a small problem formatting query results for printing. I am attempting to pull info from mysql (exact selections determined on another page) and print the results in to a two column table. The code I have works quite well for a single ID's row info. Does exactly what I want it to. But if I select more than one ID to show, the first one's info is shown completely in a single column table while the second one is shown in the correct two column format. How can I get all returned in the two column format?

Code:
<?
$columns = 2;

if (isset($_POST['subm']))$ids=implode(",",$_POST['subm']);
$query = ("SELECT * FROM `tablename` WHERE `ID` IN ($ids)");
$result = mysql_query($query);
@$numrows = mysql_num_rows($result);
for($i = 0; $i < $numrows; $i++) {
$row = mysql_fetch_array($result); {

print "<h1 align='center'>Data for " . $row['firstname'] . " " . $row['lastname'] . "</h1>";
print "<table border=2 width='90%' align='center'>";

if($i % $columns == 0) {
//if there is no remainder, we want to start a new row
print "<TR>\n";
}
print "<TD width='50%'>";
print "<b>" . $row['firstname'] . " " . $row['lastname'] . "</b><br>";
print mysql_field_name($result, 0) . ": " . $row['ID']."<br>";
print mysql_field_name($result, 3) . ": " . $row['address']."<br>";
print mysql_field_name($result, 4) . ": " . $row['city']."<br>";
print mysql_field_name($result, 57) . ": " . $row['physician']."<br>";
print mysql_field_name($result, 58) . ": " . $row['drphone']."<br>";
print mysql_field_name($result, 59) . ": " . $row['draddress']."<br>";

if(($i % $columns) == ($columns - 1) ¦¦ ($i + 1) == $numrows) {
print "</td>";
print "<td>";
}
print mysql_field_name($result, 61) . ": " . $row['meds']."<br>";
if ($row['medications']) print mysql_field_name($result, 62) . ": " . $row['medications']."<br>";
print mysql_field_name($result, 63) . ": " . $row['allergy']."<br>";
if ($row['allergies']) print mysql_field_name($result, 64) . ": " . $row['allergies']."<br>";
print mysql_field_name($result, 65) . ": " . $row['limits']."<br>";
if ($row['limitations']) print mysql_field_name($result, 66) . ": " . $row['limitations']."<br>";
print mysql_field_name($result, 88) . ": " . $row['agreedby']."<br>";
print mysql_field_name($result, 89) . ": " . $row['date']."<br>";

print "</td>";
if(($i % $columns) == ($columns - 1) ¦¦ ($i + 1) == $numrows) {
//if there is a remainder of 1, end the row
//or if there is nothing left in our result set, end the row
print "</TR>\n";
}

} // end for loop
} // end row loop
print "</table>\n";

if (!isset($_POST['subm'])){
print "<p>No entry chosen. Please go back and check the box of the entry you want to print the information for. ";
}
mysql_close();
?>

My long range goal is to take each ID's result and add a CSS page break after it so that all of the selected ID's information can be printed out on a printer, each ID on a separate page.

cookie2

8:44 pm on May 11, 2006 (gmt 0)

10+ Year Member



Found answer on another board. Simple adjustment. I had to change

if(($i % $columns) == ($columns - 1) ¦¦ ($i + 1) == $numrows) {

to

if(($i % $columns) == ($columns - 2) ¦¦ ($i + 1) == $numrows) {

Now it works as intended.