我想使用从两个不同页面链接到的一个页面。以下是我的场景:
1) The user clicks a hyperlink to be directed to the page with a salesID in the URL
2) The user navigates directly to the page and no salesID is passed in the URL
现在考虑上面的每种情况 ->
1) If salesID IS NULL then get parameters from the page
2) If salesID IS NOT NULL then onload() display all relevant data for the salesID passed
我知道如何编写查询来默认使用参数加载页面,并且我知道如何使用从按钮按下事件捕获的页面参数来加载页面。我不知道该怎么做是将两者结合起来并检查多个标准。我想要做的是在 pageload() 上评估标准 1 - 如果 salesID 传递到页面,则继续并使用该 salesID 的所有数据填充页面。如果条件 2 为真,则不填充页面,等待用户输入从选择框中进行选择并按下按钮。
这是我如何使用页面语法的基础知识:
<?php
//Capture variable from URL
$salesID = urldecode($_GET['salesID']);
//Check if variable is set
if (isset($_GET['salesID'])) {
//A salesID was passed to the page so load that data by default
//ignoring any variables set on the page
}
else {
if (isset($_POST['btnpressevent'])) {
//button has been pressed capture variables from page and run query
}
}
?>
最佳答案
你可以试试这个:-
// if salesId is not set or is null then show form with select and button
if (!isset($_GET['salesId']) || is_null($_GET['salesId'])) {
$html = "<form action='samepage.php'><select><option>Select one</option><option>Item 1</option></select><button name='btnpressevent'>Press button</button></form>";
echo $html;
return; // or die();
}
// do stuff with salesId
echo "${$_GET['salesId']} helllo w";
关于javascript - PHP 检查变量是否已设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46285750/