seriously neeed help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeshurun
Forum Newbie
Posts: 5
Joined: Wed Dec 02, 2009 5:37 am

seriously neeed help!

Post by jeshurun »

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
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: seriously neeed help!

Post by Marinusjvv »

row 2 wld have 4 rows
row 3 wld have 8 rows etc.
Huh?
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: seriously neeed help!

Post by Grizzzzzzzzzz »

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>";
 
?>
 
 
jeshurun
Forum Newbie
Posts: 5
Joined: Wed Dec 02, 2009 5:37 am

Re: seriously neeed help!

Post by jeshurun »

sory but nope the third tr must contain 8 cells
the the 4th must have 16 cells etc
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: seriously neeed help!

Post by timWebUK »

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>";
 
?>
 
That then? Surely you could have figured out from his code that you just had to change the +2 to a *2...
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: seriously neeed help!

Post by Marinusjvv »

Well how many rows are we looking at? This should do it:

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!

Post by Marinusjvv »

@tim: he's looking at 2^$i etc, not 2*$i. which is done with the pow function.
User avatar
timWebUK
Forum Contributor
Posts: 239
Joined: Thu Oct 29, 2009 6:48 am
Location: UK

Re: seriously neeed help!

Post by timWebUK »

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.
Marinusjvv
Forum Commoner
Posts: 29
Joined: Wed Dec 02, 2009 5:59 am

Re: seriously neeed help!

Post by Marinusjvv »

Lol, oh well. He has two working examples to use now.
jeshurun
Forum Newbie
Posts: 5
Joined: Wed Dec 02, 2009 5:37 am

Re: seriously neeed help!

Post by jeshurun »

thanks guys
i wld work on this
Post Reply