ahaberman25 Posted April 9, 2014 Share Posted April 9, 2014 (edited) 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 April 9, 2014 by ahaberman25 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 10, 2014 Share Posted April 10, 2014 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. Quote Link to comment 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.