Jump to content

Select * from ALL Tables


RootKit

Recommended Posts

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 ?
Link to comment
Share on other sites

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.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>";
}
?>
[/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 100

To list the 20 newest links...

SELECT * FROM linkCounter ORDER BY id DESC LIMIT 20


Sorry i dont have time to be specific...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.