Jump to content


Photo

Select * from ALL Tables


  • Please log in to reply
1 reply to this topic

#1 RootKit

RootKit
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 26 April 2006 - 12:51 PM

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 mysql

2) 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 ?

#2 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 26 April 2006 - 02:22 PM

firstly, create this table in your database.
CREATE TABLE `linkCounter` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`clicks` INT NOT NULL ,
`link` TEXT NOT NULL 
) TYPE = MYISAM;

You'll want a way to add the links to the database... simple form will do the trick.

<?php
// save this as add.php

if(!$_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>";
}
?>

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 100

To list the 20 newest links...

SELECT * FROM linkCounter ORDER BY id DESC LIMIT 20


Sorry i dont have time to be specific...
wisewood: proven fact, I am both wise, and wooden.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users