jim.davidson Posted June 7, 2007 Share Posted June 7, 2007 I'm not sure if I ask this here or in mySQL forum Here's my question: I do a query, and get the results in a recordset. Is it possible to add a record to that existing recordset? Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/ Share on other sites More sharing options...
The Little Guy Posted June 7, 2007 Share Posted June 7, 2007 Im not sure if this is what you mean, but... You can do a query, return an array result, then do an array_merge() to combine 2 arrays, or You can do a query, return an array result, then do an array_push, to push values onto the end of the array. Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270250 Share on other sites More sharing options...
jim.davidson Posted June 7, 2007 Author Share Posted June 7, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270268 Share on other sites More sharing options...
The Little Guy Posted June 7, 2007 Share Posted June 7, 2007 http://snippets.tzfiles.com/snippet.php?id=10 Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270274 Share on other sites More sharing options...
trq Posted June 7, 2007 Share Posted June 7, 2007 Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270373 Share on other sites More sharing options...
jim.davidson Posted June 8, 2007 Author Share Posted June 8, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-270765 Share on other sites More sharing options...
jim.davidson Posted June 11, 2007 Author Share Posted June 11, 2007 Still looking for some help Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-272542 Share on other sites More sharing options...
jim.davidson Posted June 12, 2007 Author Share Posted June 12, 2007 I figured another way, I'll have one recordset on the two tables via mySQL UNION Quote Link to comment https://forums.phpfreaks.com/topic/54642-recordset-question/#findComment-273247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.