I want to store all items from a field into a PHP Array.
- The database is an ".accdb" file
- The connection with the database is through PHP's ODBC functions
This is the table I've been using for my test code (its name is "Posts1"):
This is the latest version of my PHP code, it only returns one result.
<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/Project6/phptest/SampleUsers.accdb";
$connection = odbc_pconnect("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" .$dbName, ";", ";");
if ($connection != true){ exit; };
$query_string = "SELECT Body FROM Posts1";
$results = odbc_exec ( $connection , $query_string);
$output = odbc_result($results, 1);
odbc_close ( $connection );
echo $output;
?>
If I change the index of the result I'm trying to access, the code won't work.
Ex: $output = odbc_result($results, 2);
If that did work, I planned to create a loop to transfer the items to an array.
Before this, I also tried using fetch_array but could not make it work. It was especially difficult because I was using JSON to communicate the array between the client and server, which I have no experience with.
The web side I got from here, it was literally copy and paste. Basically the website is just a link and a div: when the link is clicked, some javascript sends off a request for the PHP. The div is updated based on what the PHP echos.
I'm hoping for some guidance, I'm completely new to web development.
EDIT
I've made a working version now, it makes use of odbc_fetch_array instead of odbc_result. Any other answers are still appreciated, if they offer an improvement I'll accept them.
$output = array();
for ($value = array_pop(odbc_fetch_array($results)), $i = 1;
$value != false;
$value = array_pop(odbc_fetch_array($results)), $i++)
{
$output[$i] = $value;
}