Jump to content

[SOLVED] Help with array construction


EchoFool

Recommended Posts

Not sure if i understand this correctly but im getting an error to do with my array syntax....

 

the idea is it creates a list of id's then picks one at random, but i cannot get it to work... any help is much appreciated.

 

Parse error: syntax error, unexpected '[', expecting ')' 
in C:\xampp\htdocs\name.php on line 427

 

Im unsure on what i have done wrong.

 

This is what i got:

 

<?php
$SELECT = mysql_query("SELECT ID FROM users")
   Or die(mysql_error());
$a = 0;
While($row = mysql_fetch_assoc($Find)){
$ID = $row['ID'];

Array
(
    [$a] => $ID;
)
$a = $a + 1;
}


shuffle($a);

$_SESSION['MissionID'] = $a;
?>

 

Link to comment
https://forums.phpfreaks.com/topic/115086-solved-help-with-array-construction/
Share on other sites

You have done almost everything wrong. This is what I believe you are trying to do:

<?php
$Find = mysql_query("SELECT ID FROM users")
   Or die(mysql_error());
$a = array();
While($row = mysql_fetch_assoc($Find)){
    $a[] = $row['ID'];
}


shuffle($a);

$_SESSION['MissionID'] = $a;
?>

 

Ken

Sure here it is:

 

<?php
$Find = mysql_query("SELECT ID FROM users")
   Or die(mysql_error());
If(mysql_num_rows($Find)>0){
$a = array();
While($row = mysql_fetch_assoc($Find)){

$ID  = $row['ID'];
    $a[] = $ID;   // this is where the error is
}

shuffle($a);

$_SESSION['MissionID'] = $a;
}
?>

 

Thank you for replying :)

 

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.