Jump to content

dual array?


MasterACE14

Recommended Posts

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

  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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.