Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    234
    Thanks
    0
    Thanked 0 Times in 0 Posts

    MySQL statement within mysql_fetch_array

    For some reason this script isn't working... Can anyone see why?

    PHP Code:
    <?php

        
    include_once 'conn.php'# Include database connection details
        
        
    $mlist mysql_query("SELECT x,y,z,n FROM arbiter WHERE a='1'"); # Obtain x,y,z and name fields from table 'arbiter'
        
        
    while ($ml mysql_fetch_array($mlist)) { # Loop through all rows found where a = 1 in table 'arbiter'
            
            
    $x $ml['x'];
            
    $y $ml['y'];
            
    $z $ml['z'];
            
    $n $ml['n'];
            
            
    $pl mysql_query("SELECT * FROM dumps WHERE x='$x', y='$y', z='$z'"); # Using values from table 'arbiter', get all values from table 'dumps' which correspond to values being looped through.
            
            
    $pl_n $pl[0]; # N
            
    $pl_p $pl[1]; # P
            
    $pl_r $pl[2]; # R
            
    $pl_s $pl[3]; # S
                    
            
    echo "$pl_p $pl_n<br>";
                
            echo 
    "$pl_r $pl_s<br>";
            
        }
        
    ?>
    Thankyou very much everyone
    Last edited by newmand2; 10-07-2004 at 02:34 PM.
    Dave

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    what happens when you run it?

    Error message or bad results?

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    234
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, shoulda mentioned that, eh

    i get a blank screen
    Dave

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    ok In that case I guess your not finding any results with your query.
    Do you use a front end such as phpmyadmin? If do run your query in that and see what you get

  • #5
    Regular Coder
    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    234
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Using PHPMyAdmin, I have 10 rows in the DB.

    I then altered my code to this:

    PHP Code:
    <?php

        
    include_once 'conn.php'# Include database connection details
        
            
    $pl mysql_query("SELECT * FROM dumps WHERE x='1', y='2', z='2'"); # Using values from table 'arbiter', get all values from table 'dumps' which correspond to values being looped through.
            
            
    $pl_x $pl['x']; # N
            
    $pl_y $pl['y']; # P
            
    $pl_z $pl['z']; # R

                    
    echo "$pl_x $pl_y<br>";
        
    ?>
    I still get no results displayed, even though in my DB there is a record where x=1, y=2 and z=2...

    So I am thinking that I have a problem with this query, and the rest is ok
    Last edited by newmand2; 10-07-2004 at 03:05 PM.
    Dave

  • #6
    4xz
    4xz is offline
    Regular Coder
    Join Date
    Aug 2004
    Location
    localhost
    Posts
    163
    Thanks
    0
    Thanked 1 Time in 1 Post
    If I may make a side-comment. Dunno if u designed this datamodel yourself, but with columnnames like a,b,c etc. U will be finding yourself in a lot of trouble in 12 months.

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Location
    London, UK
    Posts
    234
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, this is only a testing file, and I'll integrate it into the full design with proper filenames once I am done.
    Dave

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Didn't think you could use comma's in the query. I've always used
    PHP Code:
    $pl mysql_query("SELECT * FROM dumps WHERE x='1' AND y='2' AND z='2'"); 
    Try and stay away from the perl comments too, I think they're depreciated, try to use // or /* */
    Also, try adding or die() at the end of your query
    PHP Code:
    $pl mysql_query("SELECT * FROM dumps WHERE x='1' AND y='2' AND z='2'") or die("Unable to complete query ".mysql_error()); 

  • #9
    New Coder
    Join Date
    May 2003
    Location
    in a small damp cupboard
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i think you're missing a mysql_fetch_assoc in there!!

    PHP Code:
    <?php

        
    include_once 'conn.php'# Include database connection details
        
            
    $pl mysql_query("SELECT * FROM dumps WHERE x='1', y='2', z='2'"); # Using values from table 'arbiter', get all values from table 'dumps' which correspond to values being looped through.
            
    while($pl mysql_fetch_assoc($pl)){    
            
    $pl_x $pl['x']; # N
            
    $pl_y $pl['y']; # P
            
    $pl_z $pl['z']; # R
                    
            
    echo "$pl_x $pl_y<br>";
    }
        
    ?>
    try that

  • #10
    Regular Coder
    Join Date
    Apr 2004
    Location
    Los Angeles
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah mrjamin's right. You could also use mysql_fetch_row:
    PHP Code:
    <?php 

      
    include_once 'conn.php'# Include database connection details 
      
      
    $result mysql_query("SELECT * FROM dumps WHERE x='1', y='2', z='2'");         
      while(
    $row mysql_fetch_row($result)){     
            
    $pl_x $row[0]; # N 
            
    $pl_y $row[1]; # P 
            
    $pl_z $row[2]; # R 
                     
            
    echo "$pl_x $pl_y $pl_z<br>"
    }  
    ?>


  •  

    Posting Permissions

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