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] Link to comment https://forums.phpfreaks.com/topic/9175-how-to-increment-a-link/ 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] Link to comment https://forums.phpfreaks.com/topic/9175-how-to-increment-a-link/#findComment-33812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.