Hi, need some help getting column keys for a query, setting them as constant
and WHILE its getting rows it echo's each $row["$column1"] and ["$column2"]
I don't know how else to explain it so here is the script with and details in the comment section.
and WHILE its getting rows it echo's each $row["$column1"] and ["$column2"]
I don't know how else to explain it so here is the script with and details in the comment section.
PHP:
<?php
class PDO_connection {
function do_query($getme) {
//random do stuff connecting
try {
$this->dbh = new PDO("mysql:host=localhost;dbname=test_db", user, password);
/*** set the error reporting attribute ***/
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$STH = $this->dbh->query($getme);
$STH->setFetchMode(PDO::FETCH_ASSOC);
//PAUSE - this is where we get results like echo $row['id']
while($row = $STH->fetch()) {
//*
The Problem here is that sometimes I want to query only one colum, or sometimes different column
the $getme variable above only bring in a statement like
SELECT id FROM table1 ORDER BY updated_date DESC LIMIT 5
after while $row = $STH->fetch(), i want to be able to get the array results and get keys so I can
do something like $row['id'] or if I'm getting 2 column results for a query then get those 2 keys
and set them up like echo $row['id'] .'is for'. $row['firstsname']. this function will only be used to get
different select statements.
*//
}
} //End of Try
catch(PDOException $e) {
echo "Currently Having Problems, try again later.";
} //End of Catch
}
}
$query_one = 'SELECT id FROM table1 ORDER BY updated_date DESC LIMIT 5';
$query_two = 'SELECT id, firstname FROM table1 WHERE lastname=jordan ';
$test = new PDO_connection();
echo $test->caller($se);
?>