I'm trying to build a web portal that connects to a DB I created. I am busy trying to create a function writen in php. The function is to open a connection to the databse, select the values from the table (including two fields - the ID and the value).
Once the values are available I would like to put them into an array (that is the name the respective table).
The function so far works in that it can access the database, it can also get all value. The only issue is that I cant manage to create a while loop that will place the key and the value into a new array that is named after the respective table.
Thanks so much in advanced! Chelsea
function createArray($id, $value, $table)
require_once ('C:XAMPP/mysqli_connect.php'); // Connect to the db.
// Make the query:
$q = 'SELECT '. $id .', '. $value .' FROM '. $table .' ORDER BY '. $value .' ASC';
$r = @mysqli_query ($dbc, $q); // Run the query.
// Fetch and print all the records:
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
mysqli_free_result ($r); // Free up the resources.
mysqli_close($dbc); // Close the database connection.
$country1 = createArray("CountryID", "CountryValue", "country");