Yeah, I saw, after a closer look, that you have the function defined in separate "if" blocks. Still, there's no need to define it more than once.
Using "global" in a function more often than not defeats one of the main purposes of functions, reusability. Instead, pass the values to the function.
It looks like you want "$picrows to be the same throughout the script, so why define it several times?. Define it once, near the top of the script or in a configuration file, where it can be easily found and changed.
The display_pics() function also does two things. It retrieves data, and constructs a display. This again is against a purpose of functions. Divide it into two functions, passing only the needed variables to each one.
Something like this should work (the second function is pared down to more clearly demonstrate):
function fetch_query_result($result)
{
$num = mysql_num_rows($result);
while ($row = mysql_fetch_array($result);
$result_array['id'][] = $row['id'];
$result_array['catagory'][] = $row['catagory']; // Synonym for "category"?
$result_array['image'][] = $row['image'];
}
return $result_array;
)
function display_pics($pics_arr, $columns) // Add needed html to this function.
{
$rows = 1 + round(count($pics_arr) / $columns);
for ($r = 0; $r < $rows; $r++) {
echo '<tr>';
foreach ($pics_arr as $each) {
echo '<td align="center" valign="top" bgcolor="#000000">';
. '<img src="http://diahannphillips.com/images/stock/' . $pics_arr['image'] . '" border="0"></td>';
}
echo "</tr>";
}
}
Perform the queries and pass the resource handle to the first function. Then pass the array returned from that to the second function. The array will contain the images, and other data you can use elsewher.
I'll look at it some more a little later.