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
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];

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.