close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

While Loop

Thread began 9/15/2009 8:42 am by Daryl | Last modified 9/16/2009 2:00 pm by Jason Byrnes | 3499 views | 5 replies |

DarylBeta Tester

While Loop

I am desperately trying to create an email form that has a number of checkboxes at the top of the page that allows the user to select multiple people (one email address per check box) or a department (multiple emails per checkbox).

I can get a single email address to echo from the database into the value fields for the people, but I am having issues getting all email addresses from specific column into a checkbox value.

I have been trying to learn to use the while loop but haven't managed to get it to work successfully yet.

To start with, I do not need to have checkboxes, but I do need a way that the user can select multiple people or groups of people to send the message to - if you have any other suggestions please let me know.

The method that I am using to loop the records is as follows;

php:
<?php

$connection 
mysql_connect("localhost""username""password") or die("Error connecting to database");
mysql_select_db("db_name"$connection);
$result mysql_query("SELECT * FROM units"$connection) or die("error querying database");?>



Then this for the first checkbox;

php:
<?php while($row_rs mysql_fetch_assoc($result)){

echo 
$row_rs['chair_email'].',';}?>



Then this for the second;

php:
<?php while($row_rs mysql_fetch_assoc($result)){

echo 
$row_rs['sec_email'].',';}?>



But unfortunately the second set doesn't produce any results from the recordset.

Where am I going wrong?

I'm sure there must be an easier way....

Sign in to reply to this post

Jason ByrnesWebAssist

When you get to the second loop the recordset is on the last record. It needs to be reset to the first record.


php:
<?php
mysql_data_seek
($rs0);
$row_rs mysql_fetch_assoc($rs);
while(
$row_rs mysql_fetch_assoc($result)){
echo 
$row_rs['sec_email'].',';}
?>
Sign in to reply to this post

DarylBeta Tester

Im getting there slowly!!

The first set of loops work - horray!!!

php:
<?php do { ?>

<?php 
if ($row_rs_users['lsdogs_chair']=="1")
echo 
$row_rs_users['email'].";"?>
<?php 
} while ($row_rs_users mysql_fetch_assoc($rs_users)); ?>

<?php mysql_data_seek($rs_users0);
$row_rs_users mysql_fetch_assoc($rs_users);
if (
$row_rs_users['lsdogs_sec']=="1"
{echo 
$row_rs_users['email'].";"?>
<?php 
} while ($row_rs_users mysql_fetch_assoc($rs_users)); ?>



And the begining of the second set of loops works too!!

php:
<?php do { ?>

<?php 
echo $row_rs_units['chair_email'].";";?>
<?php 
} while ($row_rs_units mysql_fetch_assoc($rs_units)); ?>



But unfortunately the rest of that group of loops doesn't :0(

php:
<?php mysql_data_seek($rs_units0);

$row_rs_units mysql_fetch_assoc($rs_units);{
echo 
$row_rs_units['sec_email'].";"?>
<?php 
} while ($row_rs_units mysql_fetch_assoc($rs_units)); ?>



So what am I doing wrong then.....?

Sign in to reply to this post

Jason ByrnesWebAssist

This line of code does not look right:

php:
$row_rs_units = mysql_fetch_assoc($rs_units);{





the "{" at the end should cause an error change it to:

php:
$row_rs_units = mysql_fetch_assoc($rs_units);
Sign in to reply to this post

DarylBeta Tester

the reason for the

php:
{

is beacuse the next part is the

php:
echo

followed by

php:
}

and then the

php:
while

.

So I assume that I would need to remove the closing one too?

I have been through the code and have removed all of the

php:
{ }

which has not changed the output at all.

After the second set of loops, the remaining ones just show the first record only.

Sign in to reply to this post

Jason ByrnesWebAssist

this code does not start a loop:
$row_rs_units = mysql_fetch_assoc($rs_units);{



You need to add another do { command:

php:
<?php mysql_data_seek($rs_units0);

$row_rs_units mysql_fetch_assoc($rs_units);
?>
<?php 
do {
echo 
$row_rs_units['sec_email'].";"?>
<?php 
} while ($row_rs_units mysql_fetch_assoc($rs_units)); ?>
Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...