PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I'm working on a version, but having never used mysql, and having used my own private db libraries for so long I'm having to look a lot of functions up (and php.net isn't responding to me right now ) But I'll have at least one version for you soon...
its a fun project... I've never used GET so I've never had the need before...
function produceGetStyleLinks($db_result, $page, $labelColumn, $varsToPass=array())
{
$links = array();
$numColumns = mysql_num_fields($db_result);
for($i=0;$i<$numColumns;$i++)
{
$keysї$i] = mysql_field_name($db_result,$i);
}
// create a default mapping of column names to GET parameters
if (!count($varsToPass))
{
for ($i=0; $i < $numColumns; $i++)
{
$varsToPassї$keysї$i]]= $keysї$i];
}
}
$columnsToPass = array_keys($varsToPass);
while ($row = mysql_fetch_array( $db_result))
{
$aLink = "<a href="http://$page";
$first = TRUE;
for ($i=0;$i<$numColumns;$i++)
{
if (in_array($keysї$i],$columnsToPass))
{
$aLink .= ($first ? "?" : "&");
$first = FALSE;
$alink .= $varsToPassї$keysї$i]]."=".$rowї$keysї$i]]";
}
}
$aLink .= '">'.$rowї$labelColumn]."</a>";
$linksї] = $aLink;
}
return $links;
}
$varsToPass is a mapping of the columnames of your table to the names of the get parameters. it defaults to passing all data retreived by the query, under the same name as the column.
{editted: to fix a missing db_ prefix before one of the $result's}
Don't feel bad, everyone comes at this from different areas and backgrounds. I've been coding for years and while I can craft functions quickly, don't ask me to design a pretty webpage... The best I can do is make sure the php-generated html source looks nice