Can't you just remove c.id from query? You don't need that within SELECT statement if you need it in your query:
$sql = "SELECT a.id, a.Title, a.Category, c.cateName
FROM ads_list AS a
LEFT JOIN ads_cate AS c ON c.id=a.Category
WHERE a.Category = $CatID";
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) { echo $row['id'] // equals c.id }
If you need it though, you can also use PDO and value binding. I do not recommend using mysql_* functions. PDO is just better and easier to read:
$query = $pdo->query('SELECT a.id, a.Title, a.Category, c.id, c.cateName
FROM ads_list AS a
LEFT JOIN ads_cate AS c ON c.id=a.Category
WHERE a.Category = $CatID');
$query->bindColumn(1, $id_a); //numerical index goes from 1
$query->bindColumn(4, $id_b);
$query->bindColumn('Title', $title); //you can also index using column name if it's possible
while ($query->fetch(PDO::FETCH_BOUND)) //fetch returns true if there are any records to fetch
{
echo $id_a;
echo $id_b;
echo $title;
}
Downside of this solution (and mysql_fetch_row) is that any change within the query can result in change of indexes. And even if now it's not the problem, believe me - I've seen a query with 30 returned columns and mysql_fetch_row applied. It was a nightmare. Impossible to find out which column in database is represented by certain variable.
id
in every table. – Bill Karwin Aug 4 '11 at 22:09