[SOLVED]Two select queries help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

I have never user explode, is this how I would use it?

Code: Select all

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

?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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...)
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post 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!!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
Last edited by McGruff on Tue Aug 09, 2005 12:03 am, edited 1 time in total.
melindaSA
Forum Commoner
Posts: 99
Joined: Thu Oct 02, 2003 7:34 am

Post by melindaSA »

Thank you McGruff....

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