Jump to content

Recommended Posts

What you're saying to do is the exact logic that I want to do with two recordsets.  You see I'm just learning this and I got a dropdown menu that works with a recordset but I can't get it to work with an array because I get get confused on multidimentional arrays and it doesn't work.

Link to comment
https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270268
Share on other sites

A little background,

 

Customers for the site will 99.9% of the time come from US, Canada or Mexico.

 

Everything was working fine until I was asked to come up with a way to take care of the other .1% of potential customers.

 

So on the add customer page I have a drop down menu with states and provinces

for all three countries. There is option for "other" to handle states for other countries.  If that's chosen I pop up a textfield to enter the state name, then store it to a table referenced on customer id.  This all works just fine.

 

Now I'm working on the customer update page and need to combine the state data from my states table with data from other state table if it's there.

Since I can't combine two recordsets I need to use an array.  This is where I'm stuck. not sure how to modify my code to do it.

 

For one thing it's an update page so I need to display current info.

 

I think I should be using foreach instead of do while, plus I'm confused on finding and extracting data from the array.

 

Here's the code that creates the recordset and array that I would like to use instead of the GetStates recordset.

 

Any help will be greatly appreciated.

 

// get state data for states menu array

 

mysql_select_db($database_imcrecycle, $imcrecycle);

$getStatesArray=mysql_query("SELECT * FROM states ORDER BY states.country, states.state_name", $imcrecycle) or die(mysql_error());

 

// build the array and add other state name if customer from seldom used country

 

$arrayStates = array();

while($row = mysql_fetch_array($getStatesArray)){

$arrayStates[$row['state_id']] = $row['state_name'];

}

if ($totalRows_findOtherStateName > 0) {

  while($row = mysql_fetch_array($findOtherStateName)){

    $arrayStates[$row['state_id']] = $row['state_name'];

  }

}

 

 

 

Here's my code for my dropdown menu on my update customer page that I need to change. 

 

<td>

    <select name="state_id" id="state_id" class="text_background"onchange="(this.value==145) ? document.getElementById('newStateLbl').style.display='' : document.getElementById('newStateLbl').style.display='none'">

          <option value="" <?php if (isset($error) && $_POST['state_id'] == $state) { echo 'selected="selected"';

          }

          elseif ($firstState == $state) {echo "selected=\"selected\"";} ?>>

          </option>

          <?php

          do { ?>

            <option value="<?php echo $row_GetStates['state_id']?>"<?php if (!(strcmp($row_GetStates['state_id'], $firstState)))

                {echo "selected=\"selected\"";} ?>><?php echo $row_GetStates['state_name']?>

            </option>

            <?php

            } while ($row_GetStates = mysql_fetch_assoc($GetStates));

              $rows = mysql_num_rows($GetStates);

              if($rows > 0) {

                mysql_data_seek($GetStates, 0);

        $row_GetStates = mysql_fetch_assoc($GetStates);

          }?>

      </select><label style="display:none" id="newStateLbl">Enter Your State: <input type="text" name="newState" class="text_background"></label>

  <?php } ?>

</td>

 

 

Link to comment
https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270765
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.