Page 1 of 1

Dynamic button

Posted: Mon May 29, 2006 10:33 am
by a94060
Hi,
i was wondering,what code would i use to make a dynamic button that,when pressed,will do soemthing for that entry?

i want these to be retrieved from the database. So i call them and put them into an array,my question is,how would i make the value go into a button?

Code: Select all

while($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
		
		echo '<input name="validated" type="submit" value="Validated"' />//im not sure what to put here
}
i think i am going along the lines of what i need to do but i need to know what to do at the commented area so that i can use the value of $array['remove'] there.

Re: Dynamic button

Posted: Mon May 29, 2006 10:36 am
by hawleyjr

Code: Select all

while($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
		
		echo '<input name="validated" type="submit" value="Validated"' />//im not sure what to put here
}

Are you just trying to do this:

Code: Select all

echo '<input name="validated" type="submit" value="' . $array['remove']. '"' />//im not sure what to put here

Posted: Mon May 29, 2006 10:41 am
by a94060
yep,that seems almost what i want to do,i want to pass the value to another script,wwith an action also. Would it be liek

Code: Select all

echo '<input name="validated" type="submit" value=remove.php?action=remove&"' . $array['remove']. '"' />//im not sure what to put here
like that?

Posted: Mon May 29, 2006 10:44 am
by hawleyjr
No,

You need to put the action in the form element:

Code: Select all

<form action="remove.php">
<?php
while($array = mysql_fetch_array($result,MYSQL_ASSOC)) { 
echo '<input name="validated" type="submit" value="' . $array['remove']. '"' />
} 
?>
</form>

Posted: Mon May 29, 2006 11:38 am
by a94060
so then in the value,all i put is a


Code: Select all

<form action="remove.php">
<?php
while($array = mysql_fetch_array($result,MYSQL_ASSOC)) {
echo '<input name="validated" type="submit" value="'?action=remove . $array['remove']. '"' />
}
?>
</form>
wont that be something like it because i want all of the entrys to be sent with the action remove so i i can do that in my next script.

Posted: Mon May 29, 2006 11:45 am
by hawleyjr
If you want the value sent to be named: action

Then change the name of your button to: action

/* When doing stuff like this some people store the value in a hidden field and set the desired value via javascript.

Posted: Mon May 29, 2006 11:55 am
by a94060
I thought of a simpler way to do it. Can i jus make them as links?
Would this make the link,assuming that i have the $array working?

Code: Select all

echo '<tr><a href=do.php?act=approve&entry='.$array['id']>Approve</a></tr>;