www.webdeveloper.com
Results 1 to 10 of 10

Thread: Pulling Information from Database

  1. #1
    Join Date
    Feb 2011
    Posts
    177

    Question Pulling Information from Database

    Ok so The first page works it shows the Folders you can choose from

    THe second part is the one giving me issues.

    When you click on a folder name I want it to pull the information from the database related to that folder only. Example say I chose Christmas Folder so it would display the text and id from that folder only not any of the other folder information.

    Here is the coding I have for the page that works.

    PHP Code:
    <?php 
    // Script Error Reporting
    error_reporting(E_ALL);
    ini_set('display_errors''1');
    ?>
    <?php 
    // Connect to the MySQL database  
    include "COnnection"
    $FolderList "";
    $sql mysql_query("SELECT * FROM AlbumNames ORDER BY date_added DESC");
    $productCount mysql_num_rows($sql); // count the output amount
    if ($productCount 0) {
        while(
    $row mysql_fetch_array($sql)){ 
                 
    $id $row["id"];
                 
    $albumname $row["albumname"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
                 
    $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
            <tr>
              <td width="17%" valign="top"><a href="Photo_Gallery.php?id=' 
    $albumname '"><img style="border:#666 1px solid;" src="American Legion Photos/$albumname/' $albumname '.jpg" alt="' $albumname '" width="77" height="102" border="1" /></a></td>
              
          </table>'
    ;
        }
    } else {
        
    $FolderList "We have no products listed in our store yet";
    }
    mysql_close();
    ?>
    THE ABOVE CODE WORKS

    PHP Code:
    <?php 
    error_reporting
    (E_ALL);
    ini_set('display_errors''1');
    ?>
    <?php 
    // Check to see the URL variable is set and that it exists in the database
    if (isset($_GET['id'])) {
        
    // Connect to the MySQL database  
        
    include "Connection File"
        
    $albumname preg_replace('#[^0-9]#i'''$_GET['id']);  I want to pull all information for this folder only)
        
    // Use this var to check to see if this ID exists, if yes then get the product 
        // details, if no then exit this script and give message why
        
    $sql mysql_query("SELECT * FROM AlbumPhotos WHERE id='$id'");
        
    $productCount mysql_num_rows($sql); // count the output amount
        
    if ($productCount 0) {
            
    // get all the product details
            
    while($row mysql_fetch_array($sql)){ 
                 
    $albumname $row["albumname"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
             }
             
        } else {
            echo 
    "That album does not exist.";
            exit();
        }
            
    } else {
        echo 
    "Data for this album is not here.";
        exit();
    }
    mysql_close();
    ?>
    THE ABOVE CODE DOES NOT WORK

    Any ideas and help are much appreciated. I want to pull all information from the database for the selected folder and only that folder.

  2. #2
    Join Date
    Dec 2011
    Posts
    34
    In your first script
    change
    Code:
    Photo_Gallery.php?id=' . $albumname
    to this
    Code:
    Photo_Gallery.php?id=' . $id
    in your second script
    change this
    Code:
    if (isset($_GET['id'])) { 
        // Connect to the MySQL database   
        include "Connection File"; 
        $albumname = preg_replace('#[^0-9]#i', '', $_GET['id']);  I want to pull all information for this folder only)
    to this
    Code:
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'])) { 
        // Connect to the MySQL database   
        include "Connection File"; 
        $id = $_GET['id'];  I want to pull all information for this folder only)
    Now see if you can explain the changes I made

  3. #3
    Join Date
    Feb 2011
    Posts
    177

    Why Corrections/ Getting one error

    Code:
    PHP Code:

    Photo_Gallery
    .php?id=' . $id 
    You need it to pull the id information or else it can not get the other information from the database it has to have an id to start?

    Still learning so any pointers are great.


    PHP Code:
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'])) { 
        
    // Connect to the MySQL database   
        
    include "Connection File"
        
    $id $_GET['id'];  I want to pull all information for this folder only
    Preg_Match so that it only pulls the ids with the album name that was selected
    then your telling it to get id so that it can show the information located on the database?

    Are those the right answer?


    WHen I add
    PHP Code:
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'])) { 
    I get a syntax error, unexpected '{' in I have looked around and can not figure out where that is getting the error from any ideas?


    Thank you for the help after I fix error Ill let you know if it worked.

  4. #4
    Join Date
    Dec 2011
    Posts
    34
    The ID is a numeric value, pulled from the database giving the Albums location within the database.
    the preg pattern
    Code:
    #^[0-9]+$#
    # - Delimenter - marks start/end of pattern
    ^ - Start of string
    [0-9] - only allow characters within range of 0 - 9 (digits)
    + - we want 1 or more of the above
    $ = End of string

    So the pattern will allow any numeric value for $_GET['id'] if it passes this check than
    it assigns $id to this value. Making your SQL query valid (BTW: you don't need quotes around $id in your query statement, since it's numeric.

    The line looks perfectly valid, can you repost the code you are working on now?

  5. #5
    Join Date
    Feb 2011
    Posts
    177

    Question

    Thank you for all your help this is still such a learning process so much to learn.


    HERE is the Code I am using now:
    PHP Code:
    <?php 
    // Check to see the URL variable is set and that it exists in the database
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'],$matches) {
        
    // Connect to the MySQL database   
        
    include "Connection"
        
    $id $_GET['id'];  
        
    // Use this var to check to see if this ID exists, if yes then get the product 
        // details, if no then exit this script and give message why
        
    $sql mysql_query("SELECT id FROM AlbumPhotos WHERE id=$id");
        
    $productCount mysql_num_rows($sql); // count the output amount
        
    if ($productCount 0) {
            
    // get all the product details
            
    while($row mysql_fetch_array($sql)){ 
                 
    $albumname $row["albumname"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
            }
             
        }
    else {
            echo 
    "That item does not exist.";
            exit();
        }
            
    } else {
        echo 
    "Data to render this page is missing.";
        exit();
    }
    mysql_close();
    ?>
    HTML Code:
    <img src="American Legion Photos/$albumname/<?php echo $id; ?>.jpg" alt="<?php echo $albumname; ?>" />
    Last edited by shutterbug; 01-12-2012 at 02:31 PM.

  6. #6
    Join Date
    Dec 2011
    Posts
    34
    Code:
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'],$matches) {
    your missing a paren
    Code:
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'],$matches)) {

  7. #7
    Join Date
    Feb 2011
    Posts
    177

    Question Thank You / Underfined Index issu

    I knew it was a simple symbol just could not figure out what it was.

    Now its telling me
    Undefined index: albumname and date_added

    PHP Code:
    while($row mysql_fetch_array($sql)){ 
                 
    $albumname $row["albumname"];// Issue Here
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"])); //Issue Here 

  8. #8
    Join Date
    Dec 2011
    Posts
    34
    Code:
    SELECT id FROM AlbumPhotos WHERE id=$id
    you are only returning the id of that record, either add the other fields you need, or use * for all fields
    Code:
    SELECT * FROM AlbumPhotos WHERE id=$id

  9. #9
    Join Date
    Feb 2011
    Posts
    177

    Question Forgot to Change that back

    Thank you it works.

    Only one problem. When they select the folder on the first page then the second page should pull all images are in that folder not just one.

    Example

    Christmas 2011 - Say I clicked This One
    American Legion Riders
    Test Folder


    Then it opens the second page

    displays all images in that folder

    Img Img Img Img

    The information for the images is the id.jpg its just not showing but one image.



    The way I have it now when I click on the Christmas Folder it works but the other folders do not I get this messeage "Data to render this page is missing."

    If I click on the Christmas Folder then I pulls this information for Test Folder.


    Here is the first page code:

    PHP Code:
    <?php 
    // Run a select query to get my letest 6 items
    // Connect to the MySQL database  
    include "Connection File"
    $dynamicList "";
    $sql mysql_query("SELECT * FROM AlbumNames ORDER BY date_added DESC");
    $productCount mysql_num_rows($sql); // count the output amount
    if ($productCount 0) {
        while(
    $row mysql_fetch_array($sql)){ 
                 
    $id $row["id"];
                 
    $albumname $row["albumname"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
                 
    $dynamicList .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
            <tr>
              <td width="17%" valign="top"><a href="Photo_Gallery.php?id=' 
    $id '">' $albumname '</a></td>
              
          </table>'
    ;
        }
    } else {
        
    $dynamicList "We have no products listed in our store yet";
    }
    mysql_

    Here is the Second Page Code:

    PHP Code:
    <?php 
    // Check to see the URL variable is set and that it exists in the database
    if (isset($_GET['id']) && preg_match('#^[0-9]+$#',$_GET['id'],$matches)) {
        
    // Connect to the MySQL database   
        
    include "Connection FIle"
        
    $id $_GET['id'];  
        
    // Use this var to check to see if this ID exists, if yes then get the product 
        // details, if no then exit this script and give message why
        
    $sql mysql_query("SELECT * FROM AlbumPhotos WHERE id=$id");
        
    $productCount mysql_num_rows($sql); // count the output amount
        
    if ($productCount 0) {
            
    // get all the product details
            
    while($row mysql_fetch_array($sql)){ 
                 
    $albumname $row["albumname"];
                 
    $date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
            }
             
        }
    else {
            echo 
    "That item does not exist.";
            exit();
        }
            
    } else {
        echo 
    "Data to render this page is missing.";
        exit();
    }
    mysql_close();
    ?>
    Second Page HTML Code
    HTML Code:
    <a href="American Legion Photos/$albumname/<?php echo $id; ?>/.jpg" border="0"  rel="lightbox[American Legion Photos/$albumname/<?php echo $id; ?>.jpg]" title="<?php echo $id; ?>"><img src="storeadmin/American Legion Photos/$albumname/<?php echo $id; ?>.jpg" alt="<?php echo $id; ?>" width="100" height="100" /></a>

    If it helps the Database has the following information
    id albumname
    1 CHristmas Party
    2 Folder Test
    3 Test
    4 CHristmas Party
    5 Test
    Last edited by shutterbug; 01-12-2012 at 04:00 PM.

  10. #10
    Join Date
    Sep 2014
    Posts
    1

    error ReadRespinse() failed

    hi i get the ReadResponse() failed: The server did not return a response for this request.
    in products page.php pls help asap

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
  •  
HTML5 Development Center



Recent Articles