Inserting Values into MySQL table with PHP -
i have php array has several values in it, corresponding different banner ads. let's $a called, 0th value in array. have field in table impressions, likewise called 0, holds integer. want call integer field, increment it, , put in same row.
to oversimplify. want call number of impressions current ad shown has. ad $a has 500 impressions. want increment number, 501, , put in table.
i hope explained enough. here's code far:
$ads = array($a, $b, $c, $d, $e, $f, $g, $h, $i, $j); $rand = rand(0,9); print($ads[$rand]); $writevar = $rand; $con = mysql_connect("localhost","delives0_ads","ads"); if (!$con) { die('could not connect: ' . mysql_error()); } mysql_select_db("delives0_ads", $con); $sqlcmd = mysql_query("select * impressions ('$writevar');"); $sqlcmd++; mysql_query("insert impressions ('$writevar`) values ('$sqlcmd');"); mysql_close($con);
edit: here structure in sql
create table if not exists `impressions` ( `0` int(11) not null, `1` int(11) not null, `2` int(11) not null, `3` int(11) not null, `4` int(11) not null, `5` int(11) not null, `6` int(11) not null, `7` int(11) not null, `8` int(11) not null, `9` int(11) not null ) engine=myisam default charset=latin1;
you not need select , update query increment column in table.
just send 1 update query [example]:
update impressions set views = views + 1 ad_id = 3
throw out code you've written none of posted correct. not use database table designed.
if might suggest book or two:
http://www.amazon.com/build-database-driven-using-mysql/dp/0980576814/ref=dp_ob_title_bk
http://www.amazon.com/simply-sql-rudy-limeback/dp/0980455251
Comments
Post a Comment