""McShen"" <[EMAIL PROTECTED]> wrote in message
9h3lrv$dn$[EMAIL PROTECTED]">news:9h3lrv$dn$[EMAIL PROTECTED]...
> Hi
>
> I have a script which queries mySQL and outputs 32 links at once.
How 'bout this?
=======================================
define("PER_ROW", 2);
$row = Array();
$in_row = 0;
// accepts nothing, returns nothing
function ClearRow() {
global $in_row;
$in_row = 0;
}
// accepts text string, returns true if row is full
function AddToRow($val) {
global $row, $in_row;
$row[$in_row++] = $val;
return($in_row >= PER_ROW);
}
// accepts nothing, returns row string
function MakeRow() {
global $row, $in_row;
$str = "";
for ($i = 0; $i < PER_ROW; $i++)
$str .= "\n\t\t<td>".($i < $in_row ? $row[$i] : "")."</td>";
ClearRow();
return "\n\t<tr>$str\n\t</tr>";
}
// accepts database result handle, returns table string
function MakeTable($result) {
$str = "";
while($row = mysql_fetch_array($result))
if (AddToRow($row["title"]))
$str .= MakeRow();
return "\n<table border=\"0\">$str\n</table>";
}
$query = "SELECT * FROM refer ORDER BY hits, desc LIMIT $list, $end";
$result = mysql_db_query ("celebzone", $query);
ClearTable();
echo MakeTable($result);
====================================
This separates things out so you can see that each pair of tags matches; it
also doesn't leave incomplete rows in your table (ie if there is an odd
number of links returned) and makes it easy to change the number of columns
and rows.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]