I have been running weather contests in my facebook weather group using PHPMYADMIN and MYSQL. For over a year now
I have been wondering how to make a row count field appear dynamically with each submission.
Here is an example of one of my entry forms:
[URL=”http://www.directpaintsaleswa.com/MAR2013/add.php”]http://www.directpaintsaleswa.com/MAR2013/add.php
When the user submits the data is placed into the following table:
[URL=”http://www.directpaintsaleswa.com/MAR2013/add.php”]http://www.directpaintsaleswa.com/MAR2013/add.php
The database table name is users. So I used the following code in PHPMyAdmin to add the rowcount field:
[CODE]select @n := @n + 1 rowcount, t.*
from (select @n:=0) initvars, users t
Now the above code added that field nicely incrementing the table rows starting at #1 like I wanted.
My problem is that when a user submits a new table entry into the database, the rowcount of that new entry ends up being “0”
on my add.php file when the user submits a new entry I build an sql string like so to append to the database:
[CODE]$query = “insert into users
set
//I want to add a row count here that doesnt start at zero
name = ‘”.$mysqli->real_escape_string($_POST[‘name’]).”‘,
avghigh = ‘”.$mysqli->real_escape_string($_POST[‘avghigh’]).”‘,
avglow = ‘”.$mysqli->real_escape_string($_POST[‘avglow’]).”‘,
num60 = ‘”.$mysqli->real_escape_string($_POST[‘num60’]).”‘,
num45 = ‘”.$mysqli->real_escape_string($_POST[‘num45’]).”‘,
num32 = ‘”.$mysqli->real_escape_string($_POST[‘num32’]).”‘,
max = ‘”.$mysqli->real_escape_string($_POST[‘max’]).”‘,
min = ‘”.$mysqli->real_escape_string($_POST[‘min’]).”‘,
rain = ‘”.$mysqli->real_escape_string($_POST[‘rain’]).”‘,
snow = ‘”.$mysqli->real_escape_string($_POST[‘snow’]).”‘,
wind = ‘”.$mysqli->real_escape_string($_POST[‘wind’]).”‘,
raindays = ‘”.$mysqli->real_escape_string($_POST[‘raindays’]).”‘”;
The database currently has 36 entries. If I put in a 37th and so on, the rowcount just stays at zero for each new entry.
I am not an expert at syntax and have tried several combinations and failed…any help would be appreciated greatly
Thank you in advance, Brian