how to associate a randomly generated key with mysql primary key using php


Problem :

I have a table in which I storing files uploaded by users and a php page which is showing all the files uploaded by a particular user. There is a download link when user clicks on that link I am passing the file id to my download.php page then in download.php page I am retrieving file data using that id. I want to generate a random key each time a user click a download link for a particular file and using this key and file id I want to retrieve file data from database. How can I do it.



Solution :

Create a second table where you store your random keys and link them to the files you want to have downloaded.

Example:

|-------|-------------------------|
| key   | file                    |
|-------|-------------------------|
| jfdhj | /downloads/somefile.txt |
|-------|-------------------------|

Of course, you could use the ID of the file in the file column, and join it. The reason to do this, is that you can create several keys for one file.

Also: why not just use the ID from the database?


Mysql Tutorials

Mysql Howto..

How to show utf8 character in ZF2 from MySql

How to insert a date in mysql via php? [closed]

how to pass C++ variables to Insert of c++ using Mysql ++

how to insert image and data in mysql database using php source code

how to do a join in MySQL with a select?

Mysql - How to retrieve fields from two tables based on certain criteria?

How to show this structured info from database using mySQL/PHP?

How to display the content of more then one SQL database row

How to add new columns to over 10 GB innodb mysql table without affecting production performance?

C# WPF Show Image from Mysql

MySQL: How to filter out groups that don't contain a specific value?

How to update in MySql columns

how to add identity column for a table using mysql server 5.6?

How can I load an .xls file to a mysql database in php?

How to connect to MYSQL database on server via Terminal on Macbook?

How to match string with escaped quote character in MySQL?

how to get position rank of specific row using just mysql query?

How to show only certain rows from a table in my DB?

How to associate different elements to one to many categories?

MySQL: how can i convert a string '1,2,3,4' to a (1,2,3,4) so i'll be able to use it in a 'where X in ()' statement

Need advice on how to save all stock changes for rpg game in mysql

How should I structure a DB / build a Query where I sort posts by number of friends 'interacting' with it

How do I get the max id from the first n id's in a MySQL table?

How to search data from multiple tables using Mysql?

Django: How can you stop long queries from killing your database? [closed]

newbie: how to upload images from a form with PHP and mySQL

How to add a N:M relationship to my MySQL symptoms and diseases database?

Do SQL mapping tables speed up queries? How do you use them?

How to normalize mysql database table

How to tell if a mySql event succeeded or not?