Jump to content

records in a table when td = 3 new row


jesushax

Recommended Posts

Its fairly simple, I won't give it all away though ;)

 

<?php

$tbl = "<table><tr>";

$mydata = array('A', 'B', 'C');

foreach ($mydata as $data) {
$tbl .= "<td>{$data}</td>";
}

$tbl .= "</tr></table>";

echo $tbl;
?>

 

You don't have to use an array, this could be a row call to a database and a completly different loop but you get the idea?

Link to comment
Share on other sites

Hope this will help you  ;) ;) ;) ;)

 

<?php
$data="";

$data .="<tr><td><table><tr>";
for($i=1;$i<=10;$i++)
    {
        $data .="<td> $i </td>";
        
        if($i%3 ==0)
        {
         $data .="</tr><tr>";    
        }
    }
$data .="</table></td></tr>";    
echo $data;
?>

Link to comment
Share on other sites

bah im confused, cant work either of the above out, the second one gives numbers from 1-10 in teh right way but i dont know where to put my records and the first one doesnt count the records just puts them in a td.... im tryign to figure it out here, bt not so much luck lol

Link to comment
Share on other sites

:o :o :o :o :o :o :o :o

 

;) ;) ;)Look below code

<?php

$res="select * from table";
$res=mysql_query($res);
$data="";

$data .="<tr><td><table><tr>";
while($row=mysql_fetch_array($res))
    {
        $data .="<td>". $row['id']." </td>";
        $data .="<td>". $row['name']." </td>";
        $data .="<td>". $row['phone']." </td>";
        
        if($i%3 ==0)
        {
         $data .="</tr><tr>";    
        }
    }
$data .="</table></td></tr>";    
echo $data;
?>

Link to comment
Share on other sites

i see isee, gettign somewhere now but look the below

 

im trying to get the PortTitle to display 3 times then move down to the next row and prtin it 3 more times but obviously the next record

 

<?php

include($_SERVER['DOCUMENT_ROOT'] . '/includes/connection.php');

$res = mysql_query("SELECT * FROM tblPortfolio WHERE PortType='Web' ORDER BY PortDateAdded DESC") or die(mysql_error());
$data="";

$data .="<tr><td><table><tr>";
while($row=mysql_fetch_array($res))
    {
        $data .="<td>". $row['PortTitle']." </td>";
        
        if($i%3 ==0)
        {
         $data .="</tr><tr>";    
        }
    }
$data .="</table></td></tr>";    
echo $data;
?>

Link to comment
Share on other sites

Look at this example please cheers.

<?php
$test1=array("php"=>"title1","mysql"=>"tittle2","html"=>"title3");

foreach($test1 as $key => $val){

$data1=$key;
$data2=$val;

$data="<table><tr><td>$data1</td><tr>$data2</tr></tr></table><br><br>";

echo $data;
}
?>

 

another example showing the table off same info twice.

<?php
$test1=array("php"=>"title1","mysql"=>"tittle2","html"=>"title3");

foreach($test1 as $key => $val){

$data1=$key;
$data2=$val;

for($i=0; $i<2; $i++){

$data="<table><tr><td>$data1</td><tr>$data2</tr></tr></table><br><br>";

echo $data;
}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.