query Reg: warning

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

Post Reply
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

query Reg: warning

Post by sujithfem »

hi
i got following warning in my site warning:Variable passed to each() is not an array or object in php,
please let me know the reason
awaiting for your valuable answers

thank you
regards
sujith
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

uhh... the variable that you passed to each wasn't an array. Post your code :roll:
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

Post by sujithfem »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


thank u for your quick reply ,here is my code .........

Code: Select all

while(list($key, $val)=each($tc['one_res']))
   {
     $report[$val['brand_name']][$val['material_no']]['one_qty']=$val['qtysum'];
   }

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

What version of PHP are you using? if it's at least version 4, you can use foreach instead of each... so the syntax would look like:

Code: Select all

if(is_array($tc['one_res'])){
    foreach($tc['one_res'] as $val)
    {
        $report[$val['brand_name']][$val['material_no']]['one_qty']=$val['qtysum']; 
    }
}
else{
    echo "Could not iterate results, because tc is not an array!";
    print_r($tc); // Print what it is so you can figure out why it wasn't an array
}
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

Post by sujithfem »

thank u very much for ur reply but while's execution speed is better than foreach ...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Might wanna use what works till your more experienced there bucko.
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

Post by sujithfem »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hey i have one more issues that is

Code: Select all

$pattern='**SPEAKERNAME**';
if (preg_match($pattern,$source))
{   echo "A match was found.";
} else {
   echo "A match was not found.";
}


i got a following warning

Warning: preg_match() [function.preg-match]: Unknown modifier 'P' in D:\Program Files\www\Tester\search.php on line 233
A match was not found.

plz let me know the solution


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you have to have modifiers with preg_match. put a # at the beginning of your pattern and a # at the end of your pattern. that should do the trick ;)
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

Post by sujithfem »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi 
i put like ...........

Code: Select all

$pattern='#**SPEAKERNAME**#';
if (preg_match($pattern,$source))
{   echo "A match was found.";
} else {
   echo "A match was not found.";
}
but i got a warning like .............


Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 0 in D:\Program Files\www\Tester\search.php on line 233
A match was not found.


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

ok 1st thing i will say is perdy please use the php / code tags when posting code. it makes it much easier to read.

second, i don't know much about regular expressions (preg_match stuff) but why not just use strpos?

Code: Select all

$pattern = '**SPEAKERNAME**';

if (false !== strpos($source, $pattern))
{
    echo 'a match was found';
}
else
{
    echo 'no matches found';
}
its much easier if you are just looking for a string and not a pattern. also note how perdy that code looks :P
sujithfem
Forum Newbie
Posts: 23
Joined: Tue May 23, 2006 10:56 pm
Location: India
Contact:

Post by sujithfem »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


ok i will carry on ur instructions ,and i got a solution by

Code: Select all

<?php

$pattern='**SPEAKERNAME**';
if (stristr($source,$pattern))
{   echo "A match was found.";
} else {
   echo "A match was not found.";
}

?>

thank u very much and esp for ur quick responce ,God Bless u all :D


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply