quickstopman Posted May 19, 2007 Share Posted May 19, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/52077-solved-simple-counter-help/ Share on other sites More sharing options...
trq Posted May 19, 2007 Share Posted May 19, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/52077-solved-simple-counter-help/#findComment-256766 Share on other sites More sharing options...
pocobueno1388 Posted May 19, 2007 Share Posted May 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52077-solved-simple-counter-help/#findComment-256767 Share on other sites More sharing options...
quickstopman Posted May 19, 2007 Author Share Posted May 19, 2007 thats it.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/52077-solved-simple-counter-help/#findComment-256768 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.