Home > Archive > PHP SQL > January 2005 > request problem
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi,
I have a table like this:
tbl_bidon
id int(11) non-null
name varchar(15) non-null
nbview int(11) non-null
description varchar(100) non-null
in this table, I have 4 records
1 'page1' 1 'Page1'
2 'page2' 1 'Page2'
3 'page3' 1 'Page3'
4 'page4' 1 'Page4'
I call the function nbview like this :
<?
$page = 'Page1';
$nbview = nbview($page);
print('<br>This page was visited <b>' .$nbview. '</b> time.<br>');
?>
All it'a allright but the request:
$sql = "UPDATE tbl_compteurs SET nbvisite = $nbvisites WHERE nom =
'$page'";
mysql_query($sql) or die('Erreur SQL '.$sql.'<br>'.mysql_error());
return the value: 'Ressource id #6'
I'm not understand why. I'm waiting for the value: '1'
If somebody can help me.
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
function nbview($page)
{
$server = 'sql.free.fr';
$login = 'bidon';
$password = 'bidon';
$base = 'bidon';
//Connect base
$db = mysql_connect($server, $login, $password)
or die('Error to connect base '.mysql_error());
//Select base
mysql_select_db($base,$db)
or die('Error to select base '.mysql_error());
//Find value
$sql = "SELECT nbvisite FROM tbl_bidon
WHERE nom = '$page'";
$nbvisites = mysql_query($sql);
$nbvisites = $nbvisites + 1;
//Insertion des données dans la table
$sql = "UPDATE tbl_compteurs SET nbvisite = $nbvisites
WHERE nom = '$page'";
mysql_query($sql)
or die('Erreur SQL '.$sql.'<br>'.mysql_error());
//Fermeture de la connexion
mysql_close();
return $nb_visites;
}
| |
| Alan Cole 2005-01-15, 8:56 am |
| In article <41e8ce5f$0$24331$626a14ce@news.free.fr>,
"Ziggy" <nospamtpnews2004@free.fr> wrote:
> Hi,
>
> I have a table like this:
>
> tbl_bidon
> id int(11) non-null
> name varchar(15) non-null
> nbview int(11) non-null
> description varchar(100) non-null
>
> in this table, I have 4 records
> 1 'page1' 1 'Page1'
> 2 'page2' 1 'Page2'
> 3 'page3' 1 'Page3'
> 4 'page4' 1 'Page4'
>
>
> I call the function nbview like this :
> <?
> $page = 'Page1';
> $nbview = nbview($page);
> print('<br>This page was visited <b>' .$nbview. '</b> time.<br>');
> ?>
>
> All it'a allright but the request:
> $sql = "UPDATE tbl_compteurs SET nbvisite = $nbvisites WHERE nom =
> '$page'";
> mysql_query($sql) or die('Erreur SQL '.$sql.'<br>'.mysql_error());
> return the value: 'Ressource id #6'
> I'm not understand why. I'm waiting for the value: '1'
>
> If somebody can help me.
>
>
>
> // *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
> function nbview($page)
> {
> $server = 'sql.free.fr';
> $login = 'bidon';
> $password = 'bidon';
> $base = 'bidon';
>
>
> //Connect base
> $db = mysql_connect($server, $login, $password)
> or die('Error to connect base '.mysql_error());
>
> //Select base
> mysql_select_db($base,$db)
> or die('Error to select base '.mysql_error());
>
> //Find value
> $sql = "SELECT nbvisite FROM tbl_bidon
> WHERE nom = '$page'";
>
> $nbvisites = mysql_query($sql);
> $nbvisites = $nbvisites + 1;
>
> //Insertion des données dans la table
> $sql = "UPDATE tbl_compteurs SET nbvisite = $nbvisites
> WHERE nom = '$page'";
> mysql_query($sql)
> or die('Erreur SQL '.$sql.'<br>'.mysql_error());
>
> //Fermeture de la connexion
> mysql_close();
> return $nb_visites;
> }
Nothing in the php seems to correlate with the table structure you gave
us. For example you say the table tbl_bidon has a column called 'name'
and one called 'nbview'
Your query then says:
$sql = "SELECT nbvisite FROM tbl_bidon WHERE nom = '$page''";
But from the structure you've given us there isn't a column called
nbvisite or one called nom
Also, if all you are trying to do is update the number of views (nbviews
column) by one each time someone views a particular page, something
simple along the lines of
$add_views_query = mysql_query("UPDATE tbl_bidon SET nbviews=nbviews+1
WHERE name=$page");
should suffice.
Al.
--
Alan Cole. E-mail: justal at lineone dot net
http://www.forces-of-nature.co.uk [Coastal Sports]
http://www.tsunami-site-design.co.uk [Website Design]
http://tinyurl.com/64xrd [Plusnet ISP]
|
|
|
|
|