Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
01-21-2012, 07:06 AM #1
- Join Date
- Sep 2011
- Thanked 0 Times in 0 Posts
retrieve record fron db one by one
I need to retrieve records one by one
for example: If I have nth numbers of records in db table then these nth numbers records I can get one by one using for loop or else then I can create a file for each record
Just help me about how can I fetch record one by one. the file creation process I can do my self
01-21-2012, 10:15 AM #2
- Join Date
- Jan 2012
- Thanked 4 Times in 4 Posts
First things first, you'd need to apply an id to each row in your table, if you haven't already, you may need to copy the rows from your table and start again, this time with a column called "id" before all the other columns. Give it a type of "INT" and an index of "PRIMARY", and turn on AUTO_INCREMENT. Now put all your rows back in, but leave the id column blank as this will update itself automatically.
Now create a new file, name it something like entry.php, and add the following code:
//Replace "username" and "password" with your username and password for the FTP.
//If needed, change localhost to your appropriate server, but this is normally not necessary.
$connection = mysql_connect('localhost','username','password') or die('cannot connect to database');
//Replace database with your database name.
$database = mysql_select_db("database") or die('not selected');
$entry = mysql_real_escape_string($_GET['entry']);
//Replace table with your table name.
$getEntry = mysql_query("SELECT * FROM table WHERE id = '$entry'");
while($entry_data = mysql_fetch_array($getEntry))
Now to view this page the user would have to go to yoursite.com/entry.php?entry=*id*
If you want to change this to something like yoursite.com/entry/1/ you can edit the .htaccess file which should be located in the root directory of your domain. If it's not already there, create it. Add the following code:
RewriteEngine on RewriteRule ^entry/([A-Za-z0-9]+)/$ /entry.php?entry=$1
RewriteRule ^entry/([A-Za-z0-9]+)/$ /entry.php?entry=$1
Hope this helps.