Jump to content

php array help


jas4

Recommended Posts

Hi, trying to get my head around arrays, and I want to take all the results from a query and store them in an array so that I can use them  for later use:

 

here's what i've got so far:

 

$selectDistinct = mysql_query("SELECT DISTINCT mid FROM temp WHERE rand = '$rand'") or die (mysql_error());
$array = array();
while ($row= mysql_fetch_assoc($selectDistinct)){
$mid = $row['mid']."<br>";
$array($mid);             <<-----this is the line im certain is not correct
}

 

and to display the array for later use:

 

foreach ($array as $value) {
echo $value;
}

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/67211-php-array-help/
Share on other sites

Oops, nice catch hostfreak.  ;)

 

<?php

$array = array();
$count = 0;

$selectDistinct = mysql_query("SELECT DISTINCT mid FROM temp WHERE rand = '$rand'") or die (mysql_error());

while ($row= mysql_fetch_assoc($selectDistinct)){
$mid = $row['mid']."<br>";
$array[$count] = $mid;
$count++;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/67211-php-array-help/#findComment-337108
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.