Re: Why doesn't my short piece of code work??? :(
| From: | Mark Maggelet | Date: | Thu, 07 Dec 2000 20:56:20 +0000 |
| Subject: | Re: Why doesn't my short piece of code work??? :( | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29213@lists.php.net to get a copy of this message | ||
On Thu, 7 Dec 2000 12:06:31 -0800 (PST),
lee@server.mediawaveonline.com (lee@server.mediawaveonline.com)
wrote:
>theses are all VALID :)
>
><?
> if ( $num )
> echo "a<br>\n";
> else
> echo "b<br>\n";
>
> if ( $num ) {
> echo "a<br>\n";
> } else {
> echo "b<br>\n";
> }
>
> if ( $num )
> {
> echo "a<br>\n";
> } else
> {
> echo "b<br>\n";
> }
>
> if ( $num )
> {
> echo "a<br>\n";
> } else
> echo "b<br>\n";
>
> if ( $num )
> echo "<br>\n";
> else
> {
> echo "<br>\n";
> }
>?>
don't forget:
<?echo ($num)?"a<br>\n":"b<br>\n"?>
or
<?echo (($num)?"a":"b")."<br>\n"?>
- Mark
p.s. I think putting in the '==0' makes this more readable:
<?echo (($num==0)?"a":"b")."<br>\n"?>
>There are hundreds of ways of writing if statements, try em, they
all
>work. If yout IF() statment is not going to have more then one line
>then
>yout dont need { }, and IMHO reduced readability.
>
>Chris Lee
>Mediawaveonline.com
>
>
>
>On Thu, 7 Dec 2000, R. Phillips wrote:
>
>> You left the if statement open....
>>
>> > if ( mysql_errno() )
>> > echo "Error: " . mysql_errno() . ':' . mysql_error() .
>> > "<br>\n";
>> >
>>
>> should be .....
>>
>> if ( mysql_errno() ) {
>> echo "Error: " . mysql_errno() . ':' . mysql_error() .
>> "<br>\n";
>> }
>>
>> ----- Original Message -----
>> From: "Chris Lee" <lee@mediawaveonline.com>
>> To: <php-general@lists.php.net>
>> Sent: Thursday, December 07, 2000 2:01 PM
>> Subject: Re: [PHP] Why doesn't my short piece of code work??? :(
>>
>>
>> > I saw a few funny things. try this.
>> >
>> > <?
>> > $column = "country";
>> > $table = "product";
>> > $result = mysql_db_query($store_db, "SELECT $column, count(*)
>>FROM $table
>> GROUP BY $column");
>> >
>> > while( $r = mysql_fetch_array($result) )
>> > {
>> > if ( mysql_errno() )
>> > echo "Error: " . mysql_errno() . ':' . mysql_error() .
>> > "<br>\n";
>> >
>> > echo "{$r["country"]} <br>\n";
>> > }
>> > ?>
>> >
>> > more info at
>> > http://php.net/manual/function.mysql-db-query.php
>> > http://php.net/manual/function.mysql-fetch-array.php
>> >
>> > Chris Lee
>> > Mediawaveonline.com
>> >
>> >
>> > In article <20001207185614.19730.qmail@web3903.mail.yahoo.com>,
>> > "=?iso-8859-1?q?Sandeep=20Hundal?=" <sandeep_wde@yahoo.com>
>>wrote:
>> >
>> > > Hi all, I've got this short stripped down basic code to get
>>some results
>> > > from a table, but I can't get it to work. Any ideas why??
>> > >
>> > >
>> > > $column = "country";
>> > >
>> > > $result = mysql_query("SELECT $column, count(*) AS numbers
FROM
>> > > $tablename GROUP BY $column");
>> > >
>> > > for($i =0; $i < mysql_num_rows($result); $i++) {
>> > >
>> > > echo mysql_result($result, $i, $column)
>>mysql_result($result, $i,
>> > > "numbers") ";
>> > > echo "<br>";
>> > >
>> > > }
>> > > echo "<font color=red>".mysql_error()."</font>";
>> > >
>> > > mysql_free_result($result);
>> > >
>> > > TIA!!!
>> > >
>> > > Sandeep Hundal
>> > >
>> > > __________________________________________________
>> > > Do You Yahoo!? Yahoo! Shopping - Thousands of Stores. Millions
>>of
>> > > Products. http://shopping.yahoo.com/
>> > >
>> > >
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>> > For additional commands, e-mail: php-general-help@lists.php.net
>> > To contact the list administrators, e-mail: php-list-
>>admin@lists.php.net
>> >
>>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-
>admin@lists.php.net