Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I currently have an array that stores the values of one column from the database and that works fine however I want to store more than one column value. So in my example I want a team and their venue stored in the same array index. I can't seem find a way to do this.

If anyone can perhaps help that would be much appreciated.

share|improve this question
 
Please show us some code, SE is not a newspaper –  Qǝ uoɯᴉs Apr 12 at 17:00
 
Show us the code you've tried to use thus far –  John Conde Apr 12 at 17:00
 
This is what I have so far.. while($row = mysql_fetch_array($query)){ $names[$loop]= $row['teamName']; $loop++; } –  Ade Apr 12 at 17:03
add comment

2 Answers

Do you mean something like this?

$i = 0;
$my_array = array();

while ($row = mysql_fetch_assoc($result))
{
    $my_array[$i]['name'] = $row['names'];
    $my_array[$i]['otherfield'] = $row['otherfield'];
    $i++;
}

now you can do something like this

echo $my_array[2]['name'];
share|improve this answer
 
That looks like what I want to do! I'm no longer at my computer at the moment but will test it when I get back to it. I appreciate your help with it this far! –  Ade Apr 12 at 17:12
 
No problem ;) I typed it here on the fly so beware of typos and syntax errors. But you should get the general idea. Oh and mysql_fetch_assoc is short for mysql_fetch_array($result, MYSQL_ASSOC) –  user762805 Apr 12 at 17:29
1  
mysql_fetch_assoc is deprecated and you should be using mysqli_fetch_assoc –  DiscoInfiltrator Apr 12 at 17:43
add comment

Simply do :

$rows = [];
while($row = mysql_fetch_assoc($result)) {
    $rows[] = $row;
}
share|improve this answer
 
mysql_fetch_assoc is deprecated and you should be using mysqli_fetch_assoc –  DiscoInfiltrator Apr 12 at 17:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.