Fetching More than one Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The1corrupted
    New Member
    • Feb 2007
    • 134

    Fetching More than one Array

    This is truly frustrating. I'm trying to fetch one array from two different tables. Personally, I think it would work but I always get this:

    Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in C:\Vardaes\more 1.php on line 50

    Well... here's line 50 and the array fetch just before it.

    $tablesummon=my sql_query("SELE CT * FROM user_table WHERE cn='$user'");
    $array=mysql_fe tch_array($tabl esummon);

    $summon=mysql_q uery("SELECT * FROM rooms WHERE ns='$array[12]' , ew='$array[13]' , ud='$array[14]'");
    $ray=mysql_fetc h_array($summon );

    I'm working with an XYZ coordinate system, or trying to at least. I'm trying to pull back the correct coordinates for the correct display.

    I've even tried parsing it with a while statement and it still comes up with that same error. Need help badly.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You must specify an AND relation in your second query, like this:
    Code:
    $summon=mysql_query("SELECT * FROM rooms 
               WHERE ns='$array[12]' 
               AND ew='$array[13]' 
               AND ud='$array[14]'");
    It is also good practise to catch any errors that might result from the SELECT statement, then your statement must be coded something like:
    Code:
    $summon=mysql_query("SELECT * FROM rooms 
               WHERE ns='$array[12]' 
               AND ew='$array[13]' 
               AND ud='$array[14]'")
      or die ("SELECT error": ".mysql_error());
    Ronald :cool:

    Comment

    • The1corrupted
      New Member
      • Feb 2007
      • 134

      #3
      This only brings up more problems to my attention. Sessions... somehow I can never get these right. I've been through the tutorials and I'm stuck scratching my head because when I put it into practice, it blows up on me.

      This also has to do with MySQL because I want to compare the session variables to pull back the right info.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Now let's get this straight: don't change the thread subject!

        Did my reply help you with your SELECT query or not? And if not, what was the error this time?

        Ronald :cool:

        Comment

        • The1corrupted
          New Member
          • Feb 2007
          • 134

          #5
          Quite... Guess I'll just start a new thread, then.

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            That still gives no answer to the question whether the post (AND relations) helped or not.

            Ronald :cool:

            Comment

            • The1corrupted
              New Member
              • Feb 2007
              • 134

              #7
              Okay... More to do with arrays. How can I get a rolling output from a mysql table?

              [PHP]
              <?php
              session_start() ;
              $x=$_SESSION['xcoord'];
              $y=$_SESSION['ycoord'];
              $z=$_SESSION['zcoord'];

              $checklocal=mys ql_qyery("SELEC T *
              FROM user_table
              WHERE ns='$x'
              AND ew='$y'
              AND ud='$z'");
              $checkarray=mys ql_fetch_array( $checklocal);
              ?>[/PHP]
              Obviously, this will equal more than one entry so how do I keep it rolling until none are left?

              Comment

              • ronverdonk
                Recognized Expert Specialist
                • Jul 2006
                • 4259

                #8
                Use the mysql_fetch_* command. Like the following example that gets one row at a time from the result set and echoes the content of column 'column_name' to the screen.

                [php]while ($checkarray=my sql_fetch_array ($checklocal)) {
                echo $checkarray['column_name' ];
                // ... etc ...
                }[/php]

                Ronald :cool:

                Comment

                • The1corrupted
                  New Member
                  • Feb 2007
                  • 134

                  #9
                  Coolies! Thanks.

                  Comment

                  • ronverdonk
                    Recognized Expert Specialist
                    • Jul 2006
                    • 4259

                    #10
                    You are welcome (of course)!

                    Ronald :cool:

                    Comment

                    Working...