0

ive got over thousands my clients email in database.

sorting the email with php:

$q = $db->query("SELECT email FROM user LIMIT 200");
while($r = $q->fetch_array(MYSQLI_ASSOC)) :
  echo '<input type="checkbox" name="emailList" class="useremail" value="'.$r['email'].'">';
endwhile;

anyone knows how to post the selected email only?. if possible with ajax jquery. well of course i will use phpmailer to post the email.

tonoslfx
  • 3,422
  • 15
  • 65
  • 107

2 Answers2

1
how do i echo out random email

query

SELECT email FROM user ORDER BY RAND() LIMIT 200

Generally, using ORDER BY RAND() is not a good idea. check here http://jan.kneschke.de/projects/mysql/order-by-rand/

Gowri
  • 16,587
  • 26
  • 100
  • 160
1

You can SELECT random rows by using RAND();

$q = $db->query("SELECT email FROM user ORDER BY RAND() LIMIT 200");

Your second question is not clear though, you will need to change the value of the checkbox to the email address or an id relating to that email, maybe like this:

while($r = $q->fetch_array(MYSQLI_ASSOC)) :
  echo '<input type="checkbox" name="emailList" class="useremail" value="'.$r['email'].'">';
endwhile;

You can then access checked values of emailList by using $_POST or $_GET.

var_dump($_POST);

Or

var_dump($_GET);
Jake N
  • 10,535
  • 11
  • 66
  • 112
  • i just updated my question with ur answer! what i mean was, there will be possible 200 emails `(checkbox->email address)`. and i want to check/select which email i want to post. and only selected email will be submited & posted. and i want to do it with jquery ajax. hope u get what i mean :) – tonoslfx Mar 19 '11 at 11:16
  • I wrote this other day - it might be a good starting point http://stackoverflow.com/questions/5346171/ajax-get-data-from-php/5346253#5346253 – Jake N Mar 19 '11 at 11:21
  • thanks for the link jake! i understand to get if only one email selected. and how if i select more than 1 email. and how do i get those email value with ajax – tonoslfx Mar 19 '11 at 11:31