Jump to content

Recommended Posts

I'm trying to create a multi-dimensional array but it is throwing an error that just doesn't make sense.  Does anyone see anything that could be causing this?

 

This code:

echo "<br />cnt:  " . $cnt . "; k:  " . $k . "; v:  " . $v . "\n<br />";
echo "Type (cnt):  " . gettype($cnt) . "<br />";
echo "Type (k):  " . gettype($k) . "<br />";
echo "Type (v):  " . gettype($v) . "<br />";
$values[$cnt][$k]= $v;

Produces this:

cnt: 1; k: date; v: 2015-12-10 
Type (cnt): integer
Type (k): string
Type (v): string

Fatal error: Cannot use string offset as an array in /home/........../putRecords.inc.php on line 47

Sorry I really thought my reply answered that.  But based on your statement, I went back and focused on the code other than line 47 and noticed that there was code further down in the for loop that reset the $values array as a string.  I've since corrected that but now I'm getting a different error.

 

The following code (I've confirmed there is no for loop involved here) produces the what's below that.

    echo "<pre>";
    print_r($k);
    echo "</pre>";
    echo "Value0:  " . gettype($k[0]);
    echo "<br />Value1:  " . gettype($k[1]);
    echo "<br />Type (k):  " . gettype($k);
    $values = join(",",$k);
Array
(
    [0] => ( 2015-12-10,"Jack McCoy",10.00,0,4,1 )
    [1] => ( 2015-12-10,"Jack McCoy",10.00,0,4,1 )
)
Value0: string
Value1: string
Type (k): array
Warning: join(): Invalid arguments passed in /home/........./putRecords.inc.php on line 78
Edited by doni49

your code and data doesn't produce that error for me. some of the possibilities would be - your actual code for the join(....) statement contains some characters that php doesn't recognize, but which appear normal after being put into the forum post (are you typing this code or copy/pasting it from somewhere where it could have been 'published' with some non-ascii character encoding?), the data itself or the point where you are displaying the debugging output contains or is in some html markup that's hiding what is really going on (what does the 'view source' in your browser show for that output?) or the code being posted or the line number being mentioned in the error doesn't actually correspond to what the code really is (this usually happens when you have multiple versions of code and the wrong one is being executed or you have multiple statements and the one producing the error is different from the one you are looking at/posting for us to look at.)

 

you are basically asking someone to look at the tail ass end (symptom) of an animal and describe what the head (cause) looks like. this just results in a bunch of guessing and the problem could likely be a more obscure 4th or 5th thing that i didn't even mention. it's not that i/we don't trust you, it's that we have seen every possible combination of output and stated symptoms that don't tell the full story of what the code or result actually is. what is your full code from the point of the sql query statement up through where the current error is being reported at and are you outputting any html prior to this code that could be hiding some of the output? 

Edited by mac_gyver

Mac,

 

I have no idea what I changed that did it, but I seemed to have fixed it while trying to gather the info you requested.

 

Very odd.

 

Regarding the issue of trying to help with what info I was giving you, I can definitely understand what you're saying there -- on another forum that I frequent, I'm one of the guys that spends quite a bit of time helping others on the board and have dealt with quite a few issues where I felt like I was pulling teeth to get the info I needed to try and help them -- and I do greatly appreciate your effort.

 

I was trying to avoid posting the entire code and asking you (or anyone else) to sort through it all to try to diagnose the issue.  I really thought there must have been something with the code that posted -- just something obscure that I wasn't recognizing.

 

EDIT:  Regarding what I said about "what I changed", I don't REMEMBER changing anything other than adding a couple comments to help you understand what the code is doing.   I really don't know what to make of that.

Edited by doni49
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.