SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Tulsa, OK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    no results with PHP code

    Hi, I'm having a problem with my PHP code where I get no result and even no errors when I perform a command. What I'm trying to do is GET a list of records that belong to a certain category. I'll post the code to see if you have suggestions, but is there also a way I can step through what it is doing to see what might be wrong (a way to debug or compile perhaps??)

    Here is the code. The select statement works. It doesn't do anything past the if (isset($_GET['project_name'])) Thanks for any suggestions!:
    PHP Code:
    <?php include "..\config.php";

    // Create a form allowing the user to select a project type to view.
    echo '<div align="center">
    <form method="get" action="display_records.php">
    <select name="type">
    <option value="NULL">Choose a Project:</option>
    '
    ;

    // Retrieve and display the available projects.
    $query 'SELECT * FROM project ORDER BY project_name ASC';
    $result mysql_query ($query);
    while (
    $row mysql_fetch_array ($resultMYSQL_NUM)) {
            echo 
    '<option value="'$row[1], '">'stripslashes($row[1]), '</option>
    '
    ;
    }

    // Complete the form.
    echo '</select>
    <input type="submit" name="submit" value="Go!">
    </form>
    </div>
    '
    ;

    // Retrieve the documents for a particular project, if selected.
    if (isset($_GET['project_name'])) {

            
    $t intval($_GET['project_name']); // Make sure the project_name is an interval.
            
            // Get the current project name.
            
    $query "SELECT project_name FROM project WHERE project_id=$t";
            
    $result mysql_query ($query);
            list (
    $project_name) = mysql_fetch_array ($resultMYSQL_NUM);

            echo 
    "<hr /><div align=\"center\"><b>$project_name Links</b><br />
    <small>(All documents will open in their own window. Recently added documents are listed first.)</small></div>\n"
    ;

            
    $first TRUE// Initialize the variable.
            
            // Query the database.
            
    $query "SELECT data_id, data_name, data_project FROM data WHERE data.data_project = project.project_name ORDER BY date_submitted desc";
            
    $result mysql_query ($query);

            
    // Display all the documents.
            
    while ($row mysql_fetch_array ($resultMYSQL_ASSOC)) {
            
                    
    // If this is the first record, create the table header.
                    
    if ($first) {
                            echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
            <tr>
                    <td align="right" width="50%"><font size="+1">Document</font></td>
                    <td align="left" width="50%"><font size="+1">Project</font></td>
            </tr>'
    ;
                    } 
    // End of $first IF.
                    
                    // Display each record.
                    
    echo "        <tr>
                            <td align=\"right\"><a href=\"
    {$row['url']}\" target=\"_new\">" stripslashes($row['data_name']) . "</a></td>
                            <td align=\"left\">
    {$row['data_description']}</td>
                    </tr>\n"
    ;
                    
                    
    $first FALSE// One record has been returned.
            
            
    // End of while loop.

            // If no records were displayed...
            
    if ($first) {
                    echo 
    '<div align="center">There are currently no links in this category.</div>';
            } else {
                    echo 
    '</table>'// Close the table.
            
    }
            
    // End of $_GET['project_name'] conditional.

    mysql_close(); // Close the database connection.
    ?>

  2. #2
    SitePoint Enthusiast EspenA's Avatar
    Join Date
    May 2004
    Location
    Norway, Oslo
    Posts
    85
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gi goatlip,

    You can try to echo different texts downwards like this:

    PHP Code:
    // Retrieve the documents for a particular project, if selected. 
    if (isset($_GET['project_name'])) { 

      echo 
    '<p>Isset -> Okay</p>';

      
    $t intval($_GET['project_name']); // Make sure the project_name is an interval. 

      
    echo "<p>t-variable: $t</p>";

      
    // Get the current project name. 
      
    $query "SELECT project_name FROM project WHERE project_id=$t";
      echo 
    "<p>Query: $query</p>";

      
    $result mysql_query ($query) or die(mysql_error());

      list (
    $project_name) = mysql_fetch_array ($resultMYSQL_NUM) or die(mysql_error());

      echo 
    "<hr /><div align=\"center\"><b>$project_name Links</b><br /> 
    <small>(All documents will open in their own window. Recently added documents are listed first.)</small></div>\n"


      
    $first TRUE// Initialize the variable. 
             
      // Query the database. 
      
    $query "SELECT data_id, data_name, data_project FROM data WHERE data.data_project = project.project_name ORDER BY date_submitted desc"

      echo 
    "<p>Second query: $query</p>";

      
    $result mysql_query ($query) or die(mysql_error());

      
    // Display all the documents. 
      
    while ($row mysql_fetch_array ($resultMYSQL_ASSOC)) { 
             
                    
    // If this is the first record, create the table header. 
                    
    if ($first) { 
                            echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center"> 
            <tr> 
                    <td align="right" width="50%"><font size="+1">Document</font></td> 
                    <td align="left" width="50%"><font size="+1">Project</font></td> 
            </tr>'

                    } 
    // End of $first IF. 
                     
                    // Display each record. 
                    
    echo "        <tr> 
                            <td align=\"right\"><a href=\"
    {$row['url']}\" target=\"_new\">" stripslashes($row['data_name']) . "</a></td> 
                            <td align=\"left\">
    {$row['data_description']}</td> 
                    </tr>\n"

                     
                    
    $first FALSE// One record has been returned. 
             
            
    // End of while loop. 

            // If no records were displayed... 
            
    if ($first) { 
                    echo 
    '<div align="center">There are currently no links in this category.</div>'
            } else { 
                    echo 
    '</table>'// Close the table. 
            

             
    // End of $_GET['project_name'] conditional. 

    mysql_close(); // Close the database connection. 
    ?> 

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Tulsa, OK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, I try doing that and still nothing, I hit the submit button and just get a blank page. no errors show up. Even in the error logs. this is really confusing.


    any other ideas??

  4. #4
    SitePoint Addict The Mog's Avatar
    Join Date
    Dec 2002
    Location
    Manchester UK
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try adding this


    <?php
    }else{// End of $_GET['project_name'] conditional.
    print "Something";

    }
    mysql_close(); // Close the database connection.
    ?>


    then you will see if it is skipping your conditional statement

    K-

  5. #5
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Before your conditional statement echo out the $_GET['project_name']. If it's not going past that portion it's because that isn't set. Just do an echo right before the statement.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2004
    Location
    Tulsa, OK
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, got it, my first problem was on line 6. I had the wrong field name. It should have been.

    PHP Code:
    <select name="project_name"
    My other problem was with the $t variable which is discussed in this post

    http://www.sitepoint.com/forums/showthread.php?t=171245

    my final code ended up looking like the following:


    PHP Code:
    <?php include "..\config.php";
    $basedir "f:/";
    // Create a form allowing the user to select a project type to view.
    echo '<div align="center">
    <form method="get" action="display_records.php">
    <select name="project_name">
    <option value="NULL">Choose a Project:</option>
    '
    ;

    // Retrieve and display the available projects.
    $query 'SELECT * FROM project ORDER BY project_name ASC';
    $result mysql_query ($query);
    while (
    $row mysql_fetch_array ($resultMYSQL_NUM)) {
            echo 
    '<option value="'$row[2], '">'stripslashes($row[2]), '</option>
    '
    ;
    }

    // Complete the form.
    echo '</select>
    <input type="submit" name="submit" value="Go!">
    </form>
    </div>
    '
    ;

    // Retrieve the documents for a particular project, if selected.
    if (isset($_GET['project_name'])) {

            
    $t intval($_GET['project_name']); // Make sure the project_name is set to an interval.
            // Get the current project name.
            
    $query "SELECT project_name FROM project WHERE project_parent_id=$t";
            
    $result mysql_query ($query);
            list (
    $project_name) = mysql_fetch_array ($resultMYSQL_NUM);

            echo 
    "<hr /><div align=\"center\"><b>$project_name Links</b><br />
    <small>(All documents will open in their own window. Recently added documents are listed first.)</small></div>\n"
    ;

            
    $first TRUE// Initialize the variable.
            
            // Query the database.
            
    $query "SELECT data_name,data_project FROM data,project WHERE data.data_project = project.project_name AND project.project_parent_id=$t ORDER BY data_name desc";
            
    $result mysql_query ($query);

            
    // Display all the documents.
            
    while ($row mysql_fetch_array ($resultMYSQL_ASSOC)) {
            
                    
    // If this is the first record, create the table header.
                    
    if ($first) {
                            echo 
    '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
            <tr>
                    <td align="right" width="50%"><font size="+1">Document</font></td>
                    <td align="left" width="50%"><font size="+1">Project</font></td>
            </tr>'
    ;
                    } 
    // End of $first IF.
                    
                    // Display each record.
                    
    echo "        <tr>
                            <td align=\"right\"><a href=\"
    {$row['data_url']}\" target=\"_new\">" stripslashes($row['data_name']) . "</a></td>
                            <td align=\"left\">
    {$row['data_project']}</td>
                    </tr>\n"
    ;
                    
                    
    $first FALSE// One record has been returned.
            
            
    // End of while loop.

            // If no records were displayed...
            
    if ($first) {
                    echo 
    '<div align="center">There are currently no links in this category.</div>';
            } else {
                    echo 
    '</table>'// Close the table.
            
    }
            
    // End of $_GET['project_name'] conditional.

    mysql_close(); // Close the database connection.
    ?>


Bookmarks

Posting Permissions

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