lional Posted January 26, 2009 Share Posted January 26, 2009 Hi I am trying to create a script where by certain search criteria email addresses are listed from patients that we can sen a mail to each of these email addresses. The email addresses are listed in the form of checkboxes where they are automatically checked and any email addresses that you would like to exclude you just deselect the checkbox. This is working fine but I am having problems with the arrays. Because I am new to arrays I am just checking the scripts for now by letting it print the email addresses depending on the output of the array. The two script excerpts are follow if ($_SESSION['province'] != 'all') { $whereList[] = "pos_prov = '".mysql_real_escape_string($_SESSION['province'])."'"; } if ($_SESSION['city'] != 'all') { $whereList[] = "pos_city = '".mysql_real_escape_string($_SESSION['city'])."'"; } if ($_SESSION['age'] != 'all') { $whereList[] = "age > '".mysql_real_escape_string($_SESSION['age_min'])."'"; $whereList[] = "age < '".mysql_real_escape_string($_SESSION['age_max'])."'"; } if ($_GET['gender'] != 'all') { $whereList[] = "sex = '".mysql_real_escape_string($_SESSION['gender'])."'"; } $whereClause = (count($whereList)) ? ' AND ' . implode(' AND ', $whereList) : ''; $query_ail1 = "SELECT * FROM patients WHERE client_updated = 1 $whereClause"; $result_ail1 = mysql_query($query_ail1, $conn); while ($row_ail1 = mysql_fetch_assoc($result_ail1)){ $patients_id_out = $row_ail1["patients_id"]; $name_out = $row_ail1["name"]; $pos_city_out = $row_ail1["pos_city"]; $pos_prov_out = $row_ail1["pos_prov"]; $email_out = $row_ail1["email"]; print <<< MAILLIST <tr> <td><input type="checkbox" name="mailist[$patients_id_out]" value="$patients_id_out" checked></td> <td>$email_out</td> <td>$name_out</td> <td>$pos_city_out</td> <td>$pos_prov_out</td> </tr> MAILLIST; } ?> and include 'includes/conn_db.php'; // Retrieve all of the information for the clients $query = 'SELECT * FROM patients WHERE patients_id IN ('; foreach($_POST['mailist'] as $key => $value) { $query .= $key . ','; $query = substr ($query, 0, -1) . ') ORDER BY email ASC'; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { print <<< MAILLIST <tr> <td align="left"><font face="arial" size="2" color="white">{$row['email']}</font></td> MAILLIST; }} Once I get the array working I should be able to complete the rest of the script I am getting the following error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\htdocs\metabolic-typing\app\bulk_mail_selection.php on line 40 Any help will be appreciated Thanks Lional Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/ Share on other sites More sharing options...
Philip Posted January 26, 2009 Share Posted January 26, 2009 echo out $query, and see what it says, and change: $result = mysql_query($query); $result = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746328 Share on other sites More sharing options...
lional Posted January 26, 2009 Author Share Posted January 26, 2009 I changes the code to: $test = implode (', ', $_POST['mailist']); print "test"; print $test; // Display the cart if it is not empty include 'includes/conn_db.php'; // Retrieve all of the information for the clients $query = 'SELECT * FROM patients WHERE patients_id IN ('; foreach($_POST['mailist'] as $key => $value) { $query .= $key . ','; // $query = substr ($query, 0, -1) . ') ORDER BY email ASC'; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { print <<< MAILLIST <tr> <td align="left"><font face="arial" size="2" color="white">{$row['email']}</font></td> MAILLIST; }} and I get the following error: 631You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746337 Share on other sites More sharing options...
haku Posted January 26, 2009 Share Posted January 26, 2009 Echo out your query and you will see the problem. It's not complete. And you are missing a closing brace (}) in your foreach loop. Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746338 Share on other sites More sharing options...
sasa Posted January 26, 2009 Share Posted January 26, 2009 you didn't close bracket in IN part of query Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746383 Share on other sites More sharing options...
lional Posted January 26, 2009 Author Share Posted January 26, 2009 I changes the code to include 'includes/conn_db.php'; // Retrieve all of the information for the clients $query = 'SELECT * FROM patients WHERE patients_id IN ('; foreach($_POST['mailist'] as $key => $value) { $query .= $key . ','; } $query = substr ($query, 0, -1) . ') ORDER BY email ASC'; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { print <<< MAILLIST <tr> <td align="left"><font face="arial" size="2" color="white">{$row['email']}</font></td> MAILLIST; } I get no errors but I also get no results. I did an implode on the array and it prints about 60 client numbers so a I should print out about that same number. Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746436 Share on other sites More sharing options...
haku Posted January 26, 2009 Share Posted January 26, 2009 echo out the query and paste it here. Quote Link to comment https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746693 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.