943,186 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 510
  • PHP RSS
Jul 6th, 2010
0

PHP 'SELECT' Loop.

Expand Post »
Hi all,
Been some time since my last post.
I'll get straight to it -

I have actual Id's being passed from the checkbox array to a page where I dump the post variables.

I'm using this to query the db.

PHP Syntax (Toggle Plain Text)
  1. $result = mysql_query("SELECT * FROM test WHERE Id='$checkbox[0]';");
  2.  
  3. while($row = mysql_fetch_array($result))
  4. {
  5. echo $row['mobile'] . " " . $row['email'];
  6. echo "<br />";
  7. }

Which is fine if I manually create the array
like so
PHP Syntax (Toggle Plain Text)
  1. $checkbox[]= array(0=>(1), 1=>(2));

In addition some of the numbers require formatting so -

PHP Syntax (Toggle Plain Text)
  1. $mob = $sTestString;
  2. $sPattern = '/\s*/m';
  3. $sReplace = '';
  4. $mob = str_replace ('-', '', $mob);
  5. echo $mob . '<br />';
  6. echo preg_replace($sPattern, $sReplace, $mob );



What I want to do is pass the checkbox array to the SELECT directly on form submit.
Then create an array with the mobile numbers and an array with the emails which will need to be processed to a comma sep string. (if more than one email or mobile number).

I need a loop here on the SELECT right and a counter to see how many checkboxes are checked ?
That's where I'm a bit foggy. ;-)
Is there an alternative more efficient way to do this ?

Regards.
Similar Threads
Reputation Points: 14
Solved Threads: 1
Newbie Poster
Bob Arctor is offline Offline
17 posts
since Nov 2008
Jul 6th, 2010
0
Re: PHP 'SELECT' Loop.
Apologies people for some reason I was looking at the wrong loop.
*slapping head*
It should be

PHP Syntax (Toggle Plain Text)
  1. foreach ($checkbox as $value){
  2. $result = mysql_query("SELECT * FROM test WHERE Id='$value';");
  3. while($row = mysql_fetch_array($result))
  4. {
  5. echo "<br />";
  6. echo $row['mobile'] . " " . $row['email'];
  7. echo "<br />";
  8. }
  9. }
  10. mysql_close($con);
Reputation Points: 14
Solved Threads: 1
Newbie Poster
Bob Arctor is offline Offline
17 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Listbox item color
Next Thread in PHP Forum Timeline: How to insert names in db , when number isnt known





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC