Jump to content

use 2 fetch_arrays in a while loop


ahaberman25

Recommended Posts

How come this wont work?

$check = mysql_query($data);
if (mysql_num_rows($check) > 0) {
	echo 'yes';
	$res = mysql_query("SELECT * FROM $tbl_name WHERE id='$id'");
	while($row = mysql_fetch_array($res) && $deal = mysql_fetch_array($check)) {
  	
 	echo "<p>You have earned " . $deal['name'] . " worth " . $deal['value'] ." dollars.</p>";


 	// Send notification email.
 	$to = $row['email']; 
 	// this is your Email address
    $from = "andrew@websbydrew.com"; 
    // this is the sender's Email address
    // $first_name = $_POST['first_name'];
    // $last_name = $_POST['last_name'];
    $subject = "You have earned a free ??? ";
    $subject2 = "Copy of reward notification";
    $message = "You have earned " . $deal['name'] . " worth " . $deal['value'] ." dollars.";
    $message2 = "customer " . $row['name'] . " has earned a free " . $deal['name'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); 
    // sends a copy of the message to the sender
    echo "Notification has been sent to " . $row['email'];
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    // You cannot use header and echo together. It's one or the other.
		} 

it will only use $deal[]

Edited by ahaberman25
Link to comment
Share on other sites

the posted code makes little sense, both because it doesn't show the relevant information leading up to that point (what query are you running, where is $id coming from and what does it mean, what is in $tbl_name...) and the while(){} logic would require there to be the same number of rows for both results sets. however, the query against whatever is in $tbl_name implies there is one row from that query, with a specific id, so at best, your loop will only produce output the first time through the loop.

 

i'm guessing this code starts where your previous thread ended and that $tbl_name is 'customers'? your goal when retrieving related data from a database is to do it using one query. the query you ended up with at the end of your previous thread does/or should return the 'customers' table email and name for the specified id. all you need to do is select those in the query and referenced them in the php code.

Link to comment
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.