Converting this to a function
Posted: Wed Aug 21, 2002 12:33 pm
I'd like to convert the following to a generic function which will return a an array of links which pass variables in the url
I'm having some trouble abstracting it to the most basic components, thus they are the hard coded items...
This is the code as it is in procedural form
I'm having some trouble abstracting it to the most basic components, thus they are the hard coded items...
This is the code as it is in procedural form
Code: Select all
$lenRows =0;
$fieldName = array();
$link = array();
$page ='localhost:8008/msc/ud6.php';
$sql = "SELECT rec_code, item_name FROM menu_item";
$result = mysql_query($sql) or die ( mysql_error());
// place query results in rows array
$rows = array();
while( $row = mysql_fetch_array( $result))
{
$rowsї] = $row;
}
//place field names in fieldName array
$numFields = mysql_num_fields($result);
for($i = 0; $i < $numFields; ++$i)
{
$fieldNameї] = mysql_field_name($result, $i);
}
//assign $lenRows the size of $rows array
$lenRows = count($rows);
for($i = 0; $i < $lenRows; ++$i)
{
$linkї] = '<a href=http://'. $page . '?recCode=' . $rowsї'$iї$i]ї0] . '&itemName=' . $rowsї$i]ї1] .">" . $rowsї$i]ї1] . "</a>";
}