Jump to content

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:

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.