Or you can do something like:
$query = "SELECT * FROM members Where Company  LIKE '%$search1%'";
$result = mysql_db_query($dbName, $query);
$numRows = mysql_num_rows($result);

for ($i=0; $i<$numRows; $i++) {
  $row = mysql_fetch_array($result);
  $email[] = $row[email];
}

OR

while ($row = mysql_fetch_array($result)) {
  $email[] = $row[email];
}

This just puts all your emails into an array.  You can do whatever you want
within either loop and it'll do it to every element.  It's pretty limitless,
or like I did you can stick everything you want into an array to use later..
whatever your fancy :)

The reason you only get one email when you echo it outside the loop is that
mysql_fetch_array only grabs one row, so you loop through and if you echo
inside the loop you'll see every row outputted, while outside the loop
you'll only get the last row outputted. (not sure if outputted is a word :)
Anyways so now that you understand it a little more, you can do whatever you
want to each element in the row inside the loop... I hope that helps!

Rick

> your while loop is working fine -- it's just that you're re-setting the value
> of $email every time it loops through.
> 
> I'm not sure what you're trying to accomplish, but you might try something
> like:
> 
> $query = "SELECT * FROM members Where Company  LIKE '%$search1%'";
> $result=mysql_db_query($dbName,$query);
> while ($row = mysql_fetch_array($result)) {
> $email[$row['lname']] =  $row["E_mail_1"]
> } //untested code -- probably missing some quotes somewhere.
> 
> 
> that will give you an array with lname as the key and e_mail_1 as your value.
> You can then loop through it and format it however you want.
> 
> hth
> 
> --kurt 
> 
> On Friday 26 October 2001 00:10, Richard Kurth wrote:
>>  I am trying to get the data out of the while loop if I echo $email
>>  inside the } it gives me all of the data but if I echo it out side of
>>  the loop it only gives me one record even though I know there is
>>  more. How can I get this to work
>> 
>> $query = "SELECT * FROM members Where Company  LIKE '%$search1%'";
>> $result=mysql_db_query($dbName,$query);
>> while ($row = mysql_fetch_array($result)) {
>> $email= $row["lname"] . " " . "&lt;" . $row["E_mail_1"] . "&gt;" . ";";
>> }
>> 
>> 
>> echo $email;
> 
> -- 
> 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]

Reply via email to