开发者

implement a button to send information to another php file?

开发者 https://www.devze.com 2023-01-08 04:52 出处:网络
I\'ve got the following php code printing out the contents of a SQL table. $query=\"select * from TABLE\";

I've got the following php code printing out the contents of a SQL table.

$query="select * from TABLE";
$rt=mysql_query($query);                            
echo mysql_error();                                           
mysql_close();
?>
<i>Name, Message, Type, Lat, Lng, File </i><br/><br/>
<?php
while($nt=mysql_fetch_array($rt)){
if($nt[name] != null){ 
echo "$nt[id] $nt[name] $nt[message] $nt[type] $nt[lat] $nt[lng] $nt[file]";
}
}
?>

How would I implement a button so for each "row" if the button is clicked on that row it'll submit the inf开发者_运维知识库ormation of that row to another php file?

I want it looking something like...

     details details2 details3 BUTTON
     details4 details5 details6 BUTTON
     details7 details8 details9 BUTTON
     details10 details11 details12 BUTTON

Where if BUTTON was hit on row 1 details1,2,3 would be sent to a php file, on row 2 detals 4,5,6 would be sent etc. How would I do this?

Thanks.


it's going to be something like that, depending on the data you need to send:

while($nt = mysql_fetch_array($rt)) {
    if($nt[name] != null){ 
        echo "$nt[id] $nt[name] $nt[message] $nt[type] $nt[lat] $nt[lng] $nt[file] ".'<a href="another_script.php?id='.$nt['id'].'">send request</a><br/>';
    }
}


You can either use GET method and send a query string to the second php page and receive the variables there, like

next.php?variable1=value1&variable2=value2&...

or use POST method by making a hidden form for each row and assign a hidden field for each variable you want to send.

<form method="post" action"next.php">
    <input type="hidden" name="variable1" value="value1" />
    <input type="hidden" name="variable2" value="value2" />
    .
    .
    .
</form>

or instead of sending all the values, just send the row ID (if any) using any of these two methods and run another query in next.php to get the information you need from database.


Instead of submitting the entire data, just send the ID and fetch the results from the database in the other script. If you want to have an input button, you can do

<form action="/other-script.php" method="GET">
    <?php printf('<input type="submit" name="id" value="%s" />', $nt["id"]); ?>
</form>

but you could also just add a link, e.g.

printf('<a href="/other-script.php?id=%s">Submit ID</a>', $nt["id"]);

If you really want to send the entire row values over again, you have to make them into form inputs. In that case, I'd send them via POST though.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号