Newbie solves the problem of comparing result sets and arrays. -Php Tutorial

Source: Internet
Author: User
Newbie solves the problem of comparing result sets and arrays. 1 Table

----------------------------
| Id | name | baodao | time |
| 2 | Li Xiaoming | James |
| 1 | Zhang Sanming | James |
------------------------------

First, collect information.
$ Url = "http://www.abc.com ";
$ DuUrl = file_get_contents ("$ url ");
$ Name = "/bs \[. * \] \ s * \ = \ s * new \ s * Book \ (\ '[0-9] * \' \, \ '(. *?) \ '\, \' [0-9] * \ '\, \'. *\'\,\'. * \ '\, \' [0-9] * \ '\, \' (. *?) \ '\, \' [0-9] * \ '\, \'. * \ '\, \' [0-9] * \ '\, \'. *\'\,\'(. *?) \ '/IU ";
Preg_match_all ($ name, $ duUrl, $ xiaoname );
$ A = $ xiaoname [1];
$ B = $ xiaoname [2];
$ C = $ xiaoname [3]; // the three values are collected.

Q. Assume that the first one is collected, and the NNNN is later. Me
$ A = Li Xiaoming;
$ B = 23: 13;
$ C = Rong;

When obtaining a value of $ a, I want to compare it with the value in the database field baodao.
If so, modify the time field. if not, skip this step.

This is probably the case. It is hard for new users to understand .. For PHP prawns, give me some advice.


Reply to discussion (solution)

Supplement,

When the value of $ a is Li Xiaoming, use this Li Xiaoming as the condition for searching databases. If yes, change the $ c = Rong $ B value.
If not, Skip.

I can't find the result set.

$ Mysqli = new mysqli ("localhost", "root", "aa", "aa ");
$ Mysqli-> query ("set names utf8 ");
If (mysqli_connect_errno ()){
Echo "error:". mysqli_connect_error ();
Exit;
}

Another idea is.

The returned result is an array.
If you can declare all values in the field name back to array,
Then we can use in_array for comparison. If yes, insert it. if no, insert it...
But the name is declared back to the array. how does this happen?

$ SQL = "update biao set baodao = '$ B', time = '$ C' where name =' $ '";
$ Mysqli-> query ($ SQL );

But first, you need to solve the problem: how to deal with the same name
That is to say, what should I do if there are two Li Xiaoming columns in the name column?

$ SQL = "update biao set baodao = '$ B', time = '$ C' where name =' $ '";
$ Mysqli-> query ($ SQL );

But first, you need to solve the problem: how to deal with the same name
That is to say, what should I do if there are two Li Xiaoming columns in the name column?

Li Xiaoming won't appear more than two, only 0 or 1 time.

That's good. isn't the problem solved?

Do you mean that if the database has this field, it will be inserted if it is not updated?

 Query ("select * from biao where baodao = '$ '")) {// update $ mysqli-> query ("update biao set baodao = '$ B ', time = '$ C' where name =' $ '");} else {// insert $ mysqli-> query ("insert into biao ('$ A',' B ', 'C')");}?>

 Query ("select * from biao where baodao = '$ '")) {// update $ mysqli-> query ("update biao set baodao = '$ B ', time = '$ C' where name =' $ '");} else {// insert $ mysqli-> query ("insert into biao ('$ A',' $ B ',' $ c')");}?>

 Query ("select * from biao where baodao = '$ '")) {// update $ mysqli-> query ("update biao set baodao = '$ B ', time = '$ C' where name =' $ '");} else {// insert $ mysqli-> query ("insert into biao ('$ A',' $ B ',' $ c')");}?>


If not, continue to jump. So far, Li Xiaoming's data is manually added, and the baodao | time fields are used for correction and routine maintenance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.