Page 1 of 1
query Reg: warning
Posted: Tue Aug 01, 2006 1:46 am
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
Posted: Tue Aug 01, 2006 1:48 am
by Luke
uhh... the variable that you passed to each wasn't an array. Post your code

Posted: Tue Aug 01, 2006 2:11 am
by sujithfem
Pimptastic | Please use 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
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]
Posted: Tue Aug 01, 2006 2:20 am
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
}
Posted: Tue Aug 01, 2006 2:31 am
by sujithfem
thank u very much for ur reply but while's execution speed is better than foreach ...
Posted: Tue Aug 01, 2006 2:33 am
by Benjamin
Might wanna use what works till your more experienced there bucko.
Posted: Tue Aug 01, 2006 2:36 am
by sujithfem
Pimptastic | Please use 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
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]
Posted: Tue Aug 01, 2006 2:46 am
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

Posted: Tue Aug 01, 2006 3:23 am
by sujithfem
Pimptastic | Please use 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
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]
Posted: Tue Aug 01, 2006 3:30 am
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

Posted: Tue Aug 01, 2006 3:37 am
by sujithfem
Pimptastic | Please use 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
Pimptastic | Please use 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]
Posted: Tue Aug 01, 2006 3:44 am
by JayBird
Pimptastic | Please use 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]