php - Can't fetch the column data even after successful execution of query -



php - Can't fetch the column data even after successful execution of query -

here snippet of code

$query="select cid,city_name city_trade city_name '$num' or pin='$num'"; $res=pg_query($query); if (!$res) { echo "data not found city"; exit; }else{ $id=pg_fetch_assoc($res)['cid']; $name=pg_fetch_assoc($res)['city_name']; var_dump($id); var_dump($name); }

and getting $name null , $id correct. why city_name not coming after successful execution of query ? , how can fetch without using query ?

you're getting 1 result you're trying fetch 2 rows result set. need phone call pg_fetch_assoc() 1 time result set , can access values want there:

// results of query in associative array $row = pg_fetch_assoc($res); // each desired value $id = $row['cid']; $name = $row['city_name'];

php sql database postgresql

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -