PHP Count Similiar Values in multiple arrays - php

I have values in database like these :
Row 1 : ["2","3"]
Row 2 : ["1","3"]
Row 3 : ["2","3","4"]
In frontend i selected all rows, now i want to show count of similar values.
For eg : Desired o/p from above code : Count for 1 = 1 , 2 = 2 , 3 = 3 , 4 = 1
When i json_decode above values and using print_r i got like these :
Array ( [0] => 2 [1] => 3 )
Array ( [0] => 1 [1] => 3 )
Array ( [0] => 2 [1] => 3 [2] => 4 )
Note : List of rows can be increased, how can i find similar values.
I tried array_intersect as shown here , but didn't work.
Eg: image here
Please Note Data in image, is different from above data
Code to get above data :
$conn = new mysqli("localhost", "root", "", "ams");
$query="SELECT * FROM attendance WHERE subject = '$subj'";
$result = $conn->query($query);
<table class="table table-responsive">
<tr>
<th>Sr. No</th>
<th>Col 1 </th>
<th>Col 2</th>
</tr>
<form method="post">
<?php
$i=1;
if (mysqli_num_rows($result) > 0) {
while ($row=mysqli_fetch_assoc($result)) {
$data = $row['att'];
$data = json_decode($data);
echo "<tr>";
echo "<td>" . $i . "</td>";
echo "<td>" . $row['date1'] . "</td>";
echo "<td>" . print_r($data) . "</td>";
echo "</tr>";
$i++;
}
}
?>
</form>
</table>

So, I made this class for you. It will create the connection when you initalize it.
class RowData {
private $connection;
private $returnContent = array();
private $stmt = null;
function __construct() {
$connection = new PDO("mysql:host=" . MYSQL_HOST . ";dbname=" . MYSQL_DB, MYSQL_USERNAME, MYSQL_PASSWORD);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->connection = $connection;
}
public function get($subj) {
$this->getContentFromDB($subj);
$this->parseContent();
return $this->returnContent;
}
private function getContentFromDB($subj) {
$stmt = $this->connection->prepare("SELECT * FROM attendance WHERE subject = '{$subj}'");
$stmt->execute();
$this->stmt = $stmt;
}
private function parseContent() {
$content = $stmt->fetchAll(PDO::FETCH_OBJ);
if(count($content) < 1) {
throw new Exception('Unable to find any attendies');
}
foreach($content as $values) {
$row = $this->getJsonArray($values->att);
$this->findValues($row);
}
}
private function getJsonArray($content) {
return json_decode($content);
}
private function findValues(array $row) {
foreach($row as $key => $value) {
if(isset($this->returnContent[$value])) {
$this->returnContent[$value] = $this->returnContent[$value] + 1;
} else {
$this->returnContent[$value] = 1;
}
}
return;
}
}
So, let me explain it. The constructor will be the function that is initialized when you write $x = new RowData();. It creates the connection the the MySQL database. All you have to do is change the MYSQL_HOST, MYSQL_DB, MYSQL_USERNAME, MYSQL_PASSWORD values to the appropriate ones. The only function that is available for you to use publicly would be the get() function. The get() function calls 2 separate functions and accepts one value as a parameter. The one value is what you called $subj. One of the functions in the get() function just gets the content from the MySql Table using the query you provided. The second function parseContent() gets an obj from PDO and loops through it. lastly, there is the findValues() function that accepts $row as a parameter. This function will see if the number is already in the data set. If it is, then it is basically a counter. Otherwise, it makes a new key and sets the value to 1.
The values returned from the get() function would be something like this:
array(2=>2, 1=>1, 3=>3, 4=>1)
To use this class, you would write something like this:
$rowData = new RowData();
try {
$content = $rowData->get();
} catch (Exception $e) {
// No results were found
}
Hope this helps! If you need help implementing this, let me know and i'll be more than happy to help you out!

Related

How to print multiple row with several columns in a template?

I have a problem to find a way to get the MySQL-Result returned into an array which contains the data from the statement for every row and column.
controller.class.php:
class Controller {
private $template;
private $view;
private $data;
public function __construct() {
$this->view = new View();
$this->data = new Model();
}
public function display() {
$this->view->setTemplate();
$this->view->setContent("title", "Songs");
$this->view->setContent("content", $this->data->getAllDataFromSongs());
$this->view->setContent("footer", "&copy My name is Jeff\n");
return $this->view->parseTemplate();
}
}
model.class.php:
class Model {
public $db_connection = null;
public function __construct() {
$this->openDatabaseConnection();
}
private function openDatabaseConnection() {
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($this->db_connection->connect_error) {
die('Connect Error (' . $this->db_connection->connect_errno . ') '
. $this->db_connection->connect_error);
}
}
public function getAllDataFromSongs() {
$query = "SELECT * FROM songs";
$row_content = array();
if ($result = $this->db_connection->query($query)){
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
array_push($row_content, $row['id']);
array_push($row_content, $row['artist']);
array_push($row_content, $row['song']);
array_push($row_content, $row['year']);
}
$result->free();
return $row_content;
}
else
echo 'No results';
}
}
view.class.php:
class View {
private $path = 'templates';
private $template;
private $content = array();
public function setContent($key, $value){
$this->content[$key] = $value;
}
public function setTemplate($template = 'default') {
$this->template = $this->path . DIRECTORY_SEPARATOR . $template . '.tpl.php';
}
public function parseTemplate() {
if (file_exists($this->template)) {
ob_start();
require_once('templates/header.tpl.php');
include_once $this->template;
require_once('templates/footer.tpl.php');
$output = ob_get_contents();
ob_end_clean();
return $output;
}
else{
return "Can't find ".$this->template." Template";
}
}
}
default.tpl.php:
<table>
<tr>
<th>ID</th>
<th>artist</th>
<th>song</th>
<th>year</th>
</tr>
<tr>
<?php
foreach ($this->content['content'] as $con){
echo '<td>'. $con . '</td>';
}
?>
</tr>
</table>
<br>
<?php echo $this->content['footer']; ?>
It's not the entire Code, but it should show you what I'm trying.
The problem which I have now, is that the result from getAllDataFromSongs() is an Array with all Datas in behind each other. I can't separate them in a table.
This is the output:
Array (
[0] => 1 [1] => Artist 1 [2] => Song 1 [3] => Year 1
[4] => 2 [5] => Artist 2 [6] => Song 2 [7] => Year 2
[8] => 3 [9] => Artist 3 [10] => Song 3 [11] => Year 3
[12] => 4 [13] => Artist 4 [14] => Song 4 [15] => Year 4
[16] => 5 [17] => Artist 5[18] => Song 5 [19] => Year 5
)
ID artist song year
1 Artist 1Song 1Year 12Artist 2Song 2Year 2 3Artist 3Song 3Year 3...
I hope you can relate what I'm trying to explain..
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
array_push($row_content, $row['id']);
array_push($row_content, $row['artist']);
array_push($row_content, $row['song']);
array_push($row_content, $row['year']);
}
Your problem here is that you are creating a new array element for each column, so in the end you will have them all one after the other, one the same level.
Either create a temporary array first, and then assign that (so that you get rows of columns),
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$temp = [];
array_push($temp, $row['id']);
array_push($temp, $row['artist']);
array_push($temp, $row['song']);
array_push($temp, $row['year']);
array_push($row_content, $temp);
}
Or, assign just the full row array directly:
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
array_push($row_content, $row);
// $row_content[] = $row; // same thing
}
If you get additional columns from your SELECT statement that you don’t want in here, then you should name the columns directly in the SELECT statement, instead of selecting *.)
Additionally, mysqli_result::fetch_all also exists. That function puts all rows in the result set in an array in one go - so you could do away with the while loop completely.

PHP failed to load string from other function as parameter

public function test_passing_string() {
$this - > load - > model(array('registration/Registration_model', 'Jawaban_lab_model'));
$registration = new Registration_model();
$jawaban_lab = new Jawaban_lab_model();
$id = "kuda4";
$jawaban_lab - > load($id); //load jawaban_lab from id
$manualy_written_registration_number = "REG/FM/130102-0001";
echo "registration number from jawaban_lab->registration_number : ".$jawaban_lab - > registration_number
.
"<br> registration number from manualy_written_registration_number : ".$manualy_written_registration_number;
//$registration->load($jawaban_lab->registration_number);
$registration - > load($manualy_written_registration_number);
echo "<br> patient id : ".json_encode($registration - > PatientID);
}
Before go to the question, I will explain my code.
On test_passing_string() function, I call 2 model, and create object for each model there are $registration and $jawaban_lab.
To load data from model I create a load() function. load() has two parameters: column_value and column_name. The default value for column_name is that model's Primary Key.
BUT
The problem comes from
$registration->load($jawaban_lab->registration_number);
I can't retrieve any $registration object data, then I test it by passing the value manually by write this:
$manualy_written_registration_number = "REG/FM/130102-0001";
$registration - > load($manualy_written_registration_number);
And the result appear, doesn't that mean my load() function is fine?
Then I check value inside $jawaban_lab->registration_number by echoing it, surprisingly it display same value as my $manualy_written_registration_number variable.
This is screenshoot in my browser when I run test_passing_string() function:
Using $manualy_written_registration_number value
Using $jawaban_lab->registration_number value
Why can't I use the value from
$jawaban_lab->registration_number even though it has the same value as
my manually writen registraiton number?
public function load($column_value, $column_name = NULL) {
$query = NULL;
if ($column_name != NULL) {
// using custom column.
$query = $this->dbs->get_where($this::DB_TABLE, array(
$column_name => $column_value
));
} else {
// using column primary key .
$query = $this->dbs->get_where($this::DB_TABLE, array(
$this::DB_TABLE_PK => $column_value
));
}
if ($query->row()) {
$this->populate($query->row());
}
}
I use multiple database using CodeIgniter 3, registration_model from SQL server and jawaban_lab from MySQL, jawaban lab have column registration_number to store registration_model primary key
var_dump
First of all thanks to rlanvin and Nirajan N Raju
from rlanvin's comment, i find out the problem is come from codeigniter's query helper, because when i enable codeigniter profiling sql server query return "SELECT CASE WHEN (##OPTIONS | 256) = ##OPTIONS THEN 1 ELSE 0 END AS qi"
so i think codeigniter might be cannot generate query so i create the query manually
i change
public function load($column_value, $column_name = NULL) {
$query = NULL;
if ($column_name != NULL) {
// using custom column.
$query = $this->dbs->get_where($this::DB_TABLE, array(
$column_name => $column_value
));
} else {
// using column primary key .
$query = $this->dbs->get_where($this::DB_TABLE, array(
$this::DB_TABLE_PK => $column_value
));
}
if ($query->row()) {
$this->populate($query->row());
}
}
to this
public function load($column_value, $column_name = NULL) {
$query = NULL;
if ($column_name != NULL) {
$query = $this->dbs->query("SELECT * FROM " . $this::DB_TABLE . " WHERE " . $column_name . " LIKE '" . trim($column_value) . "'");
} else {
$query = $this->dbs->query("SELECT * FROM " . $this::DB_TABLE . " WHERE " . $this::DB_TABLE_PK . " LIKE '" . trim($column_value) . "'");
}
if ($query->row()) {
$this->populate($query->row());
}
}

insert array element into database

I have this function : it's work correctly,
function ms_get_did_detail($id) {
global $link;
$q2="select Dest,Priority from destpr where Id='$id'";
if($res2=mssql_query($q2)) {
while($row2[]=mssql_fetch_array($res2,MSSQL_ASSOC)) {
return $row2;
}
return 0;
}
return 0;
}
I want insert every element (every Dest & Priority) into MYSQL
if($info=ms_get_did_detail($value)) {
print_r($info);
$destination = $info['Dest'];
$priority = $info['Priority'];
my_did_destination ($priority , $dest , $active , $did_voip , $cc_id);
}
It returns array like this :
[0]=> Array (
[Dest] => 100
[Priority] => 1
)
[1]=> Array (
[Dest] => 200
[Priority] => 3
)
[2] => (
)
also , I have this function to insert value in database :
function my_did_destination($priority="",$destination="") {
global $link_voip;
$sql="INSERT INTO cc_did_destination (destination,priority)
VALUES ('$destination','$priority')";
$retval = mysql_query( $sql , $link_voip);
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
}
but It's insert empty value within
You are inserting all rows with an ID of 0, so, if a row with id=0 already exists, it will fail and will not be inserted.
Maybe the easiest solution would be to make yout ID column autoincrement with an SQL statement like:
ALTER TABLE cc_did_destination
MODIFY COLUMN id INT auto_increment;
And then change your INSERT statement for:
$sql="INSERT INTO cc_did_destination (destination,priority)
VALUES ('$destination','$priority')";
Your $info is array of rows, it has numeric keys, not 'Dest'.
You should add index, like $dest = $info[0]['Dest'].
if($info=ms_get_did_detail($value))
{
print_r($info);
$dest = $info[0]['Dest'];
$priority = $info[0]['Priority'];
my_did_destination ($priority , $dest , $active , $did_voip , $cc_id);
}
Or you can iterate through $info with a loop:
if($info=ms_get_did_detail($value))
{
foreach($info as $row) {
$dest = $row['Dest'];
$priority = $row['Priority'];
my_did_destination ($priority , $dest);
}
}
also, remove id from your insert statement
your array is:
[0]=> Array (
[Dest] => 100
[Priority] => 1
)
[1]=> Array (
[Dest] => 200
[Priority] => 3
)
[2] => (
)
so it is a multidimensional array. if you need to insert all those entries, you shouldn't run multiple queries for the same thing. just use mysql batch insert syntax. (e.g. INSERT INTO tbl (col1,col2,col3) VALUES(a,b,c),(d,e,f),(g,h,i))
build the query string for insert.
foreach($a as $i => $v)
{
$b[] = '("'.$v['Dest'].'","'.$v['Priority'].'")';
}
$c = implode(',', $b);
$sql = "INSERT INTO cc_did_destination (destination,priority)
VALUES ".$c;
then run the query
N.B.
Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
There are a couple of issues here.
Firstly your first function returns an array of arrays. Ie, it returns an array with subscript 0 for the first row (it only ever returns one rows details), which is an array containing that rows details.
You assign this to the $info variable, so it contains:-
[0]=> Array (
[Dest] => 100
[Priority] => 1
)
You then assign $info['Dest'] to $destination and $info['Priority'] to $priority. However neither of these exist. You would need $info[0]['Dest'] and $info[0]['Priority'].
2nd issue is that you are trying to assign a specific value to the auto increment id field. Just leave it out of the insert, or give it a value of null.
Quick rewrite and I would suggest you need something like this:-
<?php
if($info=ms_get_did_detail($value))
{
print_r($info);
foreach($info AS $info_row)
{
$destination = $info_row['Dest'];
$priority = $info_row['Priority'];
my_did_destination ($priority , $dest , $active , $did_voip , $cc_id);
}
}
function ms_get_did_detail($id)
{
global $link;
$q2="select Dest,Priority from destpr where Id='$id'";
if($res2=mssql_query($q2))
{
if ($row2[]=mssql_fetch_array($res2,MSSQL_ASSOC))
{
while ($row2[]=mssql_fetch_array($res2,MSSQL_ASSOC))
{
}
return $row2;
}
else
{
return 0;
}
}
return 0;
}
function my_did_destination($priority="",$destination="")
{
global $link_voip;
$priority = mysql_real_escape_string($priority);
$destination = mysql_real_escape_string($destination);
$sql="INSERT INTO cc_did_destination (id,destination,priority) VALUES (NULL,'$destination','$priority')";
$retval = mysql_query( $sql , $link_voip);
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
}
EDIT
If you want to avoid multiple inserts unnecessarily then it might be easier to use an object. This way you can do the inserts easily when there are enough batched up (I normally do 255 at a time).
Something like this, although you probably should use mysqli_*
<?php
if($info=ms_get_did_detail($value))
{
print_r($info);
$insert_object = new insert_details($link_voip);
foreach($info AS $info_row)
{
$insert_object->set_row($info_row['Priority'], $info_row['Dest']);
}
unset($insert_object);
}
function ms_get_did_detail($id)
{
global $link;
$q2="select Dest,Priority from destpr where Id='$id'";
if($res2=mssql_query($q2))
{
if ($row2[]=mssql_fetch_array($res2,MSSQL_ASSOC))
{
while ($row2[]=mssql_fetch_array($res2,MSSQL_ASSOC))
{
}
return $row2;
}
else
{
return 0;
}
}
return 0;
}
class insert_details()
{
private $db;
private $insert_row = array();
public function __CONSTRUCT($db)
{
$this->db = $db;
}
public function __DESTRUCT()
{
$this->do_insert();
}
public function set_row($priority="",$destination="")
{
$priority = mysql_real_escape_string($priority, $this->db);
$destination = mysql_real_escape_string($destination, $this->db);
$this->insert_row[] = "(NULL,'$destination','$priority')";
if (count($this->insert_row) > 255)
{
$this->do_insert();
}
}
private function do_insert()
{
$sql="INSERT INTO cc_did_destination (id,destination,priority) VALUES ".implode(',', $this->insert_row);
$retval = mysql_query($sql, $this->db);
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
$this->insert_row = array();
}
}
Quick rough mysqli_* equivalent, assuming that $link_voip is a mysqli connection. Note that prepared statements with bound parameters are an option (and it makes it harder to forget to escape variables), but it can become a bit messy when you are doing multiple inserts like this.
<?php
if($info=ms_get_did_detail($value))
{
print_r($info);
$insert_object = new insert_details($link_voip);
foreach($info AS $info_row)
{
$insert_object->set_row($info_row['Priority'], $info_row['Dest']);
}
unset($insert_object);
}
function ms_get_did_detail($id)
{
global $link;
$q2="select Dest,Priority from destpr where Id='$id'";
if($res2=mssql_query($q2))
{
if ($row2[]=mssql_fetch_array($res2, MSSQL_ASSOC))
{
while ($row2[]=mssql_fetch_array($res2, MSSQL_ASSOC))
{
}
return $row2;
}
else
{
return 0;
}
}
return 0;
}
class insert_details()
{
private $db;
private $insert_row = array();
public function __CONSTRUCT($db)
{
$this->db = $db;
}
public function __DESTRUCT()
{
$this->do_insert();
}
public function set_row($priority="",$destination="")
{
$priority = mysqli_real_escape_string($this->db, $priority);
$destination = mysqli_real_escape_string($this->db, $destination);
$this->insert_row[] = "(NULL,'$destination','$priority')";
if (count($this->insert_row) > 255)
{
$this->do_insert();
}
}
private function do_insert()
{
$sql="INSERT INTO cc_did_destination (id,destination,priority) VALUES ".implode(',', $this->insert_row);
$retval = mysqli_query($this->db, $sql);
if(! $retval )
{
die('Could not enter data: ' . mysqli_sqlstate($this->db));
}
$this->insert_row = array();
}
}

php to pick up the specific query information from array

<?php
echo "Connecting Database <br>";
$server = 'UKVDEMO03'; //Here you're server
$database = 'smtpFetch';//here the database you want to connect to
$user = 'shoaibsg';//here te user WHO HAS THE RIGHT PERMISSIONS AT THE DATABASE
$pass = '1111111';//and here the user's password
$dsn = "Driver={SQL Server};Server=$server;Database=$database;";
$connect = odbc_connect($dsn, $user, $pass);
echo "Successfully connected....";
//getting subscribe user detail
$subQuery="select emailAddress, dataSet from userDetail";
$subRes=odbc_exec($connect, $subQuery);
$ix=odbc_num_rows($subRes);
//$newArray[]=$newArray array;
$row[]=array();
$newArrayD[]=$row;
$i=0;
$xc=0;
if($ix>0)
{
while($row=odbc_fetch_array($subRes))
{
$newArrayD[$row['emailAddress']] =$row['emailAddress'];
$newArrayD[$row['dataSet']] =$row['dataSet'];
}
}
foreach($newArrayD as $arrayD)
{ $i++;
echo "<br> -" . $arrayD;
echo "-i increment -" . $i;
}
?>
The above displays the below output
-Array
-shoaib#xyz.com
-SSCRUS_CS2002
-nick#xyz.com
-SSCE_CS2002
Now the problem: if I need to display only the emailAddress only in foreach loop it only displays the first character (I used below in foreach loop)
echo "<br> -" . $arrayD['emailAddress'];
such as above output displays as
-
-s
-S
-n
-S
I am baffled, please please help
Your code to generate the array is off. Try this:
while ($row=odbc_fetch_array($subRes))
{
$newArrayD[$row['dataSet']] = $row['emailAddress'];
// This would generate for example $newArrayD['SSCRUS_CS2002'] = 'shoaib#xyz.com'
}
Then, to display them, iterate through the array:
foreach ($newArrayD as $dataset=>$emailaddress)
{
echo "- $emailaddress<br />";
}
EDIT - To save both in seperate arrays:
$newArrayD = array('dataset' => array(), 'emails' => array());
while ($row=odbc_fetch_array($subRes))
{
$newArrayD['dataset'][] = $row['dataSet'];
$newArrayD['emails'][] = $row['emailAddress'];
}
To iterate through the emails:
foreach ($newArrayD['emails'] as $emailaddress)
{
// Code you wish to execute
}
To iterate through the datasets:
foreach ($newArrayD['dataset'] as $dataset)
{
// Code you wish to execute
}
Using this method, the $newArrayD['dataset'][0] will be the dataset linked to $newArrayD['emails'][0] etc.

PDO - Call to a member function fetch() on a non-object?

I looked at all the other posts on this and none of them came up with exactly what my problem is so here we go:
$dbh stores my PDO connection, if I do a var dump on it, it returns:
object(PDO)#1 (0) { }
So I know my PDO connection is working. I then use $sth to hold my query:
$c = 2;
$sth = $dbh->query("SELECT * FROM table WHERE ID = " . $c);
Then to make sure this is working I did:
echo $sth->rowCount();
That return a value of 6. So I know it is grabbing some rows. My next step of checking my problem was to fetch a single row like the following:
$row = $sth->fetch()
print_r($row);
This returned a single row (as it should) with the $row array filled exactly how I would expect it (column names as keys and column values as the array value).
So we are good up to this point. Once I move $row = $sth->fetch() into a while loop my script fails the error it returns is: Call to a member function fetch() on a non-object
Here is my while loop:
while($row = $sth->fetch()){
//while loop stuff here
}
I know it has something to do with the condition of the loop because even when I comment out all the stuff in the middle it still isn't working. What am I doing wrong? Why won't this work? I'm beyond confused on this as it has worked in the past with all the PDO I have done but for some reason it is failing in this script.
If anyone has any tips or something that can help it would be greatly appreciated.
EDIT Since ninetwozero's post worked, I'm posting my class and basically everything I've got to get this figured out.
class html_elements {
var $units;
var $useMaps;
var $cid;
var $uid;
var $companyMoney;
var $currCity;
var $terminals;
var $termLocs;
var $cityArray;
var $cargoArray;
var $cargo;
var $tid;
var $truckArray;
var $load;
var $cityID;
var $cargoID;
var $xp;
var $gasPrice;
var $warning;
function __construct($u, $maps, $c, $userID, $cMoney, $dbh, $city, $tid, $xp){
$this->units = $u;
$this->useMaps = $maps;
$this->cid = $c;
$this->uid = $userID;
$this->companyMoney = $cMoney;
$this->currCity = $city;
$this->terminals = array();
$this->termLocs = array();
$this->cityArray = array();
$this->cargoArray = array();
$this->cargo = array();
$this->tid = $tid;
$this->truckArray = array();
$this->load = 0;
$this->cityID = array();
$this->cargoID = array();
$this->xp = $xp;
$this->gasPrice = 0;
$sth = null;
$sth = $dbh->query("SELECT * FROM tblCTerminals WHERE companyID = " . $c);
//THIS LOOP FAILS
while($row = $sth->fetch()){
$this->termLocs[] = $row['Location'];
}
}
Then in another file that has my class file included in it is:
$h = new html_element($u->get_units(), $u->get_maps(), $u->get_company(), $u->get_user_id(), $c->get_money(), $dbh, $u->get_city(), $u->get_truck_id(), $u->get_xp());
Each of those getters work, I tested them. Also $dbh is what is used my connection file that is included before anything else. So I know all of that is working.
I got to say that you've encountered a pretty interesting error, so let's try some things to pinpoint the cause:
if( $sth == null ) die('My sth is null at #1');
while( $row = $sth->fetch() ) {
if( $row == null ) die('My row is null at #2');
echo '<pre>';
print_r($row);
echo '</pre>';
}
Let me know what this tells you.
Edit:
$sql = 'SELECT * FROM tblCTerminals WHERE companyID = ' . $c;
if( intval($c) == 0 ) { die('Aaaaaaaaaa.......aaaaah.');
foreach ($dbh->query($sql) as $row) {
echo '$row[\'Location\'] is: ' . $row['Location'] .'<br />';
$this->termLocs[] = $row['Location'];
}

Categories