|
how to update hits to database and shown in
website also
|
|
|
how to update how many times till it is used
|
|
|
<?php
|
query+executequery+ convert to array of that
row with id, access that row, incriment data, write query to update, execute
that query
|
|
require 'lesson44.php';
|
we are using require, to use template we are
using require, if we declare, we can use their variables and datavalues
|
|
//to update in data base , we need query
|
|
|
function update_count() {
|
writing funciton without arguments
|
|
global $mycon;
|
to use outside variable inside function, use
global
|
|
// if we want to use outside variable in
function
|
|
|
$query = "SELECT `hits` FROM `hits_count`
WHERE `id` = 1 ";
|
select the hits column, from hits_count
database
|
|
// write a statement or query to select table
|
|
|
if ($query_run = mysqli_query($mycon, $query))
{
|
run query against database, selected hits
column
|
|
// execute query on this database
|
|
|
$result = mysqli_fetch_row($query_run);
|
converted that colummn to array
|
|
// it takes a single row not necessary while ,
get the row data, and itis in a array
|
|
|
$current_hits =$result[0];
|
acces that row
|
|
// access the array
|
|
|
echo $hits_inc = $current_hits +1;
|
incriment the hits and assigned to hits
|
|
// incriment the hits , for every refresh it
executes this functioon, it incriments
|
|
|
$update_query =
"UPDATE `hits_count` SET `hits` = $hits_inc WHERE `id` = 1";
|
we incriment the hits, so update
that to query to database
|
|
// which one is updated, and updat that
to database
|
|
|
mysqli_query($mycon, $update_query);
|
to update , run query
|
|
//run this query on this database
|
|
|
}
|
|
|
}
|
|
|
|
|
|
update_count;
|
if u run this ffunction, it call s the
function and implements that
|
|
|
|
|
?>
|
|
|
How to update hits till now
|
|
|
how to use the other page template,to connect
to database
|
require
|
|
how to write a function to know how many
hits
|
function
|
|
how to use global variable inside the function
|
global
|
|
how to write a query to display that row data
|
query- select, from, where
|
|
how to execute queery against database
|
if
|
|
mysqli_query
|
|
|
how to convert to array after executed array
|
mysqli_fetch_row
|
|
how to get the row data after executed
|
$result[0]
|
|
how to print how many hits
|
$current_hits +1
|
|
how to update data base
|
UPDATE, SET, WHERE
|
|
QUERY
|
|
|
how to run query about update?
|
mysqli_query
|
Tuesday, 9 June 2020
how to update hits to database and shown in website also
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment