Re: [PHP] Missing first record in PHP/Mysql query

2001-07-06 Thread Chris Anderson

here may be why:
//Right here you grab a row
$query_data = mysql_fetch_row($result);
//but you don't use it and you move on
 while($query_data = mysql_fetch_array($result)) {
- Original Message - 
From: "Rory O'Connor" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 05, 2001 3:11 PM
Subject: [PHP] Missing first record in PHP/Mysql query


> Excuse me if this is too newbie...but I'm writing a simple script to
> query a database and loop through the reuslts, echoing them on the page.
>  When I enter the query at the mysql command line, I get the correct
> results.  But the same query run through PHP renders all results except
> the first one.  Any idea why?  I've included the code snippet below:
> 
> //the query to select the data
> $query = "SELECT firstname,email,optin from contact where
> interest='rory'";
> $result = mysql_query($query);
> if(!$result) error_message(sql_error());
> 
> $query_data = mysql_fetch_row($result);
> 
> while($query_data = mysql_fetch_array($result)) {
> $firstname = $query_data["firstname"];
> $email = $query_data["email"];
> $optin = $query_data["optin"];
> 
> echo "\n";
> echo "$firstname;$email;$optin\n";
> 
> } //end while loop 
> 
> also, what would be the code to output the reuslts to a text file
> instead of (or in addition to) the screen?
> 
> thanks,
> 
> rory
> 
> providing the finest in midget technology
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] mySQL Query - comparing multiple values with one field

2001-08-21 Thread Niklas Lampén

What I need to do is to compare if one field matches a value from a huge
list of values.

Do I need to query like
"SELECT * FROM table WHERE field LIKE '%value1%' || field LIKE '%value2%'"
or can I do it something like this
"SELECT * FROM table WHERE field LIKE ('%value1%' || '%value2%')"?


Niklas Lampén



Re: [PHP] mySQL Query - comparing multiple values with one field

2001-08-21 Thread David Robley

On Wed, 22 Aug 2001 16:21, Niklas Lampén wrote:
> What I need to do is to compare if one field matches a value from a
> huge list of values.
>
> Do I need to query like
> "SELECT * FROM table WHERE field LIKE '%value1%' || field LIKE
> '%value2%'" or can I do it something like this
> "SELECT * FROM table WHERE field LIKE ('%value1%' || '%value2%')"?
>
>
> Niklas Lampén

The first will work. If you are doing exact comparisons, the mysql 
comparison operator IN may prove useful.

-- 
David Robley  Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES  Flinders University, SOUTH AUSTRALIA  

   It's as easy as 3.14159265358979323846264338327950...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




<    1   2