简体   繁体   English

单击链接将值提交到SQL SELECT

[英]Clicked link submit value to SQL SELECT

I am trying to get this to allow the user to click on a link, which will then change the value of what is submitted in the SQL SELECT Statement, if that makes sense. 我试图让它允许用户单击链接,然后将更改在SQL SELECT语句中提交的值(如果有道理)。
My Code so far: 到目前为止,我的代码:

<div class="Tabs" >
<?php
require 'database/connect.php';
$sql = "SELECT DISTINCT Week FROM PMWUpdates";

$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {

echo '<a class="weeks"> Week' . $row{'Week'} . '</a>';
}
?>
</div>

<div class="Pages">
<?php
require 'database/connect.php';
$sql = "SELECT * FROM PMWUpdates WHERE Week='1'";
?>
</div>

I want the value of SELECT * FROM PMWUpdates WHERE Week="'1'"; 我想要SELECT * FROM PMWUpdates WHERE Week="'1'"; to be what link the user has clicked on above, not just always 1. So if the user clicks on the link 2, the SQL changes to SELECT * FROM PMWUpdates WHERE Week="'2'"; 成为用户单击的链接,而不仅仅是单击1。因此,如果用户单击链接2,则SQL更改为SELECT * FROM PMWUpdates WHERE Week="'2'";

I am basically trying to accomplish this , but instead, I want to display the number of tabs, based on the number of weeks in a database, and then, each week will display data from the database about that particular week. 我基本上是在尝试完成此操作 ,但是我想根据数据库中的星期数显示选项卡数,然后,每个星期将显示该特定星期的数据库数据。

Any help is appreciated. 任何帮助表示赞赏。

Thank You 谢谢

Your statement should be like this... 您的陈述应该像这样...

$sql = "SELECT DISTINCT Week FROM PMWUpdates";

$result = mysql_query($sql);

while ($row = mysql_fetch_array($result)) {
    echo '<a class="weeks" href="$row['Week_link']"> Week' . $row['Week'] . '</a>';
}

If you mean dynamically changing data on a page which requires PHP to be processed, you have to take a look at AJAX. 如果要动态更改需要处理PHP的页面上的数据,则必须查看AJAX。 You can't do it this way, once your script is loaded, there is no more php, only HTML. 您无法以这种方式进行操作,一旦脚本被加载,就没有更多的php,只有HTML。 If you don't want to use AJAX, you will have to do it in 2 pages. 如果您不想使用AJAX,则必须分2页进行。 First display links, then display your data related to whatever was selected. 首先显示链接,然后显示与所选内容相关的数据。

The MySQL extension you are using is deprecated (>= 5.5). 您使用的MySQL扩展已弃用 (> = 5.5)。 Use MySQLi or PDO instead. 改用MySQLi或PDO。

What you are trying to accomplish is that where your "2" is listed, should change with the use of a variable. 您要完成的工作是列出“ 2”的位置应随变量的使用而变化。 As you want to do it via Javascript, you will need a click event on those links which then submits the variable via AJAX. 当您想通过Javascript进行操作时,您需要在这些链接上单击事件,然后通过AJAX提交变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM