Page 2 of 2

Posted: Mon May 17, 2004 12:39 pm
by melindaSA
I have never user explode, is this how I would use it?

Code: Select all

<?php
$DepID = $row['depID'];
$DepID = explode('|', $DepID);

?>

Posted: Mon May 17, 2004 1:06 pm
by McGruff
I think the select field was name="position_apply", so:

$data = explode('|', $_POST['position_apply']);

$title = data[0];
$DepID = data[1];

(Of course that doesn't include any validation...)

Posted: Mon May 17, 2004 5:02 pm
by melindaSA
Thank you for your help!

BUT :oops:
I think I am stupid, what am I doing wrong??

Code: Select all

<?php
<?php
    include ('app_inc_fns.php');
    $conn = db_connect();
    echo '<select name="position_apply">';    //Start selection box
    $query = 'SELECT * from positions';
    $result = mysql_query($query);

    while($row = mysql_fetch_assoc($result)) {
         echo '<option value="' . $row[title] . '|' . $row['depID'] . '">' . $row[title] . '</option>';
         echo "/n"; }
         echo '</select>';  //end selection box

    $data = explode('|', $_POST['position_apply']);
    $title = $row[title];
    $depID = $row[depID];

    echo '<input type="hidden" name="position_type" value="' . $depID . '">';
    mysql_free_result($result);
?>
?>
Please excuse my ignorance, but I am still learning PHP!!

Posted: Mon May 17, 2004 7:36 pm
by McGruff
This bit:

Code: Select all

<?php
    $data = explode('|', $_POST['position_apply']);
    $title = $row[title];
    $depID = $row[depID]; 
?>
..is part of the form processor code not part of the form. It extracts a title and the depID for that title from a POST submission.

I'm assuming that there is a one-department-to-many-positions db table relationship, ie that different positions don't all have the same department id. Hence the idea of passing the two together as a pipe separated string in order to associate the correct position with the correct depID.

If I've picked you up correctly, you don't need the hidden field for $depID.

Will be busy at work in the coming week but will try to look back in.

Posted: Sat May 22, 2004 12:19 pm
by melindaSA
Thank you McGruff....

I have it working, I added to my Form processing script! :oops: