+ Reply to Thread
Results 1 to 6 of 6

Thread: db retrieval
      
   

  1. #1
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default db retrieval

    I have a php display script that takes data from a flat file db and transforms it into an array and then displays that info in a table. No problems with this.

    Each line of data in the db contains 8 items. The first item is the genre or group identifier. For example:
    cars|2001|Dodge|Blue
    cars|2003|Chevy|Green
    truck|2006|Dodge|Black

    What I would like to do create a link to the display script. That link URL would contain or pass a variable (the genre / group identifier) to the display script that in turn displays only those items inside that genre or group.

    The display script is below:
    PHP Code:
    <html>
    <head>
    <style>
    .th{background:#ccdd88;}
    .td{background:#fffff0;}
    .tr{text-align:right;}
    .tc{text-align:center;}
    .pr{padding-right: 6px;}
    .plr{padding-left:6px;padding-right:6px;}
    .w1{width:100px;}
    .w2{width:75px;}
    .w3{width:400px}
    </style>
    <body>
    <?php
    ///////////////////////////////////////////////////////////
    //Here I assume I would declare the genre variable that is passed
    //in the URL from the link ???
    ///////////////////////////////////////////////////////////
    if(!file_exists("db_display_test.txt"))
    {
    echo
    "<center><b>NO RECORDS AT THIS TIME</center></b><br/>
    <center>CHECK BACK LATER</center>"
    ;
    exit;
    }
    echo
    "<table border=6 width=100% cellpadding=2 cellspacing=6>";
    echo
    "<tr>";
    echo
    "<th class='th plr'>Box 1</th>";
    echo
    "<th class='th plr'>Box 2</th>";
    echo
    "<th class='th plr'>Box 3</th>";
    echo
    "<th class='th plr'>Box 4</th>";
    echo
    "<th class='th plr'>Box 5</th>";
    echo
    "<th class='th plr'>Box 6</th>";
    echo
    "<th class='th plr'>Box 7</th>";
    echo
    "</tr>";
    //
    $openedfile fopen"db_display_test.txt"'r' );
    if(
    $openedfile)
    {
    while (!
    feof$openedfile ) )
        {
            
    $line trim(fgets$openedfile ));
            if ( !empty( 
    $line ) )
            {
                list( 
    $genre,$entry1,$entry2$entry3$entry4$entry5$entry6$entry7) = explode"|"$line );
    /////////////////////////////////////////////////////////////
    //What would go here to list only those entries that matched
    //a specific genre?
    ////////////////////////////////////////////////////////////
    echo"<tr>";
    echo
    "<td class='td tc w2'>$entry1</td>";
    echo
    "<td class='td tc w1'>$entry2</td>";
    echo
    "<td class='td tc w2'>$entry3</td>";
    echo
    "<td class='td tc w2'>$entry4</td>";
    echo
    "<td class='td tc w2'>$entry5</td>";
    echo
    "<td class='td tc w2'>$entry6</td>";
    echo
    "<td class='td tc w2'>$entry7</td>";
    echo
    "</tr>";
    }
    }
    fclose$openedfile );
    }
    else
    {
    echo
    "<tr>";
    echo
    "<td class='th w3'>Cannot open file!</td>";
    echo
    "</tr>";
    echo
    "</table>";
    }
    ?>
    </BODY>
    </HTML>
    That is my dilemma.

    Andy
    PHP- is a blast!

  2. #2
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: db retrieval

    Apparently there are issues with the forum as I could not edit my above post.

    Note- I have only listed 4 items for brevity in the db example. Additionally- in the display script, I have not displayed the genre in the table on purpose.

    Andy
    PHP- is a blast!

  3. #3
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default Re: db retrieval

    Hi Andy,



    PHP Code:
    <html>
    <head>
    <style>
    .th{background:#ccdd88;}
    .td{background:#fffff0;}
    .tr{text-align:right;}
    .tc{text-align:center;}
    .pr{padding-right: 6px;}
    .plr{padding-left:6px;padding-right:6px;}
    .w1{width:100px;}
    .w2{width:75px;}
    .w3{width:400px}
    </style>
    <body>
    <?php
    // Receiving the asked for genre, through a form in a previous page
    @$askedforgenre addslashes($_POST['askedforgenre']);
     
    if(!
    file_exists("db_display_test.txt"))
    {
    echo
    "<center><b>NO RECORDS AT THIS TIME</center></b><br/>
    <center>CHECK BACK LATER</center>"
    ;
    exit;
    }
    echo
    "<table border=6 width=100% cellpadding=2 cellspacing=6>";
    echo
    "<tr>";
    echo
    "<th class='th plr'>Box 1</th>";
    echo
    "<th class='th plr'>Box 2</th>";
    echo
    "<th class='th plr'>Box 3</th>";
    echo
    "<th class='th plr'>Box 4</th>";
    echo
    "<th class='th plr'>Box 5</th>";
    echo
    "<th class='th plr'>Box 6</th>";
    echo
    "<th class='th plr'>Box 7</th>";
    echo
    "</tr>";
    //
    $openedfile fopen"db_display_test.txt"'r' );
    if(
    $openedfile)
    {
    while (!
    feof$openedfile ) )
        {
            
    $line trim(fgets$openedfile ));
            if ( !empty( 
    $line ) )
            {
                list( 
    $genre,$entry1,$entry2$entry3$entry4$entry5$entry6$entry7) = explode"|"$line );
    /////////////////////////////////////////////////////////////
    //What would go here to list only those entries that matched
    //a specific genre?
    ////////////////////////////////////////////////////////////
    if ($genre == $askedforgenre) {
    echo
    "<tr>";
    echo
    "<td class='td tc w2'>$entry1</td>";
    echo
    "<td class='td tc w1'>$entry2</td>";
    echo
    "<td class='td tc w2'>$entry3</td>";
    echo
    "<td class='td tc w2'>$entry4</td>";
    echo
    "<td class='td tc w2'>$entry5</td>";
    echo
    "<td class='td tc w2'>$entry6</td>";
    echo
    "<td class='td tc w2'>$entry7</td>";
    echo
    "</tr>";
    }
    }
    }
    fclose$openedfile );
    }
    else
    {
    echo
    "<tr>";
    echo
    "<td class='th w3'>Cannot open file!</td>";
    echo
    "</tr>";
    echo
    "</table>";
    }
    ?>
    </BODY>
    </HTML>
    $askedforgenre of course can be changed to any variable name you like. A simple "if" statement is enough to only display those listings that match the required genre.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  4. #4
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: db retrieval

    Naval- YOU ROCK! That was incredibly simple and it works perfectly.

    Thanks again!

    Reason: Currently I have about 125 pages each that lists businesses. So for Alarm Companies one would go to alarm_companies.html. But- I can enter all the businesses in a db and then use one page with the php script to get only those businesses that pertain to those that were requested. Thus effectively allowing me to have only two pages that serve up hundreds of pages worth of data. I hope you get what I mean.

    I also did this: I am making a page (scrollable) with all the links to the various businesses / services for my directory. The link is made like this;
    <a href="my_db.php?pg_genre=alarm_companies">Alarm Companies</a><br />
    And in the script I have:
    $pg_genre = $_GET['pg_genre'];

    That way I do not need a form for them to fill out.

    Very excited. I am going to be up all night!

    Talk to ya later and thanks again.
    Andy
    PHP- is a blast!

  5. #5
    navaldesign's Avatar
    navaldesign is offline General & Forum Moderator
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,061

    Default Re: db retrieval

    Yes, that is a very common way of passing values from a page to another. I use it myself all the time. I also use forms, if more than one values are to be passed (in that case i use database driven independent fieds or dependent (chained) dropdowns).Well done Andy!
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  6. #6
    Andy128's Avatar
    Andy128 is offline Major General
    Join Date
    Dec 2005
    Location
    Michigan
    Posts
    2,322

    Default Re: db retrieval

    Naval-
    I also made the table scrollable and placed that code inside an html box. In this manner- it is more SE friendly than an I-Frame containing the table.

    Have a look at this site. I believe it will be a good resource to others that you help along the way.
    http://www.htmlbasix.com/scrollingtable.shtml

    Lots of cool stuff on that site.

    Cheers-

    Andy
    PHP- is a blast!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49