need help with function problem..

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!

Moderator: General Moderators

Post Reply
robin1
Forum Newbie
Posts: 20
Joined: Thu Aug 01, 2002 4:36 pm

need help with function problem..

Post by robin1 »

Hello everybody, I need some help with this code. my code works.. what i'm trying to do is (classified program)display available categorys for a user to click on. after clicking a category the script should display the items available.
the function display_cat() is designed to do this and it works by itself but i need to put this in a function and have it work with rest of the script. it displays the first set of items but if i click next it returns back to the main screen(category screen).. I need a way to keep it going until i click exit to exit the function to return to main menu...please help

what i have soooo far: http://www.comgen.ca/phptest/mainclas.php
<?PHP
function displaying_cat($sendwhat)//receiving selected category to list items
{
$linkid = mysql_connect($mylocalhost,$user,$password);
@mysql_select_db($database) or die( "not able to connect to database $database");

$limit=3; // rows to return
$numresults=mysql_query("select dbcategory from $table1 where dbcategory = '$sendwhat'", $linkid);
$numrows=mysql_num_rows($numresults);
// next determine if offset has been passed to script, if not use 0

if (empty($offset)) {
$offset=0;
}
// get results

$result=mysql_query("select dbitemnum, dbprice, dbcategory from $table1 where dbcategory = '$sendwhat' limit $offset,$limit");
// next we need to do the links to other results
if ($offset > 0) { // bypass PREV link if offset is 0
$prevoffset=$offset-$limit;
print "<a href=\"$PHP_SELF?offset=$prevoffset\">PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"$PHP_SELF?offset=$newoffset\">NEXT</a><p>\n";
}
// now you can display the results returned
echo "return home";
$exiting=0;
echo "<a href=\"$PHP_SELF?exiting=$exiting\">EXIT</a><p>\n";
echo "<hr>";

while ($data=mysql_fetch_row($result)) {
list($fname, $lname, $points) = $data;
// echo"<br>Number $fname<br>Desc: $lname<br>Price: $points<br>";
?>
<table width="400" border="1" cellspacing="0" cellpadding="0">
<tr>
<th><font size="2">item# </font></th>
<th><font size="2">description </font></th>
<th><font size="2">price </font></th>
</tr>
<tr>
<th><font size="2"> <? echo "$fname"; ?> </font></th>
<th><font size="2"> <? echo "$lname"; ?> </font></th>
<th><font size="2"> <? echo "$points"; ?> </font></th>
</tr>
</table>
<br>
<?PHP
}
echo "<hr>";
mysql_close();
echo "$cat";
} //end of function

if(isset($cat)) //1
{
echo displaying_cat($cat); // this is the function the above code. get whats under the selected category. and would like to stay within the function until i exit but still able to go back and forth to view the the items under the category..
http://www.comgen.ca/phptest/mainclas.php

} //

else
{rest of the code..
the main/first thats displayed is codeed in here}
?>
Post Reply