Trying to Show 87 mysql rows in 3 html tables using PHP and mysql [closed]
I current have a table in my database called (links) I am trying to get all the rows to show url_link i have 87 rows in links i am trying to get them to display in 3 html tables so that means 29 links in each table how would i do this in php with out writen out each table and it would auto put the links in the box?
Column 1
<table width="183" border="0" align="left" cellpadding="0" cellspacing="0">
<tr>
<td width="183">Text1</td>
</tr>
<tr>
<td>Text2</td>
</tr>
</table>
etc...
I know how to do query in PHP I just don't know how to start a new html table and then end it when it has 29 query in it and then start a new table.
This is almost an exact duplicate of your other question. This is trivial to solve, just look into basic mysql queries and loops. You clearly haven't done the work to even look into how to do a query in PHP, I suggest you start there.
Well, you could do something like this I suppose (very ugly - your example showed 1 column tables??) Also, this is untested, and probably not a very good way to do this.
$counter = 0;
$totalcounter = 0;
$total = count($yourarray);
foreach($yourarray as $key => $value){
if($total == $totalcounter){
echo '<tr><td>'.$value.'</td></tr></table>';
break;
}
if($counter == 0){
echo '<table width="183" border="0" align="left" cellpadding="0" cellspacing="0">';
echo '<tr><td>'.$value.'</td></tr>';
$counter++;
}
elseif($counter == 29){
echo '<tr><td>'.$value.'</td></tr></table>';
$counter = 0;
}
else{
echo '<tr><td>'.$value.'</td></tr>';
$counter++;
}
$totalcounter++
}
I would split the array into three equal pieces, and then have a separate foreach, for each new array.
1) Use prepared statements to SELECT
the data from the database
2) Place data into an associative array with mysql_fetch_assoc
3) Loop through the data and place them in td
tags:
$tds = '';
for($assoc_array as $key => $value) {
$tds .= '<td>' . $value . '</td>';
}
4) echo $tds
in the correct place in the table.
精彩评论