I have the fallowing database table ‘table_name’:
+----+---------+--------------+
| ID | user_id | meta_key1 |
+----+---------+--------------+
| 1 | 1 | d |
| 2 | 1 | f |
| 3 | 1 | c |
| 4 | 2 | g |
| 5 | 3 | 1 |
| 6 | 3 | 2 |
| 7 | 4 | 4 |
| 8 | 4 | 5 |
| 9 | 4 | 5 |
| 10 | 4 | 5 |
+----+---------+--------------+
I would like to select * from all entries where the user_id = ‘1’.
The code I’m using now returns only the first value:
$query = mysql_query("SELECT * FROM table_name WHERE user_id='1'");
$row = mysql_fetch_assoc($query);
while($row){
return $row["meta_key1"];
}
The result is always the first entry from the table_name where the user_id='(given_id)’:
d
While I’d like this result:
d
f
c
Change your code to :
Currently, you only call
mysql_fetch_assocone time.You need to call it every time you need the next row.