Discussion:
Lining up items on page
Ethan Rosenberg
2014-07-30 03:36:34 UTC
Permalink
Dear list -

I wish to align my output.

An example-

fprintf($fptr1, "%s\t %s\t\n", $row1[0],$row1[1]);

In each row of output if the strings are wider than the tab setting, the
text will indent.

Is there anyway I can formulate the fprinf so that each string will
print at a specific place?

TIA

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2014-07-30 03:52:33 UTC
Permalink
Post by Ethan Rosenberg
Dear list -
I wish to align my output.
An example-
fprintf($fptr1, "%s\t %s\t\n", $row1[0],$row1[1]);
In each row of output if the strings are wider than the tab setting, the
text will indent.
Is there anyway I can formulate the fprinf so that each string will
print at a specific place?
TIA
Ethan
Why not use a table?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2014-07-30 04:00:24 UTC
Permalink
Post by Ethan Rosenberg
Post by Ethan Rosenberg
Dear list -
I wish to align my output.
An example-
fprintf($fptr1, "%s\t %s\t\n", $row1[0],$row1[1]);
In each row of output if the strings are wider than the tab setting, the
text will indent.
Is there anyway I can formulate the fprinf so that each string will
print at a specific place?
TIA
Ethan
Why not use a table?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
If you know that the upper limit of the strings you can do:

echo sprintf("%-30s %s", $row1[0],$row1[1]);
Ethan Rosenberg
2014-08-01 04:05:46 UTC
Permalink
Post by Jim Giner
Post by Ethan Rosenberg
Dear list -
I wish to align my output.
An example-
fprintf($fptr1, "%s\t %s\t\n", $row1[0],$row1[1]);
In each row of output if the strings are wider than the tab setting, the
text will indent.
Is there anyway I can formulate the fprinf so that each string will
print at a specific place?
TIA
Ethan
Why not use a table?
Jim -
Thanks.
I am outputting to a file. OK - put the data into a table. How do
output it to a file, which I will then print.
TIA
Ethan
Jim -

This is my solution --
$fptr1 = fopen("to-order.txt", "w+");
$sql1 = "select UPC, manuf, item, quant, stock from Inventory where
ordrpt_flag = 1";
$result1 = mysqli_query($cxn, $sql1);

?>
<div align="center">
<table border="4" cellpadding="5" cellspacing="55" rules="all" frame="box">
<tr class='heading'>
<th>To Order</th>
<th>UPC</th>
<th>Manufacturer</th>
<th>Item</th>
</tr>
<?php
while ($row1 = mysqli_fetch_row($result1))
{
?>

<tr>
<td> <?php echo $row1[4] -$row1[3] ; ?> </td>
<td> <?php echo $row1[0]; ?> </td>
<td> <?php echo $row1[1]; ?> </td>
<td> <?php echo $row1[2]; ?> </td>
</tr>

<?php
fprintf($fptr1, "%s\t %s\t %-9s\t %s\t\n", $row1[4] -$row1[3],
$row1[0],$row1[1],$row1[2] );
}
?>
</table>

Not too elegant, but it works.

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...