How to create a function to add in php and save in mysql?

Asked

Viewed 32 times

-1

Good afternoon.

First, I want to create a function in PHP that every time you run add +1 in Mysql.

In my Mysql you will have a column called numbers, whenever the function is executed, it will remove what you have in this column and will be adding +1

Example:

I have in my column the number 67, then I run the function and in the column will go from 67 to 68

I hope you understood KKK

hug!

1 answer

1


You can do this directly in Mysql

If you have a "number" table and it has a "number" field, you can first add a record with the value zero

INSERT INTO numeros (numero) values (0)

In this way, you have created a record in the table. To always update this record, you can run the following command:

UPDATE numeros SET numero = numero + 1

This way, when running UPDATE, you will always increase the field number by 1 more.

  • How do I use this UPDATE? $sum = 'UPDATE numbers SET number = number + 1'; $result = mysqli_query($connected, $add); OBS: $connected is what is connecting Mysql

  • Edit: I created a new table like you said.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.