Re: while loop help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



peter@orillia.net (Peter Gumbrell) writes:
> if (isset($_POST['workshop_select']))
> {
> print $header_string;
> $user = $HTTP_POST_VARS['username'];
> 
> ***** this is the section that needs some sort of loop ************
if(isset($HTTP_POST_VARS['rank']) && is_array($HTTP_POST_VARS['rank'])){
  foreach($HTTP_POST_VARS['rank'] as $rank){
    $r = substr($rank, -1);
    ereg ('^[A-Za-z]*([0-9]+)-', $rank, $matches);
    $workshop_ID = $matches[1];
    if($r > 0)
      mysql_query=("INSERT INTO choices(user_id, workshop_ID, rank) ".
                   "VALUES ($user, $workshop_ID, $r)");
  }
}
> *********************************************************************
> }

I guess the above code would do what you want. I can't see what the
'WHERE $rank > 0' part in an INSERT query would be good for or how it
could be allowed, but there might be something I'm not aware of here
(not sure what you want to accomplish, but I guess an if test would be
right). Also, I presume you want '[0-9]+' in the regexp, but I never
use the ereg functions, so I'm not sure about the syntax. You
definitely want to look up the ereg function
(http://www.php.net/manual/en/function.ereg.php) as it only returns an
int, not a match.

I have NOT tested the above code.


-- 
--Fredrik
"Why be a man when you can be a success?"
		-- Bertold Brecht

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux