php-general Digest 26 Dec 2006 09:15:02 -0000 Issue 4535

Topics (messages 246213 through 246221):

Re: Odd behavior
        246213 by: Martin Alterisio

Re: Clarification: Jump to a record/PHP paging...
        246214 by: Martin Alterisio

Re: Merry Christmas!
        246215 by: Miles Thompson
        246217 by: Craige Leeder

array_intersect problem
        246216 by: Leo Liu
        246219 by: Martin Alterisio

Couple Problem.
        246218 by: Craige Leeder

calling a function in the same page
        246220 by: Jahangir
        246221 by: Ryan Fielding

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
2006/12/25, jekillen <[EMAIL PROTECTED]>:


On Dec 25, 2006, at 7:21 AM, Roman Neuhauser wrote:

> # [EMAIL PROTECTED] / 2006-12-24 18:11:03 -0800:
>> function display($list, $in, $out, $save, $req, $x)
>>  {
>>       for($i = 0; $i < count($in); $i++)
>>       {$j = $i + 1;
>>       // two sets of links displayed instead of one
>>          for($i = 0; $i < count($out); $i++)
>>           {$j = $i + 1;
>>             // two sets of links displayed instead of one
>>           for($i = 0; $i < count($save); $i++)
>>            {$j = $i + 1;
>>              // two sets of links displayed instead of one
>>           for($i = 0; $i < count($req); $i++)
>>            {$j = $i + 1;
>>              // two sets of links displayed instead of one
>
>> The print lines above are supposed to produce a list of links to
>> files.
>> In the web display I get duplicate sets of links which seems to mean
>> that the loops in the function are running twice, and in one instance
>> three times instead of once.
>
> Look at the variable names you use for iteration.
>
Thanks, Usually, when a variable name like $i is used and then
reset to 0 in the next loop it does not matter. But I solved the
problem and posted the solution.  I also solved the regex
problem. There was an extra \n sneaking into the test pattern
so I could not get a match. I am not sure where the extra \n is
coming from.
It looks like I didn't post the solution after all:
Update:
I solved the double loops problem with this code change:

function display($list, $a, $x)
                 {
                  for($i = 0; $i < count($a); $i++)
                     {$j = $i + 1;
                      print "<a
href=\"steps.php?list=$list&next=$j&x=$x\">$j</a><br><br>\n";
                     };
                  }
and:

if($list || $current)
   {
     switch($list)
           {
            case 'in':
            display($list, $in, $x);
            break;
            case 'out':
            display($list, $out, $x);
            break;
            case 'save':
            display($list, $save, $x);
            break;
            case 'req':
            display($list, $req, $x);
            break;
           }
   }
Apparently what was happening was that the code running under 5.1.2
was trying to process all the arrays that had values in spite of the
switch
statement in the original display() function. If the was an $in array
the
switch  would process that for the $list value being 'in' but since
there
was also a save value, the switch tried to process it also, even though
'save' wasn't the $list value. I found it would do this for all arrays
that
had values. So if three had values the loop selected loop would run
three times.
Could this be a bonafide bug?
JK


I suspect this is an EBSAC bug, but I'm not completely sure. Anyway, please
consider improving your coding style, its all messy and unreadable. Also,
you should provide a description of the calling conditions, since there
might be the cause of the error in the function.

--- End Message ---
--- Begin Message ---
2006/12/25, Robert Cummings <[EMAIL PROTECTED]>:


WRONG! See Martin Alterisio's post for the same thread. You must not
have understood the OP's requirements.


xD
I was starting to think my mails weren't getting through the list, maybe its
nothing else than only a bigger delay than the usual. Anyway, I kind of lost
the topic of your discussion there... if you're so kind to explain in such a
way that an idiot like me can understand...

And Merry Xmas, Merry hangover or anything else you should desire to
celebrate.

PS: was my previous post useful to anyone? or did I mess up the explanation?
I'm not sure... =S that's why I'm asking...

--- End Message ---
--- Begin Message ---
At 07:20 AM 12/25/2006, Robert Cummings wrote:

WoooohoooooooooooooooooooOO! Hope you all have a great Christmas day. If
you don't celebrate Christmas, then I hope you have a great Christmas
day anyways *lol*. If this post offends you due to it's promotion of
Christmas then I apologize and hope you have a great anal retentive
Christmas day!!! :B

Merry Christmas,
Rob.


Hey Rob,

It's now Christmas night here in Nova Scotia.

We had a great day. The weather was mild, so we had apcnic lunch on the way to visit my sister and her family; then had the big family get-together there. We missed our oldest, he's in Ottawa visiting his girlfriend, but then our job is to raise them to leave the nest. Besides, she's a lovely girl.

Merry Christmas to everyone - Miles


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.15.26/601 - Release Date: 12/24/2006

--- End Message ---
--- Begin Message ---
Merry Christmas everyone. I hope you have/had a great one. Enjoy your
turkey feasts this weekend, they comes only a few times a year.

On 12/25/06, Miles Thompson <[EMAIL PROTECTED]> wrote:
At 07:20 AM 12/25/2006, Robert Cummings wrote:

>WoooohoooooooooooooooooooOO! Hope you all have a great Christmas day. If
>you don't celebrate Christmas, then I hope you have a great Christmas
>day anyways *lol*. If this post offends you due to it's promotion of
>Christmas then I apologize and hope you have a great anal retentive
>Christmas day!!! :B
>
>Merry Christmas,
>Rob.


Hey Rob,

It's now Christmas night here in Nova Scotia.

We had a  great day. The weather was mild, so we had apcnic lunch on the
way to visit my sister and her family; then had the big family get-together
there. We missed our oldest, he's in Ottawa visiting his girlfriend, but
then our job is to raise them to leave the nest. Besides, she's a lovely girl.

Merry Christmas to everyone - Miles


--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.15.26/601 - Release Date: 12/24/2006

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--- End Message ---
--- Begin Message ---
Hi,
   
  I try to intersect associative array and it seems to fail to do so. Can 
anyone show me a walk around?
   
  For example I have
   
  array1
   
  Array
(
    [0] => Array
        (
            [imageID] => 1
        )

    [1] => Array
        (
            [imageID] => 2
        )

    [2] => Array
        (
            [imageID] => 3
        )

    [3] => Array
        (
            [imageID] => 4
        )
)
   
  And array 2
   
  Array
(
    [0] => Array
        (
            [imageID] => 6
        )

    [1] => Array
        (
            [imageID] => 3
        )
)
   
  After intersection instead of me getting 3 as a result, I got the array 1 
unchanged. Seems like intersection doesn't take place at all. Anyway to solve 
this problem?
   
  Regards,
   
  Leo
   



Reality starts with Dream 

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--- End Message ---
--- Begin Message ---
2006/12/25, Leo Liu <[EMAIL PROTECTED]>:

Hi,

  I try to intersect associative array and it seems to fail to do so. Can
anyone show me a walk around?

  For example I have

  array1

  Array
(
    [0] => Array
        (
            [imageID] => 1
        )

    [1] => Array
        (
            [imageID] => 2
        )

    [2] => Array
        (
            [imageID] => 3
        )

    [3] => Array
        (
            [imageID] => 4
        )
)

  And array 2

  Array
(
    [0] => Array
        (
            [imageID] => 6
        )

    [1] => Array
        (
            [imageID] => 3
        )
)

  After intersection instead of me getting 3 as a result, I got the array
1 unchanged. Seems like intersection doesn't take place at all. Anyway to
solve this problem?

  Regards,

  Leo




Reality starts with Dream


Quote from php manual, in the reference for the array_intersect function:

*Note: * Two elements are considered equal if and only if (string) $elem1
=== (string) $elem2. In words: when the string representation is the same.

That's why array_intersect isn't working with your arrays.

If you're using PHP5 you could use array_uintersect, and compare the items
by the imageID:

   function compareByImageID($elem1, $elem2) {
       return $elem1['imageID'] - $elem2['imageID'];
   }

   $intersection = array_uinsersect($array1, $array2, 'compareByImageID');

Or you can do the following, which works in PHP4, but is not as versatile as
array_uintersect:

   class InArrayFilter {
       var $arr;

       function InArrayFilter($arr) {
           $this->arr = $arr;
       }

       function filterFunction($elem) {
           return in_array($elem, $this->arr);
       }
   }

   $filter = new InArrayFilter($array2);
   $intersection = array_filter($array1, array($filter, 'filterFunction'));

--- End Message ---
--- Begin Message ---
PHP General Mailing List,

I have a few questions when it comes to installation of PHP, and a PHP
extension                                   I have been eyeing

The first question involves Installation of PHP-GTK with PHP 5, from
zip. Although I follow the simple instructions included in the zip, I
am not able to start the PHP executable. I get an error of a missing
library (php-gtk2.dll [not found], and a pop up saying intl.dll). Have
I done horribly wrong? I didn't think it would be that hard of a task.
I'm using the gtkpath batch file, as apposed to changing my  PATH
variable this time around.

The second question is about installation op PHP 6. I have tried, and
failed at the installation of PHP 6 on my windows machine. Apache will
not load the module. I am not sure my exact setup now, as I attempted
it a week and a half ago, but as I recall I did not change my PATH
variable, to avoid conflict with my existing stable PHP5 installation.
Therefor, I moved the dll into the apache folder.

Sorry if allot of this is a little cryptic. I am dead tired, and just
wanted to send this off tonight before I retired for the night.

Thanks for any help you may be able to give based on this message.

- Craige

--- End Message ---
--- Begin Message ---
I am trying to call a function from "a href" inside the same page.
this is the code:
echo "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// calling the function isearch

function isearch($query)

{$query=urlencode($query);

$request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja
hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com;

$response=file_get_contents($request);

if ($response === false) {

die('Request failed');}

$phpobj=unserialize($response);

$count=$phpobj["ResultSet"]["totalResultsReturned"];

if($phpobj["ResultSet"]["totalResultsAvailable"]==0)

{echo "<br>NO RESULTS TO DISPLAY"; }

echo "<tr>"; echo "<h4 style=\"color:#FF0000\" align=\"center\">Results from
Mysite</h4>";

for($i=0;$i<$count;$i++)

{ echo '<pre>';

$no=$i+1;

$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];

echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] . "</a></h3>"; echo "</tr>";

echo "<tr>"; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";

echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"] ."</b>"; echo "</tr>";

echo "<br>"; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];

echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo "</tr>";

echo '</pre>'; }}



whenever i try to execute this function i either get an "Object not found
error" or "Access Forbidden error".

Can someone tell me where am i going wrong here??

thanks in advance

--- End Message ---
--- Begin Message ---
Jahangir wrote:
I am trying to call a function from "a href" inside the same page.
this is the code:
echo "<br><br><a href=\"isearch($query)\">More results from Mysite</a>";
// calling the function isearch

function isearch($query)

{$query=urlencode($query);

$request='http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=Ja
hangir&query=' .urlencode($query). '&output=php&results=100&site=mysite.com;

$response=file_get_contents($request);

if ($response === false) {

die('Request failed');}

$phpobj=unserialize($response);

$count=$phpobj["ResultSet"]["totalResultsReturned"];

if($phpobj["ResultSet"]["totalResultsAvailable"]==0)

{echo "<br>NO RESULTS TO DISPLAY"; }

echo "<tr>"; echo "<h4 style=\"color:#FF0000\" align=\"center\">Results from
Mysite</h4>";

for($i=0;$i<$count;$i++)

{ echo '<pre>';

$no=$i+1;

$url=$phpobj["ResultSet"]["Result"]["$i"]["Url"];

echo "<h3>" ."$no. ". "<a href=\"$url\">" .
$phpobj["ResultSet"]["Result"]["$i"]["Title"] . "</a></h3>"; echo "</tr>";

echo "<tr>"; echo $phpobj["ResultSet"]["Result"]["$i"]["Summary"]; echo
"</tr>";

echo "<br>"; echo "<tr>"; echo "<b>"
.$phpobj["ResultSet"]["Result"]["$i"]["Url"] ."</b>"; echo "</tr>";

echo "<br>"; $link=$phpobj["ResultSet"]["Result"]["$i"]["DisplayUrl"];

echo "<tr>"; echo "<a href=\"$url\">$link</a>"; echo "</tr>";

echo '</pre>'; }}



whenever i try to execute this function i either get an "Object not found
error" or "Access Forbidden error".

Can someone tell me where am i going wrong here??

thanks in advance

why not use a temporary variable?

$temp = isearch($query);

echo "<br /><br /><a href=\"" . $temp . "\">More results from Mysite</a>";

--- End Message ---

Reply via email to