RE: mysql if statement to php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



HI John,

No worries, I got it to work.  Seems to output
correctly now.

$qr = mysql_query("SELECT IF ( emailerror = ( 'y' ) ,
'error yes', ' ' ) FROM tipping where nickname =
\"$sidarray[0]\"");
$result = mysql_query($qr);
$row = mysql_fetch_array($qr);
echo $row['0'];

Yes the code is not totally right.  $row =
myusql_fetch_array($qr); but each time I set it as
result it bombed out on me.  Not sure why.  But it
works but I guess it's not 100% reliable?

Jerry

 --- "John W. Holmes" <holmes072000@charter.net>
wrote: > > I am using a php page to grab information
using
> the if
> > statement.  Now the mysql query works fine but I
> can't
> > get the output to output into php.  I have tried
> many
> > things and have failed to get it to display.
> > 
> > This is the code:
> > 
> > <?php
> > mysql_connect ("localhost", "$usr", "$pass") or
> die
> > ('I cannot connect to the database.');
> > mysql_select_db ("$db");
> > 
> > $qr = mysql_query("SELECT IF( emailerror = ('y' ),
> > 'error yes', 'do nothing' ) FROM tipping WHERE sid
> =
> > '$sid'");
> > 
> > ?>
> > 
> > If I do the above query in mysql it returns
> correctly.
> >  If Y is in the table it dispalys error yes.  But
> how
> > do I get it to output to a php page with the above
> > function?
> 
> Run the query through mysql_query(), fetch the
> result row with
> mysql_fetch_row() and display $row[0].
> 
> $result = mysql_query($qr);
> $row = mysql_fetch_row($result);
> echo $row[0];
> 
> OR
> 
> $result = mysql_query($qr);
> echo mysql_result($result,0);
> 
> OR
> 
> $qr = mysql_query("SELECT IF( emailerror = ('y' ),
> 'error yes', 'do nothing' ) AS answer FROM tipping
> WHERE sid =
> '$sid'");
> $result = mysql_query($qr);
> $row = mysql_fetch_array($result);
> echo $row['answer'];
> 
> Notice the "AS answer" added to the query in the
> last example. 
> 
> ---John W. Holmes...
> 
> PHP Architect - A monthly magazine for PHP
> Professionals. Get your copy
> today. http://www.phparch.com/
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>  

http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux