简体   繁体   English

如何从一个或两个领域获得剩余的记录?

[英]How to get rest of record from one or two fields?

(Beginners question here...be gentle) (初学者在这里提问......要温柔)

My php script is a response to a form. 我的php脚本是对表单的响应。 Assuming I have already connected to a database and extracted the post variables (just two - emailAddress and username), like so 假设我已经连接到数据库并提取了post变量(只有两个 - emailAddress和username),就像这样

mysql_connect('localhost', 'dbusername', 'dbpassword');
mysql_select_db('database');
extract($_REQUEST);

..and knowing that within the 'users' table, there are 'emailAddress', 'username' and 'address' fields. ..并且知道在'用户'表中,有'emailAddress','username'和'address'字段。 (The email addresses will all be unique..) (电子邮件地址都是唯一的..)

How would I search thru the table to get at the specific 'address' after receiving the emailAddress and username (and output something else if there is no name and address which matches)? 在收到emailAddress和用户名后,如何通过表搜索到达特定的“地址”(如果没有匹配的名称和地址,则输出其他内容)?


seems absurdly difficult to get an answer. 似乎很难得到答案。 this must be a very very very very very very difficult question. 这一定是一个非常非常非常非常困难的问题。


Extra-special thanks to users who told me the problem was very easy, and yet couldn't come up with an answer. 特别感谢那些告诉我问题非常简单,但却无法得出答案的用户。 I salute your indefatigability, your magnificent courage, and your willingness to help. 我向你的不知疲倦,你的勇气和你的帮助意愿致敬。

A possible answer to my question is: 我的问题可能的答案是:

$result = mysql_query("SELECT * FROM users WHERE emailAddress='".$emailAddress."' AND username='".$username."'");
$row = mysql_fetch_array($result); 
if ($row['username'] == "") {
    // no results
} else if ($row['emailAddress'] == $emailAddress AND $row['username'] == $username) {
   // found result 
   echo "The address is ".$row['address'];
} else {
   // i guess something else happened
}

Be sure to tell me how this is wrong, and the real answer is easy, and yet not come up with an answer. 一定要告诉我这是怎么回事,真正的答案很简单,但却没有得出答案。

to get individual elements, you do "select column_name from table where criteria". 要获取单个元素,您可以“从表中的条件中选择column_name”。

in your example it would be 在你的例子中它会是

select address from users where emailaddress = 'email@domain.com' and name = 'John Doe'

the column_name section can be multiple items comma seperated, so, for example, if you wanted name and address, you would do column_name部分可以是逗号分隔的多个项目,因此,例如,如果您想要名称和地址,您可以这样做

select name, address from users where emailaddress = 'email@domain.com' and name = 'John Doe'

you have to take this sql request into a variable then execute it after that u can verify if the array is empty or not.. if it is it means that there are no combination with both that name and that email corresponding into your database.. and it's done!`$req= "Select name,address from users where emailaddress=$email and name=$name"; 您必须将此sql请求转换为变量然后执行它,之后您可以验证数组是否为空...如果是,则表示该名称与该数据库对应的电子邮件没有任何组合。并且它完成了!`$ req =“选择名称,来自用户的地址,其中emailaddress = $ email和name = $ name”; $result = mysql_query($req); $ result = mysql_query($ req); if !isset($result){ /// some stuffs there when everything okkay if!isset($ result){///当一切都好的时候有些东西

} else{ /// some stuffs if there is no record corresponding } else {///如果没有相应的记录,有些东西

}` in vrac.. some sample exemple in the idea.. note that the sql query give the result into an array so u have to manipulate an array or hash 在vrac中..一些示例例子中的想法..请注意,sql查询将结果提供给数组,因此你必须操纵一个数组或哈希

You can use a SELECT statement. 您可以使用SELECT语句。 Note this code is not safe to SQL injection. 请注意,此代码对SQL注入不安全。

 SELECT * FROM Users WHERE emailAddress = 'someemail@gmail.com'

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

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