Returning variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Odisey
    New Member
    • May 2007
    • 14

    Returning variables

    What is wring with this?

    Code:
    <?php  #Color instrument vars
           # ODC August 4, 2008
    	      
    require_once ('??????.php'); //Connect to database  RESET TO SAFE PATH ONCE IT FUNCTIONS
    
    // Define variables
    
    $var1 = "Hello"; 
    
    // Make selection  
    
    $query = "SELECT images FROM movie_images ORDER BY RAND() LIMIT 3";
    $result = mysql_query($query);
    
    // Table
    
    if ($result) {
        $row = mysql_fetch_array ($result, MYSQL_ASSOC);
        $s1 = $row[0];
        $s2 = $row[1];
        $s3 = $row[2];
    
    
    echo '<p>'. $s1 . '</p>';
    echo '<p>'. $s2 . '</p>';
    echo '<p>'. $s3 . '</p>';
    echo '<p>'. $var1 . '</p>';
    }
    
    
    
    mysql_close(); // Close database connection
    
    ?>

    Thank you!
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    We don't guess.

    Please be more descriptive.

    What happens? What doesn't happen?

    Comment

    • Odisey
      New Member
      • May 2007
      • 14

      #3
      The test variable Hello prints.... Other than that nothing happens...


      Nothing obviously wrong with the syntax?


      Thatnk you,
      Marc

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by Odisey
        The test variable Hello prints.... Other than that nothing happens...


        Nothing obviously wrong with the syntax?


        Thatnk you,
        Marc
        You should always do some error checking; add an ELSE to your IF and an OR DIE() to your mysql query
        Code:
        $query = "SELECT images FROM movie_images ORDER BY RAND() LIMIT 3";
        $result = mysql_query($query) or die(mysql_error());
         
        // Table
         
        if ($result) {
            $row = mysql_fetch_array ($result, MYSQL_ASSOC);
            $s1 = $row[0];
            $s2 = $row[1];
            $s3 = $row[2];
         
         
        echo '<p>'. $s1 . '</p>';
        echo '<p>'. $s2 . '</p>';
        echo '<p>'. $s3 . '</p>';
        echo '<p>'. $var1 . '</p>';
        } else {
        echo 'There was a problem...';
        }
        Please remember to use code tags when posting in the forum!

        Comment

        • Odisey
          New Member
          • May 2007
          • 14

          #5
          I usually do.

          It prints the test var Hello..... Nothing else...


          The error message does not print.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Odisey.

            There might be no error; your query might just have returned no results.

            Comment

            • Odisey
              New Member
              • May 2007
              • 14

              #7
              There is one that is there.... Look at ASSOC. It should be NUM.

              There are results... 8 AMF.


              TYFR

              Comment

              Working...