SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Array issue.

  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Array issue.

    Hey Guys,

    I've an array ... This is the code

    PHP Code:
    mysql_select_db($database$connection);
    $sql "SELECT * FROM BAY_Info WHERE BAY_Info.ContID = 2 LIMIT 1";
    $result mysql_query($sql);
    $data = array();    
                    
    while(
    $row mysql_fetch_assoc($result)) 
        {
            
    $data[] = $row;
            
    $title $data['Title'];
        }

    echo 
    $title
    Problem is $title isn't pulling anything back, and it "should" I've got a simlar statement working upon another site and this is in exactly the same context.

    Can anyone shed any light into why the "$title" isn't returning any data. the var is completely blank

    Any help would be highly appreciated.

    Kind Regards
    Dan.

  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $title = $row['Title'];
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlienDev View Post
    $title = $row['Title'];
    Thankyou AlienDev!

    I can't believe i missed that,

    ... Fresh eyes and all that

    Maybe i should take a break!


    Cheers again!

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As you are only fetching one row, you needn't use a loop at all

    PHP Code:
    mysql_select_db($database$connection);
    $sql "SELECT * FROM BAY_Info WHERE BAY_Info.ContID = 2 LIMIT 1";
    $result mysql_query($sql);
    $data mysql_fetch_assoc($result);
    $title $data['Title'];
    echo 
    $title
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Member
    Join Date
    Feb 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by Jake Arkinstall View Post
    As you are only fetching one row, you needn't use a loop at all

    PHP Code:
    mysql_select_db($database$connection);
    $sql "SELECT * FROM BAY_Info WHERE BAY_Info.ContID = 2 LIMIT 1";
    $result mysql_query($sql);
    $data mysql_fetch_assoc($result);
    $title $data['Title'];
    echo 
    $title
    For development i changed the varible to a 2, so that it was easier for a debug.

    But you are quite right if it was a single entry I wouldn't need a loop. But in this instance I do need the loop.

    Cheers thought guys! The speedy reply's are much appreciated.

    /me loves sitepoint!


Tags for this Thread

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
  •