seriously neeed help!
Moderator: General Moderators
seriously neeed help!
i am working on a php/mysql project and right now i am stuck and need help fast.
what i want to do is echo out a row with 2n cells what i mean is:
row1 wld have 2 cells
row 2 wld have 4 rows
row 3 wld have 8 rows etc.
my php codes are :
<?php
echo "table border=1>";
require_once "connector.inc" - # for the connector strings
require_once "tree.inc" - # for the mysql commands which is just a normal MySQL SELECT query
if($result=mysql_query($sql)){
while($row=mysql_fetch_assoc($result)){
$count=1; - # to initiate the count for the number of cells i want
echo "<tr>";
$ab =pow(2,$count); - #to limit the number of cells per row
$i=1;
do{
echo "<td>";
echo $i;
$studentname=current($row);
echo $studentname;
echo "</td>";
}
i++;
echo "</tr>";
}
}
}
echo "</table>";
I have tried to find out what i am doing wrong but i don;t seem to get it.
I wld love to use OOP but right now, i am still studying it.
Thanks alot for your help
what i want to do is echo out a row with 2n cells what i mean is:
row1 wld have 2 cells
row 2 wld have 4 rows
row 3 wld have 8 rows etc.
my php codes are :
<?php
echo "table border=1>";
require_once "connector.inc" - # for the connector strings
require_once "tree.inc" - # for the mysql commands which is just a normal MySQL SELECT query
if($result=mysql_query($sql)){
while($row=mysql_fetch_assoc($result)){
$count=1; - # to initiate the count for the number of cells i want
echo "<tr>";
$ab =pow(2,$count); - #to limit the number of cells per row
$i=1;
do{
echo "<td>";
echo $i;
$studentname=current($row);
echo $studentname;
echo "</td>";
}
i++;
echo "</tr>";
}
}
}
echo "</table>";
I have tried to find out what i am doing wrong but i don;t seem to get it.
I wld love to use OOP but right now, i am still studying it.
Thanks alot for your help
-
Marinusjvv
- Forum Commoner
- Posts: 29
- Joined: Wed Dec 02, 2009 5:59 am
Re: seriously neeed help!
Huh?row 2 wld have 4 rows
row 3 wld have 8 rows etc.
- Grizzzzzzzzzz
- Forum Contributor
- Posts: 125
- Joined: Wed Sep 02, 2009 8:51 am
Re: seriously neeed help!
guessing you're trying to do something like this
Code: Select all
<?php
echo "<table border=\"1\">";
$num1 = 0;
$num2 = 2;
for ($number = 1; $number < 11; $number++)
{
echo "<tr>";
while ($num1 < $num2)
{
echo "<td>Whatever</td>";
$num1++;
}
echo "</tr>";
$num1 = 0;
$num2 = $num2 + 2;
}
echo "</table>";
?>
Re: seriously neeed help!
sory but nope the third tr must contain 8 cells
the the 4th must have 16 cells etc
the the 4th must have 16 cells etc
Re: seriously neeed help!
Code: Select all
<?php
echo '<table>';
//Edit number of rows:
$numOfRows = 10;
$num1 = 0;
$num2 = 2;
for ($number = 0; $number < $numOfRows; $number++)
{
echo "<tr>";
while ($num1 < $num2)
{
echo "<td>Whatever</td>";
$num1++;
}
echo "</tr>";
$num1 = 0;
$num2 = $num2 * 2;
}
echo "</table>";
?>
-
Marinusjvv
- Forum Commoner
- Posts: 29
- Joined: Wed Dec 02, 2009 5:59 am
Re: seriously neeed help!
Well how many rows are we looking at? This should do it:
for 8 rows..
for 8 rows..
Code: Select all
<table border="1">
<?php
for($i=1; $i<=8; $i++)
{
$k = pow(2, $i);
echo "<tr>";
for($j=0; $j<$k; $j++)
{
echo "<td>Something</td>";
}
echo "</tr>";
}
?>
</table>
Last edited by Marinusjvv on Wed Dec 02, 2009 10:18 am, edited 1 time in total.
-
Marinusjvv
- Forum Commoner
- Posts: 29
- Joined: Wed Dec 02, 2009 5:59 am
Re: seriously neeed help!
@tim: he's looking at 2^$i etc, not 2*$i. which is done with the pow function.
Re: seriously neeed help!
Either it works out the same:
2 x 2 = 4, x 2 = 8, x 2 = 16, x 2 = 32.
2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, etc.
2 x 2 = 4, x 2 = 8, x 2 = 16, x 2 = 32.
2^1 = 2, 2^2 = 4, 2^3 = 8, 2^4 = 16, etc.
-
Marinusjvv
- Forum Commoner
- Posts: 29
- Joined: Wed Dec 02, 2009 5:59 am
Re: seriously neeed help!
Lol, oh well. He has two working examples to use now.
Re: seriously neeed help!
thanks guys
i wld work on this
i wld work on this