php-general | 2001062
Date: 06/24/01
- Next message: Carmen & Gene: "[PHP] filemtime function not working"
- Previous message: Hugh Bothwell: "Re: [PHP] CORRECT sort"
- In reply to: McShen: "[PHP] ->>coding help"
- Next in thread: Richard Lynch: "Re: [PHP] ->>coding help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
""McShen"" <webmaster <email protected>> wrote in message
news:9h3lrv$dn$1 <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: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Carmen & Gene: "[PHP] filemtime function not working"
- Previous message: Hugh Bothwell: "Re: [PHP] CORRECT sort"
- In reply to: McShen: "[PHP] ->>coding help"
- Next in thread: Richard Lynch: "Re: [PHP] ->>coding help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

