Jump to content

[SOLVED] simple counter help


quickstopman

Recommended Posts

hey guys

i wanna make a simple counter

i think i know what i shoud do

i just wrote a script for it but it doesn't work

does anyone know what im doing wrong??

<?
include("config.php");
$i = 1;
$sql = mysql_query("UPDATE counter SET number = '{$count['number']} + 1' WHERE number") OR die(mysql_error());
$number = mysql_query("SELECT number FROM counter") OR die(mysql_error());
$count = mysql_fetch_array($number);
echo "You are 1 out of ". $count['number'] ." to view  to view this page";

?>

thanks ahead of time!

Link to comment
https://forums.phpfreaks.com/topic/52077-solved-simple-counter-help/
Share on other sites

Sorry, but your code doesn't make allot of sense. Where is the $count['number'] variable you use in your first query defined? Also that query is missing part of the WHERE clause.

 

Maybe something like....

 

<?php

  include("config.php");
  if (mysql_query("UPDATE counter SET number = number+1")) {
    if ($result = mysql_query("SELECT number FROM counter")) {
      if (mysql_num_rows($result)) {
        $row = mysql_fetch_assoc($result);
        echo "You are 1 out of {$row['number']} to view  to view this page";
      }
    }
  }

?>

 

is what your after?

Your SQL statement makes no sense at all. You are using a WHERE without a condition 0_o

Also, why are you setting a variable $i to 1? Your counter is obviously stored in the database...not within the script.

 

<?php

mysql_query("UPDATE counter SET number=number+1");

$sql = mysql_query("SELECT number FROM counter");
$row = mysql_fetch_assoc($sql);

echo "You are 1 out of ". $row['number'] ." to view  to view this page";

?>

 

I already typed this before the first post was there...so might as well post it =]

 

And yes, you might need to insert a valid WHERE clause to tell the database which row in the table "counter" to update.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.