R
R
raymon942015-12-25 02:15:42
PHP
raymon94, 2015-12-25 02:15:42

How to pass value from php variable to MySQL?

Hello, I'm new to php and I'm having the same problem. I'm trying to make my mini game. Do not judge strictly, I just started learning php, so I'm learning from practical examples. So I remember better. But that's not the point.
The mysql users table has a views column with the number of page views for each user.
user | view
nick | 2384
It was required to make payment by points for each page viewed by a unique visitor.
In php, to display the number of points a user has, I displayed the following code:
$queryviews=mysql_query("SELECT SUM(views) FROM users");
$point=mysql_result($queryviews,0);
$summ=$point/1150;
$summ=round($balance, 2);
echo $sum;
Everything works fine, but now there is a need to make an "extraction" from the points. That is, minus points without affecting the number of page views, and in this script this is the only way. I understand that for storage you need to create another column point to store the number of points there. But how do I write the value from the $summ variable to the point column for further "editing" the balance.
I apologize for my possibly incorrect message, but, as I said above, I am still a beginner and do not know much.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Litvinenko, 2015-12-25
@edli007

The mysql_query and other mysql_* functions were deprecated a few years ago and now use PDO. You may see more guides mentioning mysqli_*, these are also undesirable, these functions were designed to smoothly transition old sites from mysql_* to PDO, not for real work.
Here it is better to add a new entry for each view, then it is easy to manipulate any data, and connect the page table with views with a foreign key, select by JOIN

P
Puppollo, 2015-12-25
@Puppollo

Alexander Litvinenko @edli007
The mysql_query and other mysql_* functions were deprecated a few years ago, now they use PDO. You may see more guides mentioning mysqli_*, these are also undesirable, these functions were designed to smoothly transition old sites from mysql_* to PDO, not for real work.

$summ=$point/1150; // вероятно это $balance
$summ=round($balance, 2);  // откуда взялась $balance?

Use any of the available record update functions in mysql? ( REPLACE ,
UPDATE ,
INSERT with ON DUPLICATE KEY UPDATE )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question