Closed Thread Icon

Topic awaiting preservation: Several actions in same page (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12275" title="Pages that link to Topic awaiting preservation: Several actions in same page (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Several actions in same page <span class="small">(Page 1 of 1)</span>\

 
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-20-2002 09:38

Hello!
little question: Let's say I have a page with 4 buttoms.

Buttom 1 prints all the table A content (select * from tabla A etc etc...)

Buttom 2 inserts into table B some data (a form in the same page, I.E.)

Buttom 3 deletes from Table C

And so on...
Can I have all the 'functions' in the same page? if bottom A is clicked do this, if it's bottom B do this other and so on??
I ask for this because I've always made another page to process all the stuff......


So, I have no idea on how to do this.

Thanks in advance!

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 06-20-2002 10:37

sure
I usually assign an action integer to each button
ie:
button0 > intAction = 0
button1 > intAction = 1
button2 > intAction = 2 etc.

when each button is clicked, it passes the its action value either in a hidden variable or querystring back to the page where the value is retrieved and you figure out which database activity needs to be performed with a simple select case or switch statement depending on which language you're using

hth
I:.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-20-2002 10:45

Oh!! i got it!!!

So, a hidden value and into the 'proccess.php' some kind of select case to choose the action to perform!!!

Thanks!!!

someoneInverse
Bipolar (III) Inmate

From:
Insane since: May 2002

posted posted 06-20-2002 11:33

exactly that
glad to help
I:.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-20-2002 22:46

Query strings work as well. Using 4 forms.

code:
<form action="#?action=1" method="post">
<input type="submit" value="Button 1">
</form>

<form action="#?action=2" method="post">
<input type="submit" value="Button 2">
</form>

...



to go along with that:

code:
<?php
function printForm($buttonName, $actionNumber)
{
echo '<form action="#?action=' . $actionNumber .'" method="post">\n";
echo '\t<input type="submit" value="' . $buttonName . '">\n";
echo '</form>\n"
}
?>



Then you would just need to catch the result at the top.

code:
if($action)
{
switch ($i)
{
case 0:
$sql = "case 0 sql";
break;
case 1:
$sql = "case 1 sql";
break;
default:
$sql = "default sql or some other function";
break;
}
}



Just keep it fun!



[This message has been edited by WarMage (edited 06-20-2002).]

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-20-2002 23:23

I'm having fun WarMage!

Edit:


[This message has been edited by Wakkos (edited 06-23-2002).]

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-22-2002 19:18
code:
if($action)
{
switch ($i)
{
//caso 0: borrar el registro
case 0:
$query_darAlta = "INSERT INTO post SELECT * ";
$query_darAlta .= "FROM espera WHERE ID = " . $hola . "";
$result_darAlta = mysql_query($query_darAlta) or die ("Could not query.");
$num_darAlta = mysql_num_rows($result_darAlta);
$row = mysql_fetch_array ($result_darAlta);
break;
//caso 1: damos de alta el registro
case 1:
$query_delete = "delete from espera where ID = " . $hola . " ";
$result_delete = mysql_query($query_delete, $link);
break;
default:
$sql = "default sql or some other function";
break;
}
}



I have the form as you told me (action=index.php?action=0, action=1 and so on...) but it just work with the number 0, the number 1 plays the #0 action!

[editing your code, you shouldn't use tabs in here try 4 spaces per tab instead]

[This message has been edited by WarMage (edited 06-23-2002).]

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-23-2002 04:12

Maybe try switing $action instead of $i

In the code as far as I can see $action has no value.

I didn't check but when checking an empty value for an integer it may default underfined to 0... but I am not sure. I am going to check that out with some test runs.

Yeah I ran the checks, and on a switch statement on an undefined variable it defaults to 0 instead of the actual default. Kinda dumb. Off to see about filing a bug report.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-23-2002 08:38

Duh... PHP does have an undefined. String are empty integers are 0.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-23-2002 08:51

I'm trying with a simple IF to select the action, makeing this:


$borrar = "borrar";
$aceptar = "aceptar";
echo "<FORM action='process.php?script=".$borrar."' method=post><input type=hidden name=hola value=$hola><INPUT TYPE=submit VALUE=borrar></form>\n";
echo "<FORM action='process.php?script=".$aceptar."' method=post><input type=hidden name=hola value=$hola><INPUT TYPE=submit VALUE=ingresar></form>\n";


then in the process.php

If ($script = "borrar") {

echo "blah blah blah";
}

elseif ($script = "aceptar") {
echo "blah 2"; }
else {
echo "hola";
}


And the variable takes always the first value ($borrar)

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 06-23-2002 16:57

If ($script == "borrar") {

echo "blah blah blah";
}

elseif ($script == "aceptar") {
echo "blah 2"; }
else {
echo "hola";
}

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 06-23-2002 20:52

heheh, i just discovered: == (2, no 1)

« BackwardsOnwards »

Show Forum Drop Down Menu