Current location: Hot Scripts Forums » Programming Languages » PHP » This strange error, anyone had this ?


This strange error, anyone had this ?

Reply
  #1 (permalink)  
Old 05-17-06, 06:57 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Question This strange error, anyone had this ?

Fatal error: Cannot use string offset as an array
this code requires nusoap.php to function properly
this is the code:

PHP Code:



for($a=0;$a<5;$a++)
{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => $res,
'maxResults' => 10,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
);

$soapclient = new soapclient("http://api.google.com/search/beta2");
$searchresults $soapclient->call("doGoogleSearch"$params,"urn:GoogleSearch""urn:GoogleSearch");
//print_r($searchresults);
// echo $uri=$searchresults[resultElements][$i][URL].'<br>';

for($i=0;$i<10;$i++)
{

print 
$uri=$searchresults[resultElements][$i][URL].'<br>';
flush();
}
echo 
'<br><br>';
$res+=10;

this is the line that gives me troubles :
print $uri=$searchresults[resultElements][$i][URL].'<br>';
the error is the following:
Fatal error: Cannot use string offset as an array

Now I don't understand sometimes I get no results only the error, sometimes 2 results and the error and so on. I don't think I can understand this...

I want to build a friendly api search with at least 5 result pages from google, but this error stops me...

B4 I tryed 20 and worked now it gives me the creeps...

If someone knows how to deal with this problem please help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-17-06, 07:07 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
I reply to myself now. I mean this is strange.
I changed print to echo the script works well, no fatal error, I changed back to print and still works well. I had this error manny times and it gives me a headache...
Is it a php bug ? Or something that is not working well ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-17-06, 07:15 PM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
PHP Code:

print $uri=$searchresults[resultElements][$i][URL].'<br>'
Having an equal sign where you have it should not allow the script to run properly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 05-17-06, 07:26 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Never encountered that one before, but it seems like it only affects arrays that are three levels deep (http://bugs.php.net/bug.php?id=28107) and may or may not be a bug.

Also, I'm assuming resultElements and URL are constants? Make sure they are assigned the proper values.

Try rewriting the code in a different way and see if that helps.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 05-17-06, 07:57 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Keith
PHP Code:

print $uri=$searchresults[resultElements][$i][URL].'<br>'
Having an equal sign where you have it should not allow the script to run properly.
I tried that b4 I forgot to mention it, it's the same error, maybe I should think how to rewrite the code as jfulton said...

If anybody has an idea it would be of great help.
thanks in advance
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-18-06, 10:18 AM
Crassius Crassius is offline
Newbie Coder
 
Join Date: Mar 2006
Location: Melbourne, FL
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Your code:
PHP Code:

 for($a=0;$a<5;$a++)

{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => $res,
'maxResults' => 10,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
); 
Have you tried putting single quotes everywhere?? like this:

PHP Code:

 for($a=0;$a<5;$a++)

{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => '$res',
'maxResults' => '10',
'filter' => 'false',
'restrict' => '',
'safeSearch' => 'false',
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
); 
__________________
~With great power comes great responsibility.~
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 05-18-06, 01:17 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Crassius
Your code:
PHP Code:

 for($a=0;$a<5;$a++)

{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => $res,
'maxResults' => 10,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
); 
Have you tried putting single quotes everywhere?? like this:

PHP Code:

 for($a=0;$a<5;$a++)

{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => '$res',
'maxResults' => '10',
'filter' => 'false',
'restrict' => '',
'safeSearch' => 'false',
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
); 
Neah That won't work, false it's 0, true is 1 and you can't put $res in simple quote because it won't work, maybe in double quotes, so you can't put everything between simple quotes...

Anybody has some more ideas ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 05-19-06, 08:11 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Once again I must say that I don't know why this error keeps geting, at first it worked fine, after I modified some values, the error camed...

Anybody knows how deal with it, a code rewrite or something..
I tried different ways, it worked but after that the same error came up.
I hate this error...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 05-19-06, 09:16 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
I'm with Keith, having $uri= as part of a print/echo in that for loop makes no sense. The $uri variable is not referenced within that loop.

You state this worked before you made some changes. Post the before code so someone here can zero in on what might be causing this.

The resultElements is an index name, try enclosing it in single quotes - $searchresults['resultElements']...

It would be interesting to see the results of this -
PHP Code:

echo "<pre>";

print_r($searchresults); 
echo 
"</pre>"
Could you post or attach a screen shot of this?
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 05-19-06, 09:43 PM
klaniak klaniak is offline
Wannabe Coder
 
Join Date: Apr 2005
Location: Underground
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by mab
I'm with Keith, having $uri= as part of a print/echo in that for loop makes no sense. The $uri variable is not referenced within that loop.

You state this worked before you made some changes. Post the before code so someone here can zero in on what might be causing this.

The resultElements is an index name, try enclosing it in single quotes - $searchresults['resultElements']...

It would be interesting to see the results of this -
PHP Code:

echo "<pre>";

print_r($searchresults); 
echo 
"</pre>"
Could you post or attach a screen shot of this?
the code was the same as be4

PHP Code:

 for($a=0;$a<5;$a++)

{
$params = array(
'key' => 'your api key',
'q' => 'mp3 player'
'start' => $res,
'maxResults' => 10,
'filter' => false,
'restrict' => '',
'safeSearch' => false,
'lr' => 'lang_en',
'ie' => '',
'oe' => ''
);

$soapclient = new soapclient("http://api.google.com/search/beta2");
$searchresults $soapclient->call("doGoogleSearch"$params,"urn:GoogleSearch""urn:GoogleSearch");
//print_r($searchresults);
// echo $uri=$searchresults[resultElements][$i][URL].'<br>';

for($i=0;$i<10;$i++)
{

print 
$uri=$searchresults[resultElements][$i][URL].'<br>';
flush();
}
echo 
'<br><br>';
$res+=10;

I modified the value of $a
in the for loop
for($a=0;$a<5;$a++)
I put here 10 and 6 and 7
when I modified this value the error camed:
I could see 20 links and then fatal error...
I know it works because it worked the first time...
Maybe I sould do a xml request that would work much better (I think)
The thing is that I build this code and as a writer of it: It's buggy and it drives me crazy, it should work like a daydream.

About $uri Neah $uri has nothing to do with it.
I did an echo $searchresults[resultElements][$i][URL].'<br>'; b4 and it did the same, until now the code has suffered lots of modification, I mean I posted only the loop. I will come with the function
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Javascript Error benholmes12345 JavaScript 2 03-03-06 04:48 AM
Strange Cookie Problems darkreaper PHP 1 12-30-04 07:39 PM
Strange script behavior attached kjmatthews PHP 2 07-13-04 12:00 PM
very strange functions issue jolac PHP 3 05-13-04 02:54 AM
This is a strange index.php problem! Balaheler PHP 2 10-16-03 11:11 PM


All times are GMT -5. The time now is 12:59 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.