Loops to output columns
Moderator: General Moderators
Loops to output columns
I almost feel dumb for asking this but what is the logic that would let me output X number of table columns. I have data that if I were to output normally would be about 3 pages long. So I guess I could say that I am trying to shorten it.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Code: Select all
$i=0;
while ($i<10)
{
echo "<td></td>";
}
// tada.we have outputted 10 table columnsAnd a $i++ in there too. heheCharles256 wrote:Code: Select all
$i=0; while ($i<10) { echo "<td></td>"; } // tada.we have outputted 10 table columns
Now, this is the part where I get to a standoff with myself. Where would this go?
Code: Select all
while($row=mssql_fetch_array($result)
{
echo $variable 1 ." - ". $variable2;
}Code: Select all
$x = 10 // number of table columns
$i = 1 // start counter
// proceed with the loop
while($array = mysql_fetch_assoc($result))
{
// check if counter is = to number of table columns
if($i == $x)
{
echo "</tr><tr>";
$i = 0; // reset counter
}
echo "<td>{$array['field']}</td>";
// increment counter
$i++;
}
Last edited by s.dot on Wed Jan 04, 2006 2:35 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Thanks scrotaye! With a little tweakin, I got it to work.
Code: Select all
$x = 10 // number of table columns
$i = 1 // start counter
// proceed with the loop
while($array = mysql_fetch_assoc($result)
{
// check if counter is = to number of table columns
if($i == $x)
{
echo "</tr><tr>";
$i = 0; // CHANGE: I had to reset the counter.
}
echo "<td>{$array['field']}</td>";
// increment counter
$i++;
}ah, yes
I fixed it in my post in case someone else reads this and uses that code
thanks
I fixed it in my post in case someone else reads this and uses that code
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: