result()" method. Result; 3. Save the modified file."/> result()" method. Result; 3. Save the modified file.">

Home  >  Article  >  Backend Development  >  What should I do if the return values ​​​​of php and sql are different?

What should I do if the return values ​​​​of php and sql are different?

藏色散人
藏色散人Original
2022-10-18 09:34:221199browse

The return values ​​​​of php and sql are different because the code processes the results by only taking the current row. The solution is: 1. Find the corresponding PHP code file; 2. Pass "$query->result ()" method to obtain complete results; 3. Save the modified file.

What should I do if the return values ​​​​of php and sql are different?

The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer

Why is the return value of php different from sql? manage?

Specific problem description:

Desired query results: Input the mobile phone number and type, and format Y-m-d H:i:s text The time field is converted into Y-m-d format, and the number is grouped and counted.

This is the sql statement in the project. Note: The statement that returns the result is rewritten in the project. What is returned is all the results obtained by the query. , is not the result of returning a row (Oh my god, let me reiterate it again, they have rewritten it! They have rewritten it! They have rewritten it! Don't read it with inertial thinking...)

public function getSmsByTelephone($sms_mobile,$type) {
    $query = $this->db->query("SELECT DATE_FORMAT(`add_date`, '%Y-%m-%d') num,count(*)  FROM " . DB_PREFIX . "sms_mobile WHERE sms_mobile = '" . $sms_mobile ."' AND  type = '" . $type . "' group by num");    
    return $query->row;
}

This is the query result in phpadmin

What should I do if the return values ​​​​of php and sql are different?

This is the method obtained in the program, and then printed

What should I do if the return values ​​​​of php and sql are different?

This is The print result of the page

What should I do if the return values ​​​​of php and sql are different?

Question: The underlying sql statements are all queried using $this->db->query, and there are no restrictions on the sql statements at the bottom. If you want to limit, just add limit to the sql to limit the number of items.
My sql has no limit, I don’t know why there is only one

Solution:

ci The writing method in the framework is very similar to this. Many people have said just now, the explanation of row:

What should I do if the return values ​​​​of php and sql are different?

If you want to get the complete result, please use -$query->result() to get the result .

If you are using CI, please look at http://codeigniter.org.cn/user_guide/database/results.html#id2 for an explanation!

Summary: If you encounter such a problem, you can read the manual first

Recommended study: "PHP Video Tutorial"

The above is the detailed content of What should I do if the return values ​​​​of php and sql are different?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn