MySQL returns only one row

mysql, php

Solution

$query = mysql_query("SELECT `title`,
                             `url_title`
                        FROM `fastsearch`
                       WHERE `tags`
                            LIKE '%$q%'
                       LIMIT 5");

while ($row = mysql_fetch_assoc($query)) {
    print_r($row);
}

- You misspelled `$query` in your example

- `mysql_fetch_assoc()` will return a row each time it is called, and `FALSE` when out of rows. Use that to your advantage, by assigning a variable to it in the condition. Within the `while()` loop, `$row` will be the current row.

Problem

I have this simple PHP code: ``` $query = mysql_query("SELECT `title`, `url_title` FROM `fastsearch` WHERE `tags` LIKE '%$q%' LIMIT 5"); $query2 = mysql_fetch_assoc($quer); print_r($query2); ``` It only returns this: ``` Array ( [title] => Kill Bill Vol 1. [url_title] => kill_bill_vol_1 ) ``` I have 3500+ rows in the table, and running the SQL in PhpMyAdmin works perfectly.

Original source