Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/142442-help-with-arrays/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746337
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/142442-help-with-arrays/#findComment-746436
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.