How does php determine whether to add to favorites?

Source: Internet
Author: User
How does php determine whether to add to favorites? You have created an information favorites function,
On the information details page, there are hidden title, url, and other information. as long as you press the Submit button, the system will prompt you that you have added your favorite information. then, you will have a record list in the background to facilitate future viewing.

The question now is how to determine if a user has already added a favorite to the information details page? So that users can no longer add to favorites?
In addition, you can add this information to favorites after deleting this information.


Reply to discussion (solution)

So how did you add it to your favorites?

Favorites is recorded in the database.
It is also determined in the database.

If the record is a url
You can use this url and user ID to determine whether the user has added a favorite.

The table structure is as follows:
Id, user_id, title, url

Determine whether to add to favorites
Select * from table where url = xxx and user_id = xxx;

@ Fdipzone

You mean to query the database again when adding it to the Favorites folder.

If this record exists, you will be prompted to add it to favorites.

If this record is not found, why is it not added to favorites?

How to write the specific code? Please advise

Hypothesis
The data table is XX_ SC.
The primary ID field is ID
The user ID field is UID.
URL

How to write it? (You do not need to connect to the database. the whole code segment has been linked and determined)

;



@ Fdipzone

You mean to query the database again when adding it to the Favorites folder.

If this record exists, you will be prompted to add it to favorites.

If this record is not found, why is it not added to favorites?

How to write the specific code? Please advise

Hypothesis
The data table is XX_ SC.
The primary ID field is ID
The user ID field is UID.
URL

How to write it? (You do not need to connect to the database. the whole code segment has been linked and determined)

Favorites is recorded in the database.
It is also determined in the database.

If the record is a url
You can use this url and user ID to determine whether the user has added a favorite.

The table structure is as follows:
Id, user_id, title, url

Determine whether to add to favorites
Select * from table where url = xxx and user_id = xxx;





I cannot write this if else statement.

You don't tell me how to complete my favorites. how do I know how to find out if my favorites have been added?
If you record your favorite information in the database, you will naturally need to access the database during the check.
If you record it in other carriers, you can find it in the appropriate way.
In short: How to store and read

@ Fdipzone

You mean to query the database again when adding it to the Favorites folder.

If this record exists, you will be prompted to add it to favorites.

If this record is not found, why is it not added to favorites?

How to write the specific code? Please advise

Hypothesis
The data table is XX_ SC.
The primary ID field is ID
The user ID field is UID.
URL

How to write it? (You do not need to connect to the database. the whole code segment has been linked and determined)



Yes.


Favorites is recorded in the database.
It is also determined in the database.

If the record is a url
You can use this url and user ID to determine whether the user has added a favorite.

The table structure is as follows:
Id, user_id, title, url

Determine whether to add to favorites
Select * from table where url = xxx and user_id = xxx;





I cannot write this if else statement.




Determine whether to add to favorites
$ Url = 'http: // www.baidu.com '; $ user_id = '1'; $ sqlstr = "select * from table where url = '". $ url. "'and user_id = '". $ user_id. "'"; $ query = mysql_query ($ sqlstr) or die (mysql_error (); if (mysql_num_rows ($ query)> 0) {// added to favorites} else {// not added to favorites}


If you do not understand this, please first learn about the database.

The user's favorite records should be written to the database to determine whether the user has collected the data and directly query the data.



Favorites is recorded in the database.
It is also determined in the database.

If the record is a url
You can use this url and user ID to determine whether the user has added a favorite.

The table structure is as follows:
Id, user_id, title, url

Determine whether to add to favorites
Select * from table where url = xxx and user_id = xxx;





I cannot write this if else statement.




Determine whether to add to favorites
$ Url = 'http: // www.baidu.com '; $ user_id = '1'; $ sqlstr = "select * from table where url = '". $ url. "'and user_id = '". $ user_id. "'"; $ query = mysql_query ($ sqlstr) or die (mysql_error (); if (mysql_num_rows ($ query)> 0) {// added to favorites} else {// not added to favorites}


If you do not understand this, please first learn about the database.



Thank you. this is clear.
How do I write more than two data tables?
Assume that news, activities, and Q & A are added to the favorites function, and three data tables, namely, $ url, can be queried simultaneously.
Is it written three times in a loop and determined in sequence?

I did not ask about the above.

The header is dizzy. I don't know if the URL of each page is different. thank you. I will try again after testing.



Favorites is recorded in the database.
It is also determined in the database.

If the record is a url
You can use this url and user ID to determine whether the user has added a favorite.

The table structure is as follows:
Id, user_id, title, url

Determine whether to add to favorites
Select * from table where url = xxx and user_id = xxx;





I cannot write this if else statement.




Determine whether to add to favorites
$ Url = 'http: // www.baidu.com '; $ user_id = '1'; $ sqlstr = "select * from table where url = '". $ url. "'and user_id = '". $ user_id. "'"; $ query = mysql_query ($ sqlstr) or die (mysql_error (); if (mysql_num_rows ($ query)> 0) {// added to favorites} else {// not added to favorites}


If you do not understand this, please first learn about the database.





OK, I changed one sentence.
$ Sqlstr = "select * from". DB: table ('XX _ XXXX'). "where url = '$ url' and uid =' $ uid '";
Related Article

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.