MasterACE14 Posted September 22, 2010 Share Posted September 22, 2010 Hello, I have the following MySQL query selecting data from 2 tables: $P1itemWq = Database::query("SELECT * FROM `ca_items`, `ca_shop` WHERE `ca_items`.`itemid` = `ca_shop`.`id` && `ca_items`.`ownerid`='".$P1['id']."' && `ca_shop`.`type`='weapon' "); $P1itemW = Database::fetch_array($P1itemWq); However when I try to display the query data after fetch'ing it into an array, I appear to get 2 arrays displayed which have the same values? // test $P1wepCount = Database::num_rows($P1itemWq); if($P1wepCount > 0) { foreach($P1itemW as $key => $val) { echo $key." -> ".$val."<br />"; } } exit; result: Quote 0 -> 6 id -> 15 1 -> 1 ownerid -> 1 2 -> 15 itemid -> 15 3 -> 15 4 -> Club name -> Club 5 -> description -> 6 -> 10 price -> 10 7 -> 2 power -> 2 8 -> weapon type -> weapon thanks in advance! Link to comment https://forums.phpfreaks.com/topic/214086-dual-array/ Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 That's because you're using fetch_array(). If you wish to return only the associative array use fetch_assoc(), or for the numeric array use fetch_row() .. That's assuming of course the DB class you're using has those methods. Link to comment https://forums.phpfreaks.com/topic/214086-dual-array/#findComment-1114010 Share on other sites More sharing options...
MasterACE14 Posted September 22, 2010 Author Share Posted September 22, 2010 Quote That's because you're using fetch_array(). If you wish to return only the associative array use fetch_assoc(), or for the numeric array use fetch_row() .. That's assuming of course the DB class you're using has those methods. ah ha! I've just added a fetch_assoc(); method to my DB class and it's working! thank you kindly! much appreciated Link to comment https://forums.phpfreaks.com/topic/214086-dual-array/#findComment-1114019 Share on other sites More sharing options...
miltonstephen2010 Posted September 22, 2010 Share Posted September 22, 2010 Thanks MrAdam, It also working with me. Link to comment https://forums.phpfreaks.com/topic/214086-dual-array/#findComment-1114028 Share on other sites More sharing options...
Adam Posted September 22, 2010 Share Posted September 22, 2010 No problem Link to comment https://forums.phpfreaks.com/topic/214086-dual-array/#findComment-1114033 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.