PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Thu Jul 19, 2007 10:11 am
hi.
i'am having some problems resolving this issue, everytime i load an array and them i test if a value is set in a variable, i get the following notice, "PHP Notice: Uninitialized string offset: 0"
Code: Select all
//$dayResult is an array
$dayResult = $dbprod->returnProductInfo($today, $productCod, $_site);
//$dayResult[0]['productID'] is a string
if ( $dayResult[0]['productID'] != "" ) { --> PHP Notice: Uninitialized string offset: 0
...
}
can someone tell how can i remove this notice ?
regards
Last edited by
bouncer on Fri Jul 20, 2007 10:15 am, edited 1 time in total.
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Thu Jul 19, 2007 10:17 am
use this instead
if (isset($array['key'])) ;
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Thu Jul 19, 2007 10:24 am
Begby wrote: use this instead
if (isset($array['key'])) ;
i've already try that and no progress
Code: Select all
//$dayResult is an array
$dayResult = $dbprod->returnProductInfo($today, $productCod, $_site);
if ( isset ( $dayResult['productID'] ) ) { --> cant get the $dayResult[0]['productID'] value
...
}
regards
Last edited by
bouncer on Thu Jul 19, 2007 10:26 am, edited 1 time in total.
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Thu Jul 19, 2007 10:25 am
do a print_r() on your array and paste the output here.
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Thu Jul 19, 2007 10:29 am
i get this
Code: Select all
Array ( [0] => Array ( [id] => 14 [date] => 2007-07-30 [productID] => 13349 [cod] => 408081 [price] => 389 [description] => [auxiliar] => 0 [site] => 1 )
regards
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Thu Jul 19, 2007 10:42 am
Are you doing print_r($dayResult) right there in your code above the if?
The notice you are getting is when you try to access a string by a character and its past the end of the string, you will get the error if you do this
Code: Select all
$string = 'test' ;
echo $string[2] ; // echos 's'
echo $string[7] ; // echos '' but gives you a notice
Why that is doing that in your code I haven't a clue. Also try doing var_export or var_dump on your dayResult right before the if statement.
Also, are you sure the notice is happening on that exact line? When I make a string and try to access it like $string[0]['key'] it throws a different error instead of that notice.
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Thu Jul 19, 2007 10:51 am
if i do,
Code: Select all
var_dump($dayResult[0]['productID']); --> string '13349'
var_dump($dayResult['productID']); --> NULL
but in the if statment it throws this notice, dont know why
, and everything is working right
regards
Begby
Forum Regular
Posts: 575 Joined: Wed Dec 13, 2006 10:28 am
Post
by Begby » Thu Jul 19, 2007 12:12 pm
HAHAH... whoops
not equals is != in php, not <>. I am sorry I put you through the trouble and didn't notice that from the start. Give that a try
Chalks
Forum Contributor
Posts: 447 Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana
Post
by Chalks » Thu Jul 19, 2007 12:21 pm
woah, I've never seen <> before. What language(s) is that from?
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Thu Jul 19, 2007 12:28 pm
In MySQL it is equivalent to !=
Chalks
Forum Contributor
Posts: 447 Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana
Post
by Chalks » Thu Jul 19, 2007 12:29 pm
I should have figured that one out.
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Fri Jul 20, 2007 10:17 am
thank you guys, i've already fix that issue
.
but i continue with the same problem: "PHP Notice: Uninitialized string offset: 0". anyone knows what i'm doing wrong in,
Code: Select all
//$dayResult is an array
$dayResult = $dbprod->returnProductInfo($today, $productCod, $_site);
//$dayResult[0]['productID'] is a string
if ( $dayResult[0]['productID'] != "" ) { --> PHP Notice: Uninitialized string offset: 0
...
}
thanks in advance
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 20, 2007 5:44 pm
The zero should be a hint.
bouncer
Forum Contributor
Posts: 162 Joined: Wed Feb 28, 2007 10:31 am
Post
by bouncer » Mon Jul 23, 2007 8:39 am
feyd wrote: The zero should be a hint.
sorry for my ignorance but, what do you mean with that ?
thanks in advance
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Jul 23, 2007 2:32 pm
There's a zero in "$dayResult[0]['productID']" and a zero referenced in the error.