Re: counter help

From: Greg (greg_at_aperfectnumber.com)
Date: 03/14/05


Date: Sun, 13 Mar 2005 16:52:25 -0800

Well, I tried that stuff, and nothing seems to work. Any other experts can
shed some light on my problem? Thanks for the efforts of the other posters.
Here's the current php:

<?

   require ('dbconnect.php');

   $query = "SELECT num FROM counter";
   $result = mysql_query($query);

   while( $row = mysql_fetch_array( $result ) )
    {
     echo( "You Have seen this page " . $row["num"] ." times");
    }

    $i = $row["num"];

   ++$i;

   $query2 = "UPDATE counter SET num = $i";

   mysql_query($query2);

   echo ("<br><br>Update Complete - Refresh to view new value.");

   mysql_close();

?>

"MS" <SpamNoThnx_santa____clause@hotmail.com> wrote in message
news:d12isr$2nj$1@hercules.btinternet.com...
> $row["num"] = $i;
>
> makes $row["num"] equal to $i
>
> by the looks of it you should make $i equal the $row["num"] and then
> increment $i
>
> $i = $row["num"];
> $i++;
>
> hope this helps
> --
> --------------------------------------------------------------------------

--
> http://www.clickonlingerie.com?SIG - Exotic Erotic Lingerie
> --------------------------------------------------------------------------
--
>
>
> "Floortje" <floortje-apestaartjexs4allpuntnl@hetminnetjehoort.erbij> wrote
> in message news:mn.6d1e7d5361d62b07.23446@hetminnetjehoort.erbij...
> > Greg had uiteengezet :
> > > Hello All,
> > >
> > > I'm getting pretty good with getting tutorial scripts to function, and
> now
> > > I'm trying to experiment on my own with PHP.  I'm trying to develop a
> simple
> > > counter.  Before PHP I've never really been able to think like a
> programmer,
> > > but the code below seems logical to me.  First, the script connects to
> the
> > > database and retrieves the value in the "counter" table, row "num".
It
> > > returns this value to the brower.  Then it assigns that row to another
> > > variable, that I increment with the ++ .  Then it updates the database
> with
> > > the new number.  Where am I going wrong with the script.  Please be
> gentle,
> > > I"m pretty green.
> > >
> >
> > Dunno seems okay, maybe small error .. havent tried it cause im lazy
> > ... try this instead
> >
> > $sql= "SELECT num FROM counter LIMIT 1";
> > $query = mysql_query("$sql")
> >          or exit ("Ongeldige query " . mysql_error());
> >
> > $row = mysql_fetch_array($result);
> > echo "You Have seen this page " .$row["num"] ." times";
> >
> > $sql= "UPDATE counter SET num = num+1";
> > $query = mysql_query("$sql")
> >          or exit ("Ongeldige query " . mysql_error());
> >
> >
> >
> > >
> > > PHP SCRIPT:
> > >
> > > <?
> > > require ('dbconnect.php');
> > >
> > >    $query = "SELECT num FROM counter";
> > >    $result = mysql_query($query);
> > >
> > >    while( $row = mysql_fetch_array( $result ) )
> > >     {
> > >      echo( "You Have seen this page " .$row["num"] ." times");
> > >     }
> > >
> > >     $row["num"] = $i;
> > >
> > >    ++$i;
> > >
> > >    $query2 = "UPDATE counter SET num = $i";
> > >
> > >    mysql_query($query2);
> > >
> > >    echo ("<br><br>Update Complete - Refresh to view new value.");
> > >
> > >    mysql_close();
> > >
> > > ?>
> >
> > -- 
> > www.cavalierpage.com
> >
>
>


Relevant Pages

  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... This is why I am thinking about rewriting my whole script in a C language. ... Perhaps there are different methods I could be using to speed up execution. ...
    (php.general)
  • Re: How to Add a Feeback Form
    ... I saw nothing in that script that indicates where the form is e-mailed to so ... Greg Maxey/Word MVP ... PHP or not. ... have the support available yet. ...
    (microsoft.public.frontpage.programming)
  • How best to show PHP source? (was: One page, multiple submit buttons)
    ... script to add to the top of a PHP script to enable showing its ... Maybe anybody submitting their own PHP code for critique here ... Anything posted to a newsgroup is a "snapshot" of what the ... there ought to be a FAQ for this ...
    (comp.lang.php)
  • Re: [PHP] PHP console script vs C/C++/C#
    ... My script is taking a longer time to execute than I want. ... I prefer to write in PHP because that is what I know best. ... thinking about rewriting my whole script in a C language. ... execution of the code. ...
    (php.general)
  • Email form script
    ... I have a web form that posts to a .php ... who cannot run .php on their server. ... Or does anyone have a .asp script that will ... Thank you for choosing FormToEmail by FormToEmail.com ...
    (microsoft.public.scripting.jscript)