View Full Version : displaying output across page
rocg23
11-24-2006, 03:33 PM
I am trying to display 3 across 12 total, but as as you can probably see from my script, it is not working that way. I am getting 3 acroos and 12 total of the first entry in the DB, then 12 of the next...
else if(!isset($_POST['submit'])) //looking at root
// {
$numentries=12;
$start=0;
print "<table align='center' border='0' width='90%'>";
print "<tr><td colspan='3' align='center'><b>Identification Guide</b><br><br></td></tr>";
$ptrnselect="Select * FROM PIECES order by numa LIMIT $start,$numentries";
$ptrnquery=mysql_query($ptrnselect) or die("diesroot");
while($p=mysql_fetch_array($ptrnquery))
{
$j=0;
$y=4;
while ($j < $y) {
++$j;
print "<tr>";
$i=0;
$x=3;
while ($i < $x) {
print "<td align='center' width='33%'>";
print "<a href='index.php?EntryID=$p[EntryID]'><img src='$p[img1]'></a><br>";
print "<font color='#000000'>$p[numa]-$p[numb]-$p[numc]</font><br>";
print "<font color='#000000'>$p[shorttext]</font>";
++$i;
}
print "</td>";
}
print "</tr>";
}
How do I get it move to teh next entry each time?
Ugh, more hideous code. OK.
else if(!isset($_POST['submit'])) {
$numentries = 12;
$start = 0;
$query = mysql_query("select * from pieces order by numa limit $start, $numentries;");
?>
<table style="text-align: center; margin: auto; width: 90%;">
<tr>
<th colspan="3">Identification Guide</th>
</tr>
<?php while($row = mysql_fetch_array($query)) { ?>
<tr>
<td style="color: black;">
<p>
<a href="index.php?EntryID=<?php echo($row['EntryID']); ?>">
<img src="<?php echo($row['img1']); ?>" alt="You need some alt text here!">
</a>
</p>
<p>
<?php echo($row['numa'] . '-' . $row['numb'] . '-' . $row['numc']); ?>
</p>
<p>
<?php echo($row['shorttext']); ?>
</p>
</td>
</tr>
<?php } ?>
</table>
<?php
rocg23
11-25-2006, 12:39 AM
So, it is easier to make it an html page with php in it? How does this repeat?
Thanks Twey
So, it is easier to make it an html page with php in it?All PHP pages are HTML with PHP in them by default. It's a lot easier (and neater) to drop out of PHP parsing mode when outputting large chunks of HTML than it is to echo them all out, fiddling around escaping quotes, and ending up with an unformatted blob of HTML all on one line.
How does this repeat?
<?php while($row = mysql_fetch_array($query)) { ?>
rocg23
11-28-2006, 01:29 PM
ok, I trimmed the code down to
<?php
if(!isset($_POST['submit'])) {
$numentries = 12;
$start = 0;
$query = mysql_query("select * from pieces order by numa limit $start, $numentries;");?>
<table style="text-align: center; margin: auto; width: 90%;">
<tr>
<th colspan="3">Identification Guide</th>
</tr>
<?php while($row = mysql_fetch_array($query)) { ?>
<tr>
<td style="color: black;">
<p>
<a href="index.php?EntryID=<?php echo($row['EntryID']); ?>">
<img src="<?php echo($row['img1']); ?>" alt="<?php echo($row[name]); ?>">
</a>
</p>
<p>
<?php echo($row['numa'] . '-' . $row['numb'] . '-' . $row['numc']); ?>
</p>
<p>
<?php echo($row['shorttext']); ?>
</p>
</td>
</tr>
<?php } ?>
</table>
and I am getting "Parse error: syntax error, unexpected $end in /home/public_html/pieces/index.php on line 30"
I have been working on it for an hour now, and don't have a clue what is wrong.
djr33
11-28-2006, 02:14 PM
Hmm?
There is no "$end", and, that is 29 rows, according to how I counted... maybe I counted wrong...
rocg23
11-28-2006, 02:56 PM
Hmm?
There is no "$end", and, that is 29 rows, according to how I counted... maybe I counted wrong...
You are correct, that is why I am really confused...
djr33
11-28-2006, 03:55 PM
Well, usually when it claims that there is a problem of some sort at the end of the script, there's something wrong with a loop, and it's usually that there is an endless loop or something else to do with the format of the loop being wrong, like a missing bracket...
I am, however, not seeing any errors like this in the code. A semicolon errror can also behave like this (as can a misplaced quote), but I don't see that either.
rocg23
11-28-2006, 04:24 PM
Think I got it this time, Was missing the secong '}' but it is still displaying down, not across like I was origianally looking for.
<?
include "connect.php";
include "admin/variables.php";
print "<body link=$link>";
print "<body vlink=$vlink>";
print "<body bgcolor=$bgcolor>";
if(!isset($_POST['submit'])) {
$rowselect="Select * FROM PIECES order by numa LIMIT 0,12"; ?>
<table style="text-align: center; margin: auto; width: 90%;">
<tr>
<th colspan="3">Identification Guide</th>
</tr>
<? $rowquery = mysql_query($rowselect) or die("diesroot"); ?>
<? while($row = mysql_fetch_array($rowquery)) { ?>
<tr>
<td style="color: black;">
<p>
<a href="index.php?EntryID=<? echo($row['EntryID']); ?>">
<img src="<? echo($row['img1']); ?>" alt="<? echo($row[name]); ?>">
</a>
</p>
<p>
<? echo($row['numa'] . '-' . $row['numb'] . '-' . $row['numc']); ?>
</p>
<p>
<? echo($row['shorttext']); ?>
</p>
</td>
</tr>
<? } ?>
<? } ?>
</table>
djr33
11-28-2006, 06:01 PM
I think you just need to adjust your setup... use <td> elements within a single <tr> element for a row....
This means that the <tr> and </tr> elements should be OUTSIDE the loop, so that you get one row containing multiple rows from the database. As is you get a <tr> and </tr> per result from the DB.
rocg23
11-28-2006, 06:46 PM
i understand exactly what you mean, but I can't figure out how to impliment it. How can I repeat the element 3 times, then go to the next row.
If I repeat the code, it gives me 3 of the same element before jumping to the next row...It isn't the html I have an issue with it is getting the php to output correctly...
At a total loss...I know I have seen it before.
rocg23
11-28-2006, 07:13 PM
Hey and if your bored...I don't know why I am getting an unexpected T_ELSE in line 33. I don't see what I missed...
<?
include "connect.php";
include "admin/variables.php";
print "<body link=$link>";
print "<body vlink=$vlink>";
print "<body bgcolor=$bgcolor>";
if(!isset($_GET['EntryID'])) { ?>
<? $piece="SELECT * FROM PIECES where EntryID='$EntryID'"; ?>
<table style="text-align: center; margin: auto; width: 75%;">
<tr>
<td colspan="2">
<? $piecequery=mysql_query($piece) or die("It died"); ?>
<? while($pq=mysql_fetch_array($piecequery)) { ?>
<font face="arial" size="5"><b><? echo($pg['name']); ?>
</td>
</tr>
<tr>
<td><img src="<? echo($pq['img2']); ?>"></td>
<td valign='top' align='left'><? echo($pq['largetext']); ?>
</td>
</tr>
<? } ?>
</table>
<? } ?>
<?
else if(!isset($_POST['submit'])) {
$rowselect="Select * FROM PIECES order by numa LIMIT 0,12"; ?>
<table style="text-align: center; margin: auto; width: 90%;">
<tr>
<th colspan="3">Identification Guide</th>
</tr>
<tr>
<? $rowquery = mysql_query($rowselect) or die("diesroot"); ?>
<? while($row = mysql_fetch_array($rowquery)) { ?>
<td style="color: black;">
<p>
<a href="index.php?EntryID=<? echo($row['EntryID']); ?>">
<img src="<? echo($row['img1']); ?>" alt="<? echo $row[name] ?>">
</a>
</p>
<p>
<? echo($row['numa'] . '-' . $row['numb'] . '-' . $row['numc']); ?>
</p>
<p>
<? echo($row['shorttext']); ?>
</p>
</td>
</tr>
<? } ?>
</table>
<? } ?>
djr33
11-28-2006, 10:36 PM
Oh. Every 3?
Try this-- untested--
<table><tr>
<?php while ($row = mysql_fetch_array($rowquery)) { ?>
<td>
<p>stuff <?php echo $row['data']; ?> more stuff</p>
</td>
<?php
$three++;
if ($three % 3 == 0) echo "</tr>\n<tr>";
}
?>
</tr></table>
May act kinda weird if you don't have a number of items divisible by three, like 4 items or 5, etc.
To explain:
The basic idea here is in these two lines:
$three++;
if ($three % 3 == 0) echo "</tr>\n<tr>";
First, the variable "three" is just counting the number of entries already passed into the table.
If the remainder of $three/3 is 0 (to check if it's 3, 6, 9...), then echo end row (the first row is opened either in the last loop of 3 or at the very start), a line break (so the html looks right; you can play with this more), then a start row tag (the tag is closed either in the next loop or after the loops at the end.)
rocg23
11-29-2006, 04:15 PM
Great, thanks, I'll let you know what I come up with, but this makes sense.
rocg23
12-01-2006, 06:16 AM
Worked as is...Thanks again.
Oh. Every 3?
Try this-- untested--
<table><tr>
<?php while ($row = mysql_fetch_array($rowquery)) { ?>
<td>
<p>stuff <?php echo $row['data']; ?> more stuff</p>
</td>
<?php
$three++;
if ($three % 3 == 0) echo "</tr>\n<tr>";
}
?>
</tr></table>
May act kinda weird if you don't have a number of items divisible by three, like 4 items or 5, etc.
To explain:
The basic idea here is in these two lines:
$three++;
if ($three % 3 == 0) echo "</tr>\n<tr>";
First, the variable "three" is just counting the number of entries already passed into the table.
If the remainder of $three/3 is 0 (to check if it's 3, 6, 9...), then echo end row (the first row is opened either in the last loop of 3 or at the very start), a line break (so the html looks right; you can play with this more), then a start row tag (the tag is closed either in the next loop or after the loops at the end.)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.