hi,

I want to display the mysql records in to row and column....like

user1   user2  user3
10        20       30

where this users are dynamic and the rows also.

here is the code

$sql=mysql_query("select * from report,admin_table where report.admin_id=admin_table.admin_id and which_day='".date('Y-m-d')."' ") or die(mysql_error());	

while($row=mysql_fetch_array($sql))
{ 
 $admin_name=$row['admin_name'];
 $activity=$row1['activity'];
}

Now it should look like

admin_name 1            admin_name 2     
abc                              xyz

Please suggest...Thanks in advance.

Raj

Do you just want a blurb accross the screen or do you want to look good in an html format?
For html use a table , then populate the cells with the loop with embedded php.

Hi Jrm,

Thanks for your suggestion...actually i am trying to achieve something else..bit complicated.

I would like to make a html table like this

timeslots            User1          User2      User3       User4    
8am-9am            work            work       work        work

9-10                

10-11

...
...
...

17-18

also I have made this multidimensional array

Array
(
[az] => Array
(
[dsdsds] => Array
(
[2010-02-02 2:47 PM 2010-02-02 2:55 PM] => 8
)

)

[an] => Array
(
[sdsdsdsdsd] => Array
(
[2010-02-02 1:47 PM 2010-02-02 2:47 PM] => 60
)

)

[mu] => Array
(
[sdsdsd] => Array
(
[2010-02-02 1:30 PM 2010-02-02 2:48 PM] => 78
)

)

[raj] => Array
(
[dsdwew] => Array
(
[2010-02-02 3:34 PM 2010-02-02 3:40 PM] => 6
)

[cdsfdfdfd] => Array
(
[2010-02-02 3:25 PM 2010-02-02 3:35 PM] => 10
)

)

)

and my code is;

$sql=mysql_query("select * from report,admin_table where report.admin_id=admin_table.admin_id and which_day='".date('Y-m-d')."' ") or die(mysql_error());	
  
$tot=mysql_num_rows($sql);
 
 		  
while($row=mysql_fetch_array($sql))
{ 
 $admin_name=$row['admin_name'];
 $admin_id=$row['admin_id'];
  
$activity=$row['activity'];
 
 $start_time=$row['start_time'];
$end_time=$row['end_time'];
$time=$start_time." ".$end_time; 
$total_value=$row['total_value'];
 
$test_array[$admin_name][$activity][$time] = $total_value; 
 
}

Now the problem is i can't put the above array output into html table

Now the problem is i can't put the above array output into html table

try this:

<td> <?php echo $admin_name ;?></td>

I tried to put into loops in html but i have lost.

it might be something like this

foreach ($test_array as $name => $works)
{
    print('<tr><td rowspan="' . count($works) . '">' . htmlentities($name ) . '</td>');

    foreach ($works as $i => $work)
    {
        // If $i == 0, we've already printed the <tr> before the loop
        if ($i)
            print('<tr>');

        print('<td>'.$work.' </td></tr>');
    }
}

Just to make the array elements into td and tr...thats it..

Yes but don't use print.
You can cascade the whole thing into one big echo statement embedded into the table.

echo"<tr><td>{$work} </td></tr>";

It doesnt work...I would like to display in this way

user1      user2     user3
ddd          eee        rrr

That was an example only, not a working code to display in your format.
Before the loop make the header titles, then loop out the rows under those titles.

echo " <tr><td> {$var1}</td><td> {$var2}</td><td> {$var3}</td></tr>"

That was an example only, not a working code to display in your format.
Before the loop make the header titles, then loop out the rows under those titles.

echo " <tr><td> {$var1}</td><td> {$var2}</td><td> {$var3}</td></tr>"

How can I get $var1,$var2... and put as header columns from the multidimensional array i have created...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.