RootKit Posted April 26, 2006 Share Posted April 26, 2006 i have 2 problem.1) I want to designe a link counter. when you click the link the number should increase and be writen to the table at mysql2) How can I list the informations at ALL TABLES at Mysql that order by the most clicked 100? and how can I list the 20 last inserted data??what can i do ? Quote Link to comment https://forums.phpfreaks.com/topic/8457-select-from-all-tables/ Share on other sites More sharing options...
wisewood Posted April 26, 2006 Share Posted April 26, 2006 firstly, create this table in your database.[code]CREATE TABLE `linkCounter` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`clicks` INT NOT NULL ,`link` TEXT NOT NULL ) TYPE = MYISAM;[/code]You'll want a way to add the links to the database... simple form will do the trick.[code]<?php// save this as add.phpif(!$_POST){echo "<FORM METHOD=POST ACTION=$PHP_SELF>";echo "<INPUT TYPE=TEXT NAME=input_link>";echo "<INPUT TYPE=SUBMIT VALUE=Submit>";echo "</FORM";}else{$query = mysql_query("INSERT INTO `linkCounter` ( `link` ) VALUES ( '$_POST[input_link]' )");echo "$_POST[input_link] has been added to the database";echo "<a href=$PHP_SELF>Click here to add another link</a>";}?>[/code]Just noticed the time... no time to flesh this out in full... sorry.Next, run a mysql query to list all the links that are in the linkCounter table"SELECT * FROM linkCounter"For each link, have it like this;<a href=out.php?link=$the_link_from_the_database&id=$the_id_from_the_database>$the_link_from_the_database</a>Set out.php so that it updates the clicks field of the linkCounter table where id is the id from the address bar ($_GET[id]) and add one to the number already there... then redirect the visitor to the page they selected.To list top100 by popularity, most popular first;SELECT * FROM linkCounter ORDER BY clicks DESC LIMIT 100To list the 20 newest links...SELECT * FROM linkCounter ORDER BY id DESC LIMIT 20Sorry i dont have time to be specific... Quote Link to comment https://forums.phpfreaks.com/topic/8457-select-from-all-tables/#findComment-30941 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.