Saturday, 8 June 2013

Accessing information in array

Accessing information in array

Ok Im getting a bit confused with arrays in php. This is the code
  $search = "%" . $search ."%";
    // Step 1: Establish a connection
    $db = new PDO("mysql:host=localhost;dbname=########", "#########", "###########");

// Step 2: Construct a query
$query = "SELECT * FROM movies WHERE title LIKE " . $db->quote($search);

// Step 3: Send the query
$result = $db->query($query);

// Step 4: Iterate over the results
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
    var_dump($row);

    echo $row['title'];

}


// Step 5: Free used resources
$result->closeCursor();
$db = null;
Now when I search for say "Candyman" it returns 6 results, what I am tring to do is something like $row['title'][3] (So I can grab the title of the 3rd film in the array) however this doesnt work $row['title']; displays all 6 titles how do I access the next level?
Below is a link to the search I am using http://www.gorrors.com/moviesearch.php?search=candyman
Sorry for the newbie question but Im at a loss any help would be greatly appeciated.

No comments:

Post a Comment