Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    69
    Thanks
    6
    Thanked 0 Times in 0 Posts

    retrieve record fron db one by one

    Hi,

    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

    Regards

  • #2
    New Coder
    Join Date
    Jan 2012
    Posts
    53
    Thanks
    8
    Thanked 4 Times in 4 Posts

    Post

    Quote Originally Posted by shajiuddin View Post
    Hi,

    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

    Regards
    What are the columns in said table, and where would you want them to appear on the page?

    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:

    PHP Code:
    <?php
    session_start
    ();

    //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');
    ?>
    <html>
    <head>
        <title>test</title>
    </head>
    </html>
    <body>
    <?php
    if(isset($_GET['entry']))
        {
        
    $entry mysql_real_escape_string($_GET['entry']);
            
    //Replace table with your table name.
        
    $getEntry mysql_query("SELECT * FROM table WHERE id = '$entry'");
    ?>
    <?php
    while($entry_data mysql_fetch_array($getEntry))
             {
    ?>
    <?=$entry_data
    ['id']?>
    <br />
    <?=$entry_data['name']?>
    <?php
             
    }
          }
    ?>
    </body>
    </html>
    That code would display the id for the entry and the name of the entry. You can change <?=$entry_data['column']?> to display any information related to the row that has been fetched, just replace what's between the apostrophes with the column name and it will display it.

    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:

    Code:
    RewriteEngine on
    
    RewriteRule ^entry/([A-Za-z0-9]+)/$ /entry.php?entry=$1
    If the "RewriteEngine on" is already there, you just need to add this code below it:

    Code:
    RewriteRule ^entry/([A-Za-z0-9]+)/$ /entry.php?entry=$1
    So in the end you can just type yoursite.com/entry/1/ and it will show you any data for a row that's got the id 1, and so on so forth.

    Hope this helps.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •