Reputation: 461
I am trying to grab the first 3 title names of my search results to display somewhere else and when i use
$rows[0]['title']
It works fine and shows the first title, or so its looks to be anyway but when i use
$rows[1]['title'] or $rows[2]['title']
It gives me the same results that this gives me
$rows[0]['title']
I have tried flipping everything around and doing all I can think of to grab the first 3 title names. anyone have any ideas?
Another thing to note is when I use
$rows['title']
I get no result at all.
EDIT:
Here is what is above the data i am trying to get.
$rows = array();
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
//$rows[$row['id']] = $row;
$rows[] = $row;
}
foreach ($rows as $c => $row) {
}
Upvotes: 2
Views: 106
Reputation: 14777
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$rows[] = $row;
}
foreach ($rows as $row) {
print_r($row);
print("<br>");
}
So, if you have the following $rows
:
[
['a', 'b', 'c'],
['d', 'e', 'f']
]
The code above would show you output similar to
array(
[0] => 'a',
[1] => 'b',
[2] => 'c'
);
for the first $row
in $rows
. That is $rows[0][0] = 'a'
or, in the foreach
loop, $row[0] = 'a'
.
Upvotes: 1