phpbar.de logo

Mailinglisten-Archive

[php] PHP Knowledge Base in deutscher Sprache

[php] PHP Knowledge Base in deutscher Sprache

Egon Schmid eschmid_(at)_s.netic.de
Fri, 27 Aug 1999 22:48:40 +0200


Hi, 
hab gerade entdeckt, dass die Knowledge Base auch deutsch kann.

	http://www.e-gineer.com/e-gineer/phpkb/view.phtml/qid/123/lang/de

Da das Wort "grandmother" nur in 4 Postings in der englischen
Mailingliste auftaucht, hier ist das Original: 

-------------------------------------------------------------------------------
>  $query2 = " FROM Clients"
>      . " WHERE 0 = 0"
>      . " and fusebox_ID = $attributes.fusebox_ID"
>      if (!empty($attributes.Criteria)) {
>      . " and $attribues.Criteria" .
>      }
>      . " ORDER BY user_id";
>  include("php_selectquery.php");
> 
> This doesn't work.  It doesn't like my "if".  If you understand what I'm
> trying to do, can I do it in one statement?  or do I have to create several
> small strings and combine them?

You can't just toss an "if" into the middle of a string like that.  You
could create a function that does the check and returns the appropriate
string and then call that.  ie.
 
  function CheckAttr($string) {
    if(!empty($string)) return " and $string";
  }

  $query2 = " FROM Clients"
     . " WHERE 0 = 0"
     . " and fusebox_ID = $attributes.fusebox_ID"
     . CheckAttr($attributes.Criteria)
     . " ORDER BY user_id";

Or, to avoid the function call, you could get even trickier and use the
cool '?' operator.  (Wasn't that a Sade song?)

  $query2 = " FROM Clients"
     . " WHERE 0 = 0"
     . " and fusebox_ID = $attributes.fusebox_ID"
     . (!empty($attributes.Criteria) ? " and $attribues.Criteria" : "")
     . " ORDER BY user_id";

This probably looks confusing to all you non-C programmers out there. 
So,
here comes a "Conditionals for Dummies" summary:

It works like this:

  ( (condition) ? "true" : "false" )

If the condition is true, then the above line evaluates to "true" and
if the condition is false, it evaluates to "false".

Another way to look at it.  Take this very normal example:

  if($a==1) print "a is one";
  else      print "a is not one";

Even your grandmother could probably tell you what this did.  You can
rewrite this with a conditional to confuse your grandmother, like this:

  print ( ($a==1) ? "a is one" : "a is not one" );

Conditionals are not just for confusing grandmothers, though.  As per
Cameron's example, sometimes it is very handy to be able to check a
simple
condition in the middle of a larger expression.

-Rasmus
--------------------------------------------------------------------------


php::bar PHP Wiki   -   Listenarchive