TheFilmGod Posted March 18, 2007 Share Posted March 18, 2007 Is there any way to have a link that would trigger a php code to work? Like if the visitor clicked a "I like it link" it would trigger php to add 1 to the count of "how many like it"? Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/ Share on other sites More sharing options...
fert Posted March 18, 2007 Share Posted March 18, 2007 yes, <a href="page.php">I liked it[/url] Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210125 Share on other sites More sharing options...
DeathStar Posted March 18, 2007 Share Posted March 18, 2007 $_GET['action']... <a href='script.php?action=triger'>I like it link</a> Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210126 Share on other sites More sharing options...
TheFilmGod Posted March 18, 2007 Author Share Posted March 18, 2007 This would refresh the page and trigger the php code, right? Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210130 Share on other sites More sharing options...
cmgmyr Posted March 18, 2007 Share Posted March 18, 2007 It would work kinda like your page counter: link on page: <a href="fav.php?page=$page">I like it!</a> and your fav.php: <?php // Page ID $page = $_GET['page']; require("connect.php"); $result = mysql_query("SELECT fav_count FROM favs WHERE page_id = $page"); $t_count = mysql_num_rows($result); if($t_count > 0){ $cnt = mysql_result($result, 0, 'fav_count'); $cnt++; mysql_query("UPDATE favs SET fav_count = $cnt WHERE page_id = $page"); }else{ mysql_query("INSERT INTO favs ( page_id , fav_count ) VALUES ($page, '1')"); } echo "Thank you for telling us you like this!<br />Please wait..."; echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=$page.php\">"; ?> You can use the same DB structure that I sent to you before...just change the name of the table to "favs" and page_count to "fav_count" Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210132 Share on other sites More sharing options...
TheFilmGod Posted March 18, 2007 Author Share Posted March 18, 2007 I tried it and it doesn't work. It says it has an error. The error is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/T/h/e/TheFilmGod/html/test/fav.php on line 17 Thank you for telling us you like this! Please wait.. Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210141 Share on other sites More sharing options...
DeathStar Posted March 19, 2007 Share Posted March 19, 2007 You can use the same DB structure that I sent to you before...just change the name of the table to "favs" and page_count to "fav_count" Did you do that first? Quote Link to comment https://forums.phpfreaks.com/topic/43277-php-trigger/#findComment-210384 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.