faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

45 of 52 people (87%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can i add the First,Previous,Next, Last,Update,Delete,Modify buttons in the same form?(I am using MYSQL as a backend in my server)

Feb 20th, 2008 22:49
dman, Mike Boucher, Arthur Sujith, http://www.ttnr.org


I use control structures such as if -ifelse-else statements or 
switches to look for the value of the named button that was clicked.
EXAMPLE 1:
<FORM>
fields and all the fun stuff....
<INPUT type="submit" name="submit" value="next">
<INPUT type="submit" name="submit" value="prev">
<INPUT type="submit" name="submit" value="update">
...etc
</FORM>
<?
switch ($submit)
{
    case "next":
           myNextFunction();
           break;
    case "prev":
           myPrevFunction();
           break;
    case "update":
           myUpdateFunction();
           break;
    default:
           switchMissingFunction();
           break;
}
......etc
?>
However, if you are using image buttons (<INPUT type="image">), 
I've found that the switch statement doesn't work because the 
variables that are passed by the image button are imgName_x 
and imgName_y, for the x and y coords for the mouse click.
For this I do:
EXAMPLE 2:
<FORM>
fields and all the fun stuff....
<INPUT type="image" src="1.gif" name="next">
<INPUT type="image" src="2.gif" name="prev">
<INPUT type="image" src="3.gif" name="update">
...etc
</FORM>
<?
if ($next_x > "0")
{
     myNextFunction();
}
elseif ($prev_x > "0")
{
     myPrevFunction();
}
elseif ($update_x > "0")
{
     myUpdateFunction();
}
else
{
     switchMissingFunction();
}
....etc
?>
Best of Luck!