php-general Digest 16 Jul 2009 05:32:16 -0000 Issue 6232

Topics (messages 295430 through 295449):

Re: Pattern Matching[Resolved]
        295430 by: VamVan

Re: I have an idea
        295431 by: Martin Scotta
        295432 by: tedd
        295433 by: Martin Scotta
        295435 by: Govinda
        295437 by: Ashley Sheridan
        295438 by: Daniel Brown
        295439 by: VamVan
        295440 by: Tom Worster
        295441 by: tedd

Re: Alphabetical pagination
        295434 by: Miller, Terion

boolean vs int comparison
        295436 by: Martin Scotta

Re: Scope of Variables and use of global and this->var
        295442 by: tedd

why is this SIMPLE elseif not firing?
        295443 by: Govinda
        295444 by: Govinda
        295445 by: Jim Lucas
        295446 by: Govinda
        295449 by: Stuart

Re: PHP/mysql equivalent of PEAR's tableInfo()??
        295447 by: Jason Pruim
        295448 by: Govinda

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
On Wed, Jul 15, 2009 at 4:21 AM, Lenin <le...@phpxperts.net> wrote:

> On Wed, Jul 15, 2009 at 3:24 AM, VamVan<vamsee...@gmail.com> wrote:
>
> > contact/me - Contact US
> >
> > perfect match would be easy because I can exactly look for what I want.
> >
> > It becomes tricky when I introduce wild cards like contact/* for example.
> It
> > could also be contact/me/*
> >
> > How would I match patterns for this kind of relative matches.? Any ideas
> > anyone?
>
>
> Use preg_match function to do that.


Ok here is how I solved it. When I have a url like www.xx.ccom/a/b/c for
example, what I do is
get an array of abc, ab, a

Then I run a union query for all three combinations. So basically select *
from {lookup_table} WHERE path = 'abc' UNION select ........

Then I just retrieve the first row  mysql_fetch_object. That is what I need.

Thanks Anyways
V

--- End Message ---
--- Begin Message ---
On Wed, Jul 15, 2009 at 10:38 AM, Govinda<govinda.webdnat...@gmail.com> wrote:
>> PHP is a great language. You can do a lot of things with him, even
>> have fun with it.
>> My idea is to make a simple game where your have to write some AI to
>> beat the other players AI
>>
>> The idea, as simple as it looks, is really difficult to implement
>> specially about security
>>
>> so, do you like me idea?
>>
>> -- Martin Scotta
>>
>
>
> sorry if this is getting OT:
>
> Martin, I wrote a really fun and charming remake of a great that 2 others
> wrote in the 1980's.  My version has really fun graphics and sounds.  I used
> visual basic as that is what I had then on my then windows laptop, without
> internet, literally in the mountains in north India where we only had
> electricity a couple hours per day, let alone no internet.  It is a simple
> but very fun strategy game with more depth than say checkers (by far!),  but
> less complex/daunting than say chess.  It has 2-player option, but writing
> the AI for the various levels of difficulty when playing against the
> computer was the most challenging and fun part of the project.  I often
> thought of taking it the next step and doing just what you propose here.   I
> don't know what is LISP, but I assume that post meant to say that PHP is not
> the best language for this.  (?)  I say, "so?"  If you know PHP, (and what,
> AJAX to go with it?)  then you can do it, and HAVE FUN, regardless that it
> is very inefficient way to do it.
> For myself I can't afford to take time for that much programming fun, just
> now..  but let me know in case you (or anyone) would like a copy of that
> game.. it may give you some ideas, not to mention it is perfect fun for
> unwinding at the end of a day of coding.  Takes 5 minutes to play.  The
> expert level is not at all easy to beat!  ;-)
> (for windows 98-->Vista.    Windows-7 I don't know... I use Mac when I have
> a choice.)
>
> -Govinda
>

That's the idea. You will have fun programming the AI and looking how
it "match" between others.

I'd like to see your game, do you still have it?

-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
At 4:40 PM +0100 7/15/09, Ashley Sheridan wrote:
On Wednesday 15 July 2009 16:29:49 tedd wrote:
 > Here's an AI (rule based) php game:

 http://sperling.com/quarters/

 Get your AI to beat mine.  :-)

 Cheers,

 tedd

 --
 -------
 http://sperling.com  http://ancientstones.com  http://earthstones.com

I think I can figure out how not to lose, but I don't know how to win...

--
Thanks,
Ash


Yes, but that's you -- write an AI program to do it.  :-)

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Wed, Jul 15, 2009 at 12:29 PM, tedd<tedd.sperl...@gmail.com> wrote:
> At 1:21 AM -0300 7/15/09, Martin Scotta wrote:
>>
>> Hi
>>
>> Do you noted that all the discussion here are about problems, bugs, or
>> just "urgent pleaaase help me"
>> I have an idea. It is not really THE idea... but it is.
>> What happen if tell this idea to the community? I don't know, so,
>> let's take a look.
>>
>>
>> PHP is a great language. You can do a lot of things with him, even
>> have fun with it.
>> My idea is to make a simple game where your have to write some AI to
>> beat the other players AI
>>
>> The idea, as simple as it looks, is really difficult to implement
>> specially about security
>>
>> so, do you like me idea?
>>
>> --
>
> Here's an AI (rule based) php game:
>
> http://sperling.com/quarters/
>
> Get your AI to beat mine.  :-)
>
> Cheers,
>
> tedd
>
> --
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
>

nice game tedd, I played it a lot of times and still can't beat it.
Also I have pass the link about 2 weeks ago in the office... and the
AI always wins

quite frustrating, but really entertained

-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
That's the idea. You will have fun programming the AI and looking how
it "match" between others.

I'd like to see your game, do you still have it?

-- Martin Scotta


I would love to see someone write an AI to beat my best skill level that I could get into the AI. I can beat expert level now, every time.. so I know there is more than I have captured so far in the AI.. (thus the greyed-out option for skill level "Master") .. but as Tedd alluded to in his reply to Ashley - having the skill is one thing.. but capturing the skill in bytes is a feat, not for the meek coder!

http://www.blisscode.com/BC_downloadables/Rama's%20Campaign%201.0.2%20-%20INSTALLER.ZIP

the game itself is like 1MB. The rest of those 14 MB's are for the sounds (.wav) mostly.. and a few small graphics.

make sure your windows desktop screen resolution is set to the default (96 d.p.i., IIRC) or else it is unplayable due to improper positioning of controls. Also ignore the hokey opening .. I wrote it for the members of the ashram where I was living at the time; just push any key to get past the intro and then read the directions of how to play in the help menu - the "?" icon in the sky on the top right.

Let me know how it goes!

------------
Govinda
govinda.webdnat...@gmail.com


--- End Message ---
--- Begin Message ---
On Wed, 2009-07-15 at 12:28 -0400, tedd wrote:
> At 4:40 PM +0100 7/15/09, Ashley Sheridan wrote:
> >On Wednesday 15 July 2009 16:29:49 tedd wrote:
> >  > Here's an AI (rule based) php game:
> >>
> >>  http://sperling.com/quarters/
> >>
> >>  Get your AI to beat mine.  :-)
> >>
> >>  Cheers,
> >>
> >>  tedd
> >>
> >>  --
> >>  -------
> >>  http://sperling.com  http://ancientstones.com  http://earthstones.com
> >
> >I think I can figure out how not to lose, but I don't know how to win...
> >
> >--
> >Thanks,
> >Ash
> 
> 
> Yes, but that's you -- write an AI program to do it.  :-)
> 
> Cheers,
> 
> tedd
> 
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 
Done! In order to never lose, don't play ;)

Thanks
Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
On Wed, Jul 15, 2009 at 15:30, Ashley Sheridan<a...@ashleysheridan.co.uk> wrote:
> Done! In order to never lose, don't play ;)

    That's what I had expected.  ;-P

    About eleven years ago, a co-worker and I each wanted the same day
off.  I had seniority, but decided to play fair with him and give him
a shot.  I told him that I could guarantee I could tell him the score
of a football game that night before the game started.  If I was
wrong, he could have the day off AND I would give him my pay for the
day (we were medics for the state, so it wasn't a horrible chunk of
change).  If I was right, I got the day off --- but to make sure it
was fair, we had to watch the game together that night, and he had to
pay for pizza.

    When I got to his house, he ordered the pizza and asked if I was
ready to lose.  I told him quite the contrary: before the game starts,
the score is a tie at zero-zero.

    Being a good sport and admitting defeat, he let me have the day
off.  Being as graceful as he was, I instead let him have the day
off.... and paid for the pizza.

    A very "cheesy" story (yeah, that's right), but relevant.  Seems
that now, in some places, trying to pull the same gag - even on a
friend - could get you two to the chest, single to the head.  People
just don't have a sense of humor anymore....

-- 
</Daniel P. Brown>
daniel.br...@parasane.net || danbr...@php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Check out our great hosting and dedicated server deals at
http://twitter.com/pilotpig

--- End Message ---
--- Begin Message ---
On Wed, Jul 15, 2009 at 12:40 PM, Daniel Brown <danbr...@php.net> wrote:

> On Wed, Jul 15, 2009 at 15:30, Ashley Sheridan<a...@ashleysheridan.co.uk>
> wrote:
> > Done! In order to never lose, don't play ;)
>
>     That's what I had expected.  ;-P
>
>    About eleven years ago, a co-worker and I each wanted the same day
> off.  I had seniority, but decided to play fair with him and give him
> a shot.  I told him that I could guarantee I could tell him the score
> of a football game that night before the game started.  If I was
> wrong, he could have the day off AND I would give him my pay for the
> day (we were medics for the state, so it wasn't a horrible chunk of
> change).  If I was right, I got the day off --- but to make sure it
> was fair, we had to watch the game together that night, and he had to
> pay for pizza.
>
>    When I got to his house, he ordered the pizza and asked if I was
> ready to lose.  I told him quite the contrary: before the game starts,
> the score is a tie at zero-zero.
>
>    Being a good sport and admitting defeat, he let me have the day
> off.  Being as graceful as he was, I instead let him have the day
> off.... and paid for the pizza.
>
>    A very "cheesy" story (yeah, that's right), but relevant.  Seems
> that now, in some places, trying to pull the same gag - even on a
> friend - could get you two to the chest, single to the head.  People
> just don't have a sense of humor anymore....
>
> --
> </Daniel P. Brown>
> daniel.br...@parasane.net || danbr...@php.net
> http://www.parasane.net/ || http://www.pilotpig.net/
> Check out our great hosting and dedicated server deals at
> http://twitter.com/pilotpig
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
> : nice one

--- End Message ---
--- Begin Message ---
On 7/15/09 12:21 AM, "Martin Scotta" <martinsco...@gmail.com> wrote:

> Hi
> 
> Do you noted that all the discussion here are about problems, bugs, or
> just "urgent pleaaase help me"
> I have an idea. It is not really THE idea... but it is.
> What happen if tell this idea to the community? I don't know, so,
> let's take a look.
> 
> 
> PHP is a great language. You can do a lot of things with him, even
> have fun with it.
> My idea is to make a simple game where your have to write some AI to
> beat the other players AI
> 
> The idea, as simple as it looks, is really difficult to implement
> specially about security
> 
> so, do you like me idea?

like core wars?



--- End Message ---
--- Begin Message ---
At 3:40 PM -0400 7/15/09, Daniel Brown wrote:
    When I got to his house, he ordered the pizza and asked if I was
ready to lose.  I told him quite the contrary: before the game starts,
the score is a tie at zero-zero.

Reminds me of many years ago when I was in New Orleans and a street kid came up to me and said "I bet I know where you got them boots."

Considering that my boots were genuine elephant-skin made custom by a boot maker in Las Vegas, I figured that the kid had mistaken the maker for someone local. So I asked him "How much?" and he answered "Five Bucks!"

I said "Okay, you got a bet." and the kid replied "You got them boots on Bourbon Street." Considering that I was currently standing on Bourbon street in the french Quarter, I saw how I had been tricked.

In any event, I paid the kid $5 and the next kid who asked me the same question, I qualified the bet but had no takers.

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---


--snip----


How do I write the for each loop in here:

   //alphabetical pagination links                                              
                      if (!isset($_GET['letter'])) {$letter = "A";} else 
{$letter = $_GET['letter'];}                                                    
                echo '<div align="center"><b>';                                 
                                   for ($i=65; $i<90; $i++) {                   
                                                 if ($letter!= chr($i)) {echo 
'<a href="browse.php?letter='.chr($i).'">';}                                    
                                echo chr($i)."&nbsp;";                          
                                          if ($letter!= chr($i)) {echo '</a>';  
                                                                                
                                                      ----->>> for each letter 
pull out those restaurants names and reload the page ....                       
                                                                                
                                                                                
                                                                                
                                                                                
     }                                                                    }

Or is that passed in the isset portion,

--- End Message ---
--- Begin Message ---
I always have doubts about comparison between boolean and integers.
Lets PHP shows hows is that he does.

The results where:
false <   $int === true / $int !== 0
false <=  $int === true
false >   $int === false
false >=  $int === false / $int !== 0
false ==  $int === false / $int !== 0
false === $int === false
false !=  $int === true / $int !== 0
false !== $int === true
true  <   $int === false
true  <=  $int === true / $int !== 0
true  >   $int === false / $int !== 0
true  >=  $int === true
true  ==  $int === true / $int !== 0
true  === $int === false
true  !=  $int === false / $int !== 0
true  !== $int === true

<?php # the script I used

function bol2string($boolean)
{
     return $boolean ? 'true' : 'false';
}

$results = array();

foreach(array(false, true) as $boolean)
    foreach(array('<  ', '<= ', '>  ', '>= ', '== ', '===', '!= ', '!==') as
$test)
        for($i=-1; $i<1; ++$i)
        {
            @eval(
                '$value =' . (
                    $_test = bol2string($boolean) . ' ' . $test . ' ' . $i
                ) . ';'
            );
            $results[ $boolean][ $test ][ $i ] = $value;
        }

foreach($results as $boolean => $_boolean)
    foreach($_boolean as $test => $_test)
        echo bol2string($boolean) , $boolean ? '  ': ' ' ,
            $test ,' $int === ' , bol2string($_test[-1]),
            $_test[0] !== $_test[-1] ? ' / $int !== 0' : '' ,
        PHP_EOL;
?>
-- 
Martin Scotta

--- End Message ---
--- Begin Message ---
At 12:21 PM +0200 7/14/09, Anton Heuschen wrote:

In my index.php page I then use $dbconnect again .... but do I simply use
$dbconnect again ... or must I say global $dbconnect and then use it in the
rest of the DB calls? or use GLOBALS ..

Anton:

My way -- every time I open a database, I do so by including the configuration.php file that holds the logon/password et other data to connect with the database. When I'm done with what I want from the database, I close it. I do not store anything in GLOBALS.

Cheers,

tedd


--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message --- Sorry this is isn't good 'ninja' material.. but I gotta start where I am.

this:

echo 'is set (EditExistingClient) ='. isset($EditExistingClient)."<br / >\n";
is returning:
is set (EditExistingClient) =1<br />

but this, later down the page:
elseif ((isset($EditExistingClient)) || ($CreateClient)) //we just created a client, OR edited a client
{
echo '<input name="EditExistingClient" type="submit" value="Edit This Client">'."\n";
}

is not firing unless $CreateClient is set.

This, too, is not firing when I think it should:
elseif (($EditExistingClient) || ($CreateClient)) //we just created a client, OR edited a client
{
echo '<input name="EditExistingClient" type="submit" value="Edit This Client">'."\n";
}

what ridiculously simple thing am I missing?


------------
Govinda
govinda.webdnat...@gmail.com


--- End Message ---
--- Begin Message ---
nevermind..  sorry for the noise.
It was my if clause that was firing too much, and never even reaching that elseif.
-G

--- End Message ---
--- Begin Message ---
Govinda wrote:
> Sorry this is isn't good 'ninja' material..  but I gotta start where I am.
> 
> this:
> 
> echo 'is set (EditExistingClient) ='. isset($EditExistingClient)."<br
> />\n";

I realize this is after the fact, but...

The above does not indicate WHAT it is set too.  Just that it is set.

it could be set to /null/, FALSE, or 0 and they would all return false,
and fail, in your if condition later on.


> is returning:
> is set (EditExistingClient) =1<br />
> 
> but this, later down the page:
> elseif ((isset($EditExistingClient)) || ($CreateClient)) //we just
> created a client, OR edited a client
> {
> echo '<input name="EditExistingClient" type="submit" value="Edit This
> Client">'."\n";
> }
> 
> is not firing unless $CreateClient is set.
> 
> This, too, is not firing when I think it should:
> elseif (($EditExistingClient) || ($CreateClient)) //we just created a
> client, OR edited a client
> {
> echo '<input name="EditExistingClient" type="submit" value="Edit This
> Client">'."\n";
> }
> 
> what ridiculously simple thing am I missing?
> 
> 
> ------------
> Govinda
> govinda.webdnat...@gmail.com
> 
> 



--- End Message ---
--- Begin Message ---
I realize this is after the fact, but...

The above does not indicate WHAT it is set too.  Just that it is set.

it could be set to /null/, FALSE, or 0 and they would all return false,
and fail, in your if condition later on.

I understand.  I appreciate your taking the time to explain things.
You too Nathan!

-G


--- End Message ---
--- Begin Message ---
2009/7/15 Govinda <govinda.webdnat...@gmail.com>:
> Sorry this is isn't good 'ninja' material..  but I gotta start where I am.
>
> this:
>
> echo 'is set (EditExistingClient) ='. isset($EditExistingClient)."<br />\n";
> is returning:
> is set (EditExistingClient) =1<br />
>
> but this, later down the page:
> elseif ((isset($EditExistingClient)) || ($CreateClient)) //we just created a
> client, OR edited a client
> {
> echo '<input name="EditExistingClient" type="submit" value="Edit This
> Client">'."\n";
> }
>
> is not firing unless $CreateClient is set.
>
> This, too, is not firing when I think it should:
> elseif (($EditExistingClient) || ($CreateClient)) //we just created a
> client, OR edited a client
> {
> echo '<input name="EditExistingClient" type="submit" value="Edit This
> Client">'."\n";
> }
>
> what ridiculously simple thing am I missing?

The only possibility I can see is that $EditExistingClient is getting
modified between the echo and the first elseif statement.

-Stuart

-- 
http://stut.net/

--- End Message ---
--- Begin Message ---

On Jul 13, 2009, at 10:03 AM, Govinda wrote:

I have this code:

      $db_billing=mysqli_connect(localhost,metheuser,mypass,billing);
if (mysqli_connect_error()) { die("Can't connect: " . mysqli_connect_error()); }

mysqli


      //$dbname = 'billing';
      $sql = "SHOW TABLES";

      $result = mysql_query($sql); // line 53

Now mysql, What are you doing?

Yes. 3 lashing. Thanks. I am not likely to neglect again remembering that mysql and mysqli are different and have different syntax.

unfortunately I am still in over my head enough to have to ask..

Here is what I have now:

$db_billing=mysql_connect(localhost,metheuser,mypass,billing);
if (!$db_billing) { die('Could not connect: ' . mysql_error()); }

        $sql = "SHOW TABLES";
        
        $result = mysql_query($sql);
        
        foreach(mysql_fetch_assoc($result) as $k => $v) { //line 62
        $ssql = "DESCRIBE ".mysql_real_escape_string($v);
        $rresult = mysql_query($ssql);
        echo "<b>".$k."</b>:<br />\n";
        echo "<pre>\n";
        print_r(mysql_fetch_assoc($rresult));
        echo "</pre>\n";
        echo "<br />\n";
        }

giving this error:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/meee/public_html/somedir/test.php on line 62

I read about:
-mysql_fetch_assoc
-mysql_query
-SHOW TABLES

but do not see why this should be failing. Why isn't $result a ' valid MySQL result resource'?

Better late then never! :)

I played around with your code tonight and got this working on a test server:


<?PHP

$db_billing = mysql_connect($DBHOST, $DBUSER, $DBPASS) or die("Could not connect: " .mysql_error());

$db_selected = mysql_select_db($DB, $db_billing);

        if(!$db_selected) {
                die("Can't use database: " . mysql_error());
        }


if (!$db_billing) { die('Could not connect: ' . mysql_error()); }

        $sql = "SHOW TABLES";

$result = mysql_query($sql) or die("query failed: " .mysql_error());
        $resulttest = mysql_fetch_assoc($result);


        foreach($resulttest as $k => $v) { //line 62
        $ssql = "DESCRIBE ".mysql_real_escape_string($v);
        $rresult = mysql_query($ssql);
        echo "<b>".$k."</b>:<br />\n";
        echo "<pre>\n";
        print_r(mysql_fetch_assoc($rresult));
        echo "</pre>\n";
        echo "<br />\n";
        }



?>

The only big difference from what you had is that I moved the mysql_fetch_assoc($result); into a separate line rather then running it from the foreach...

Let me know if that helps.



--- End Message ---
--- Begin Message ---

Better late then never! :)

I played around with your code tonight and got this working on a test server:


<?PHP

$db_billing = mysql_connect($DBHOST, $DBUSER, $DBPASS) or die("Could not connect: " .mysql_error());

$db_selected = mysql_select_db($DB, $db_billing);

       if(!$db_selected) {
               die("Can't use database: " . mysql_error());
       }


if (!$db_billing) { die('Could not connect: ' . mysql_error()); }

       $sql = "SHOW TABLES";

$result = mysql_query($sql) or die("query failed: " .mysql_error());
       $resulttest = mysql_fetch_assoc($result);


       foreach($resulttest as $k => $v) { //line 62
       $ssql = "DESCRIBE ".mysql_real_escape_string($v);
       $rresult = mysql_query($ssql);
       echo "<b>".$k."</b>:<br />\n";
       echo "<pre>\n";
       print_r(mysql_fetch_assoc($rresult));
       echo "</pre>\n";
       echo "<br />\n";
       }



?>

The only big difference from what you had is that I moved the mysql_fetch_assoc($result); into a separate line rather then running it from the foreach...

Let me know if that helps.

Thanks Jason :-)

What you just offered just shows info about only the first column in the table.

I got this working to show info about all the columns in the table:

$ssql = "DESCRIBE billing_table";
$rresult = mysql_query($ssql);
echo "<hr /><pre>\n";
while ($row = mysql_fetch_assoc($rresult)) {
        print_r($row); //line 278
}
echo "</pre>\n";
echo "<hr />\n";

-G

--- End Message ---

Reply via email to