我有一个名称列表和一些带有产品名称的按钮.单击其中一个按钮时,列表的信息将发送到PHP脚本,但我无法点击提交按钮来发送其值.怎么做?我将我的代码简化为以下内容:
发送页面:
<html>
<form action="buy.php" method="post">
<select name="name">
<option>John</option>
<option>Henry</option>
<select>
<input id='submit' type='submit' name = 'Tea' value = 'Tea'>
<input id='submit' type='submit' name = 'Coffee' value = 'Coffee'>
</form>
</html>
Run Code Online (Sandbox Code Playgroud)
接收页面:buy.php
<?php
$name = $_POST['name'];
$purchase = $_POST['submit'];
//here some database magic happens
?>
Run Code Online (Sandbox Code Playgroud)
除了发送提交按钮值之外的所有内容都可以正常运行.
我有一个包含产品和价格的MySQL数据库表.虽然是html表单,但我在某个php文件中获得了产品名称.对于我要做的这个文件中的操作,我还需要相应的价格.
对我来说,以下内容看起来足够清晰:
$price = mysql_query("SELECT price FROM products WHERE product = '$product'");
Run Code Online (Sandbox Code Playgroud)
但是,它的回声返回:
Resource id #5
Run Code Online (Sandbox Code Playgroud)
而是像这样的值:
59.95
Run Code Online (Sandbox Code Playgroud)
似乎还有其他选项,如mysqli_fetch_assoc mysqli_fetch_array但我不能让它们输出任何有意义的东西,我不知道使用哪一个.
提前致谢.
上下文:
在 Python 3.9 中,即使存在重复项,按第二个列表对大多数对象的列表进行排序也很容易:
>>> sorted(zip([5, 5, 3, 2, 1], ['z', 'y', 'x', 'w', 'x']))
[(1, 'x'), (2, 'w'), (3, 'x'), (5, 'y'), (5, 'z')]
Run Code Online (Sandbox Code Playgroud)
如果要排序的列表包含字典,则排序通常会顺利进行:
>>> sorted(zip([3, 2, 1], [{'z':1}, {'y':2}, {'x':3}]))
[(1, {'x': 3}), (2, {'y': 2}), (3, {'z': 1})]
Run Code Online (Sandbox Code Playgroud)
问题:
但是,当要排序的列表包含重复项时,会出现以下错误:
>>>sorted(zip([5, 5, 3, 2, 1], [{'z':1}, {'y':2}, {'x':3}, {'w': 4}, {'u': 5}]))
*** TypeError: '<' not supported between instances of 'dict' and 'dict'
Run Code Online (Sandbox Code Playgroud)
这个问题对我来说非常疯狂:要排序的列表的值如何影响要排序的列表?
替代解决方案:
一种不太优雅的解决方案是按索引从列表中获取字典对象:
>>> sort_list = [5, 5, 3, 2, 1]
>>> …Run Code Online (Sandbox Code Playgroud)