Jump to content

Return Arrays Inside Arrays?


thefiscster

Recommended Posts

I have this thing that i am trying to make but i cant get it to work.. can anyone help?

 

function sql_read( $dbname,$dbusername,$dbpassword )
{
$names = array();
$password = array();


$connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect");
@mysql_select_db ($dbname) or die("Could not find DataBase");


$query = mysql_query("select * from users");
$numrows = mysql_num_rows($query);

if ($numrows > 0){

while($row = mysql_fetch_assoc($query)){

$names[] = $row["uname"];
$password[] = $row["password"];
$id = $row["id"];

}
$return = array($names,$password,$id);

}else{
$return = array();
}


return $return[];
}



$names = array();

$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];

 

The error i get is

Parse error: syntax error, unexpected '[' in /home/a5480952/public_html/sql/index.php on line 28

Line 28 is "$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];"

 

Please help... i REALLLLD need help with this.. ask questions if you want to know more about what i am trying to do... thanks!

Link to comment
https://forums.phpfreaks.com/topic/235483-return-arrays-inside-arrays/
Share on other sites

$return[] isnt a data map

 

 

function sql_read( $dbname,$dbusername,$dbpassword )
{
$names = array();
$password = array();


$connect = @mysql_connect("mysql11.000webhost.com",$dbusername,$dbpassword) or die("Could Not Connect");
@mysql_select_db ($dbname) or die("Could not find DataBase");


$query = mysql_query("select * from users");
$numrows = mysql_num_rows($query);

if ($numrows > 0){

while($row = mysql_fetch_assoc($query)){

$names[] = $row["uname"];
$password[] = $row["password"];
$id = $row["id"];

}
$return = array($names,$password,$id);

}else{
$return = array();
}


return $return;
}



$names = array();

$names = sql_read("XXXXXX","XXXXXX","XXXXXXX")[0];

 

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.