...

View Full Version : Nesting ifs with specific values taken from mysql



cmxsevenfoldxmc
05-15-2008, 03:57 PM
Good morning everyone,

I've been trying to nest a few if statements for a newsletter that first checks for users in the database that are part of a particular group (ex: Retail, Distributors, TEST), and then I have another if statement that checks if they want to receive the newsletter (simple "YES" or "NO" in that field).

Here's my code for the group "TEST":

elseif($ngroup == "TEST")
{
mysql_select_db($database_TireSafe_Database, $TireSafe_Database);
$ngroupselection = "SELECT * FROM TS_NEWSLETTER WHERE `group` = 'TEST'";
$Newsletter = mysql_query($ngroupselection, $TireSafe_Database) or die(mysql_error());
$row_Newsletter = mysql_fetch_assoc($Newsletter);
$totalRows_Newsletter = mysql_num_rows($Newsletter);
do {
if($nreceive == "YES")
{
mysql_select_db($database_TireSafe_Database, $TireSafe_Database);
$nreceiveselection = "SELECT * FROM TS_NEWSLETTER WHERE `receive` = 'YES'";
$Newsletter = mysql_query($nreceiveselection, $TireSafe_Database) or die(mysql_error());
$row_Newsletter = mysql_fetch_assoc($Newsletter);
$totalRows_Newsletter = mysql_num_rows($Newsletter);

$ngroupemails = $row_Newsletter['email'] . ", ";
}
}
while ($row_Newsletter = mysql_fetch_assoc($Newsletter));
}

How can I fix this? I know there's a lot of unnecessary coding in there, I can tell, but can someone point it out for me? The coding for the other groups looks the same as this, so if I know how to fix TEST, then I'll be able to figure out how to structure the rest correctly.

I'd greatly appreciate it!

Thank you all very much in advance

cmxsevenfoldxmc
05-15-2008, 06:41 PM
Hey guys, nevermind.

I fixed it after looking at some logical solutions. It was staring at me in the face. I had to insert the do...while statement inside the second if statement.

Here's what I did to fix it if anyone who read my post wants to know:



elseif($ngroup == "TEST")
{
mysql_select_db($database_TireSafe_Database, $TireSafe_Database);
$ngroupselection = "SELECT * FROM TS_NEWSLETTER WHERE `group` = 'TEST'";
$Newsletter = mysql_query($ngroupselection, $TireSafe_Database) or die(mysql_error());
$row_Newsletter = mysql_fetch_assoc($Newsletter);
$totalRows_Newsletter = mysql_num_rows($Newsletter);
if($nreceive == "YES")
{
mysql_select_db($database_TireSafe_Database, $TireSafe_Database);
$nreceiveselection = "SELECT * FROM TS_NEWSLETTER WHERE `receive` = 'YES'";
$Newsletter = mysql_query($nreceiveselection, $TireSafe_Database) or die(mysql_error());
$row_Newsletter = mysql_fetch_assoc($Newsletter);
$totalRows_Newsletter = mysql_num_rows($Newsletter);
do {
$ngroupemails = $row_Newsletter['email'] . ", ";
}

while ($row_Newsletter = mysql_fetch_assoc($Newsletter));
}
}



Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum