how correctly get country and other info from sql for specific id(如何从特定 id 的 sql 中正确获取国家和其他信息)
问题描述
我试图从特定 id 的 sql 获取国家和其他信息,在这两种情况下,只有id
"正确显示.
和
0) {while($rows = mysql_fetch_assoc($result)) {回声 $id;回声$国家;}}?>
我认为您有一个名为 id 的列和另一个命名的国家/地区,您希望从中收集某个记录的国家/地区行中的数据.我对一些评论有类似的想法,并想在这个答案中强调我的想法.
$_GET superglobal 用于从 URL 参数中提取数据.如果它用于从记录中获取数据,您可能需要使用 mysql_fetch_assoc($result)[country"].更多信息请查看https://www.php.net/manual/en/function.mysql-fetch-assoc.php和 https://www.w3schools.com/php/php_superglobals_get.asp>
要根据某些输入 id 过滤某些记录,您需要使用 WHERE 子句.更多信息链接:- https://www.w3schools.com/sql/sql_where.asp可能的代码可能是:-
<?php$id = $_GET["id"]$sql = "SELECT * FROM `list` WHERE id='$id' ORDER BY category ASC";$result = mysql_query($sql);如果 (mysql_num_rows($result) > 0) {while($rows = mysql_fetch_assoc($result)) {回声 $rows['id'];回声 $rows['country'];}}?>
PS:如果提供的信息较少,我已尽力回答所提出的问题.希望有帮助
I am trying to get country and other info from sql for specific id, only "id
" displays correctly in both cases.
<?php
$sql = "SELECT * FROM `list` ORDER BY category ASC";
$result = mysql_query($sql);
$rows = mysql_fetch_assoc($result);
$id = $_GET['id'];
$country = $_GET['country'];
echo $id;
echo $country;
?>
and
<?php
$sql = "SELECT * FROM `list` ORDER BY category ASC";
$result = mysql_query($sql);
$id = $_GET['id'];
$country = $_GET['country'];
if (mysql_num_rows($result) > 0) {
while($rows = mysql_fetch_assoc($result)) {
echo $id;
echo $country;
}
}
?>
I think you have a column named id and another named country from which you want to collect the data in the country row of a certain record. I have similar ideas to some of the comments and would like to highlight my thoughts in this answer.
$_GET superglobal is used to extract data form a URL parameter. If it is used to get the data from the record, you might want to use mysql_fetch_assoc($result)["country"]. For more information, please take a look at https://www.php.net/manual/en/function.mysql-fetch-assoc.php and https://www.w3schools.com/php/php_superglobals_get.asp
To filter certain records according to some input id, you would want to use the WHERE clause. Link for more information:- https://www.w3schools.com/sql/sql_where.asp The possible code might be:-
<?php
$id = $_GET["id"]
$sql = "SELECT * FROM `list` WHERE id='$id' ORDER BY category ASC";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
while($rows = mysql_fetch_assoc($result)) {
echo $rows['id'];
echo $rows['country'];
}
}
?>
PS: I have tried my best to answer the asked question provided the less information given. Hope it helps
这篇关于如何从特定 id 的 sql 中正确获取国家和其他信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从特定 id 的 sql 中正确获取国家和其他信息
基础教程推荐
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 使用 PDO 转义列名 2021-01-01