redarrow Posted May 6, 2006 Share Posted May 6, 2006 Advance thank you.I am learnig php and i want to learn how to get a link to increment and update the database each time the link is pressed.Got no idear how to do this just an example of what i want to do.[code]<?$db=mysql_conect("loclhost");mysql_select_db("test",$db);$query="select * from link where links='$links'";$result_mysql_query($query);if(mysql_num_rows($result)==0) {$query="insert into link (links)values('$links')";$result_mysql_query($query);<a href="http//www.whatever.com">goto page</a>}if(mysql_num_rows($result)==1) {$query="update link set links='$links++' ";$result_mysql_query($query);}$query="select * from link where links='$links'";$result_mysql_query($query);while(record=mysql_fetch_assoc($result){while(list($tablename,$data)=each($record){echo"<br>number of times $tablename has been pressed $data<br>";}echo"<br>";}?>[/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 something like this is one simplified way of doing it[code]if(!empty($_GET['url'])){ $url = htmlspecialchars($_GET['url']); mysql_query("update links set hits = hits + 1 where url='$url'"); header("Location: $url"); exit();}$get_links = mysql_query("select url from links");while($row = mysql_fetch_array($get_links)){ $url = $row['url']; print "<a href="this_page.php?url=$url" target="_blank">$url</a>"; print "<br />";}[/code] Quote Link to comment 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.