Jump to content

Setting Variables Dynamically


random1

Recommended Posts

Thanks :D

 

I've tried it with my array but the variable names confuse me.

 

My Array is outputted as:

 

Array ( [0] => Array ( [iD] => 1 [string Name] => login message [string Text] => Welcome, please login ... ) [1] => Array ( [iD] => 2 [string Name] => login successful message [string Text] => You have successfully logged in. ) [2] => Array ( [iD] => 3 [string Name] => login unsuccessful message [string Text] => You failed to login. Please check the username and password you enterd and the profile you selected. ) [3] => Array ( [iD] => 4 [string Name] => login heading [string Text] => Login ) [4] => Array ( [iD] => 5 [string Name] => logout link [string Text] => Logout ) [5] => Array ( [iD] => 6 [string Name] => logout successful message [string Text] => You have logged out of your account successfully. ) [6] => Array ( [iD] => 7 [string Name] => xhtml [string Text] => XHTML ) [7] => Array ( [iD] => 8 [string Name] => css2 [string Text] => CSS2 ) [8] => Array ( [iD] => 9 [string Name] => powered by [string Text] => powered by phpSandbox ) [9] => Array ( [iD] => 10 [string Name] => language [string Text] => Australian English ) [10] => Array ( [iD] => 11 [string Name] => author [string Text] => Author ) [11] => Array ( [iD] => 12 [string Name] => javascript message full [string Text] => String for Javascript

 

I've tried:

 

extract($results, EXTR_PREFIX_ALL, "lang");

 

Can someone help with using extract() on this array?

 

public function getRecords($sql)

{

$records = array();

 

//variables

$connection = $this->m_Connection;

 

//get the result from database with SQL

$result = $connection->query($sql);

if ($connection->error) {

$errorMessage = '**** mysqli error ' . $connection->errno. ': ' . $connection->error;

error_log($errorMessage);

throw new DatabaseBadSqlStatementException($errorMessage);

}

 

//read out data

while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){

$records[] = $row;

}

return $records;

}

 

$results = $database->getRecords("select languagestring_ID as 'ID', languagestring_name as 'String Name', languagestring_text as 'String Text' from language_strings where language_ID ='1'");

 

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.