I have a query:
SELECT * FROM categorys
LEFT JOIN category_info ON categorys.cat_id=category_info.cat_id
WHERE `cat_name` = 'aname'
ORDER BY `cat_order`
When I run this in phpMyAdmin I get an cat_id back regardless of if there is a match in the second table.
However, when I run this query in my PHP code I get a blank cat_id back, as shown by this print_r():
Array ( [cat_id] => [cat_name] => baths [type] => main [cat_order] =>
99 [cat_img] => [display] => 1 [deleted] => 0 [desc_id] => [desc] =>
[text] => )
Why would there be a different result when the query is exactly the same?
EDIT:
My PHP code:
$getcatidsql = "SELECT * FROM categorys
LEFT JOIN category_info ON categorys.cat_id=category_info.cat_id
WHERE `cat_name` = '{$cname}'
ORDER BY `cat_order";
$getcatidresult = $db->query( $getcatidsql );
$catdata = $db->fetchRow( $getcatidresult );
function query() {
$this->query_total++;
if (func_num_args() == 1) {
$sql = func_get_arg(0);
} else {
$args = func_get_args();
for ($i=1;$i<count($args);$i++) if (!is_numeric($args[$i])) $args[$i] = '"'.mysql_real_escape_string($args[$i]).'"';
$sql = vsprintf(array_shift($args),$args);
}
if ($result = mysql_query($sql,$this->db_connection)) {
return $result;
} else {
$this->dberror( $this->db_connection, $sql );
}
}
function fetchRow($result,$type=MYSQL_ASSOC)
{
if($result)
$row = mysql_fetch_array($result,$type);
return $row;
}
I think you must not use select * (also because of same column names in both tables) , but select exactly fields for your needs
.. and you’ll get right results from both php code and phpmyadmin