增加值按钮 [英] Increase in Value button

查看:123
本文介绍了增加值按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够创建一个按钮来增加 upvotes 的数量并减少 downvotes的数量

  $ result = mysqli_query($ con,SELECT * FROM champion_counters_b WHERE champion_name ='。$ search_result。'); 

echo< table class ='champion_counters'border ='1'>< tr>< th> Champion Counter< th> th投票< / th>< th ; th>向下投票< / th>< / tr>;
while($ row = mysqli_fetch_array($ result)){
echo< tr>;
回显< td> 。 $ row ['champion_counter']。 < / TD> 中;
回显< td> 。 $ row ['upvotes']。 < / TD> 中;
回显< td> 。 $ row ['downvotes']。 < / TD> 中;
}

echo< / table>;

正如您所看到的,我目前正在回显表格,直到没有为输入留下搜索结果。正如你可以看到 $ row ['upvotes'],$ row ['downvotes'] 这些是我希望能够生成按钮的东西,

 Upvote=> upvotes + 1 => 1,2,3等
Downvote=> downvotes - 1 => -1,-2,-3等

tl; dr:想成为能够为每一行生成按钮以增加upvotes的数量并减少downvotes的数量

解决方案

不是你要找的,但据我了解,这将是我的解决方案:

你可能在你的数据库中最可能有某种主键。在执行SELECT *时,您确实可以在这里找到它。检索所有列。



基于主键,您现在可以实现您的down-up和upvoting功能。例如,你可以在你的while循环中插入以下内容(让$ row ['key']为主键):

  echo< td>< a href ='action.php?do = up& id =。 $ row ['key']。 >给予好评< / A>< / TD>中; 
echo< td>< a href ='action.php?do = down& id =。 $ row ['key']。 > Downvote< / A>< / TD>中;

使用这种方式,每个表格行都会有两个链接,它们会将用户发送到action.php并附加一些GET参数到URL。 GET参数是do,它会告诉你该做什么(向上或向下)和id,这是主键。



在行动.php,您可以读取这些GET参数并执行任何进一步的操作,例如更新数据库。你可以像这样得到它们:

  $ action = $ _GET ['do']; 
$ id = $ _GET ['id'];

根据$ action,您现在可以更新downvotes或upvotes。您可以使用$ id标识要更新的项目。


I wish to be able to create a button that increase the number of upvotes and decreases the number of downvotes

$result = mysqli_query($con, "SELECT * FROM champion_counters_b WHERE champion_name='" . $search_result . "'");

echo "<table class='champion_counters' border='1'><tr><th>Champion Counter</th><th>Up Votes</th><th>Down Votes</th></tr>";
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['champion_counter'] . "</td>";
    echo "<td>" . $row['upvotes'] . "</td>";
    echo "<td>" . $row['downvotes'] . "</td>";
}

echo "</table>";

As you can see, I am currently echoing a table until there are no search results left for the input. As you can see $row['upvotes'], $row['downvotes'] these are the things that i'd like to be able to generate a button for, on each row.

"Upvote" => upvotes + 1 => 1, 2, 3, etc
"Downvote" => downvotes - 1 => -1, -2, -3, etc

tl;dr: Would like to be able to generate buttons for each row to increase the number of upvotes and decrease the number of downvotes

解决方案

This might not be what you are looking for, but as far as I understood, this would be my solution:

You will most probably have some kind of primary key in your database. You do actually get it here as you perform a "SELECT *", e.g. retrieve all columns.

Based on the primary key, you can now implement your down- and upvoting functionality. You could for example insert the following into your while-loop (let $row['key'] be the primary key):

echo "<td><a href='action.php?do=up&id=" . $row['key'] . "'>Upvote</a></td>";
echo "<td><a href='action.php?do=down&id=" . $row['key'] . "'>Downvote</a></td>";

Using this, each table row will have two links which will send the user to an action.php and append some GET-Parameters to the URL. The GET-Parameters are "do", which will tell you what to do (either up or down) and "id", which is the primary key.

In action.php, you can read those GET-Parameters and perform any further action, like updating the database. You can get them like this:

$action = $_GET['do'];
$id = $_GET['id'];

Depending on $action, you can now update the downvotes or the upvotes. You can identify the item to update with $id.

这篇关于增加值按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆