Bulletin board, there is a request for the formation of the action of paid services:

function applyStatus($id, $act) { if($act=='top') $sql="UPDATE board SET top_time='".(14 * 86400 + time())."' WHERE id='{$id}'"; elseif($act=='color') $sql="UPDATE board SET is_color='1' WHERE id='".functions::q($id)."'"; $sql="UPDATE board SET is_important='1' WHERE id='".functions::q($id)."'"; return mysql_query($sql); } 

Where at start-up, the "top_time" table is triggered by time for 2 weeks - as a paid service, and "is_color" or "is_important", if they are used, it is activated to the position "1" (these are eternal).

At the same time, no service updates the current date. I need to, in addition to these actions, also update the date for all lines of services. That is, the service itself and the announcement is higher in the list (by date). The time format is now TIMESTAMP. The desired time table.

I tried to substitute this for each service:

 $sql="UPDATE board SET time='".(data = NOW())."'"; 

Did not work. Error code:

Parse error: syntax error, unexpected '=' in Z: \ home \ test1.ru \ www \ service.php on line 53

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

The elseif condition lacks curly brackets, only the first line is executed (or is it conceived? If not, do not neglect brackets in the conditions)

In the first piece of code you set top_time, in the line

 $sql="UPDATE board SET time='".(data = NOW())."'"; 

already just time, and a certain data appears in the field value. Either I do not understand something, or I just need to assign NOW () to a field, and without single quotes. Something like that

 $sql="UPDATE board SET top_time=NOW()"; 

Hope helped.

  • data, - it is simply not copied from there, it is not from here ... where do you mean curly brackets in the elseif condition? - dolphinbibik
  • @dolphinbibik for example, if if ($ t == 1) {} elseif ($ t == 2) {} and on the next question (which is below), you assign one variable to the different requests. those. always the one you appointed last is executed. do so $ sql = "FIRST REQUEST"; $ sql. = ';' . "SECOND INQUIRY" through the point you combine the lines into one, and the variable will be one request - asmproger
  • Thanks, I will try ... - dolphinbibik
  • Hi, I threw a piece of code here - jsfiddle.net/dolphinbibik/v09j4gct ... help is still needed ... - dolphinbibik

I tried this:

 function applyStatus($id, $act) { if($act=='top') $sql="UPDATE board SET top_time='".(14 * 86400 + time())."' WHERE id='{$id}'"; $sql="UPDATE board SET time='".time()."'"; elseif($act=='color') $sql="UPDATE board SET is_color='1' WHERE id='".functions::q($id)."'"; $sql="UPDATE board SET time='".time()."'"; elseif($act=='important') $sql="UPDATE board SET is_important='1' WHERE id='".functions::q($id)."'"; $sql="UPDATE board SET time='".time()."'"; return mysql_query($sql); } 

As a result, the dates are now okay, the current one comes out, but the services themselves do not work, every first line after if, elseif. By the way, the date is updated exclusively for all ads, and I want only for the service used only for this id.

Maybe there is an opportunity to somehow make a paired query, moving away from two consecutive lines with the view - "sql = ................."?

  • Do you think without knowledge of the database structure can you understand your question? So grieve you, not possible. For example, I have not been born to clairvoyants and can’t imagine how to select “only for the service used”, not knowing where these services lie and how they relate to ads. And I cannot understand your code without knowing what the function functions :: q () does and how the id that passes through it differs from just id. By the way, questions must be asked in questions, not in answers ... - Mike
  • Good criticism! I'm new here, I'm sorry if I wrote there, I don’t understand the structure of this site. There is no other connection, this is a separate file for payment. There are three services, each with its order must not only be launched (what works!), But also to update these id for the current date. That is the problem. The row of the table "board" is called "time", so it must be updated simultaneously with the connection of the service by the date. - dolphinbibik
  • And the service is connected to which of the lines. All I see here is the code that changes something in the board table, judging by the name of the table, these are ads, and where are the services? By the way, when you write update board set time=.. without specifying where conditions, you update the column in all entries in the table! in addition, in the set clause it is possible to specify several updatable columns through a comma. And so if you decide to add a question, click on the "edit" link below it and make changes to the question itself - Mike
  • The field where it is indicated how the service behaves only here. "top_time" - push to the top for 2 weeks, "is_color" - highlight with color ... activate it 1, "is_important" - make urgent ... also like highlight with color ... That's the point, what I have updated all in this situation, but the services themselves are not executed ... Above the branch, they told me how to knock down the requests into one, so that there were no 2 lines beginning with $ sql = ... Again, I do not understand everything ... Thank you for your response ! - dolphinbibik
  • Something I didn’t even pay attention to; you really assign 2 queries to the sql variable two times in a row. And then at the very end you are already doing something in the variable, i.e. the most recent request. You do one request then update board set is_important=1, time=now() where ... - Mike