Perad Posted December 1, 2006 Share Posted December 1, 2006 I am still getting my head around arrays. I have this function, when i echo out the array values it only records the last value.[code] function reorder () { $query = "SELECT group_name FROM uncgroupss"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $name = $row['group_name']; $valuearray[] = $_POST[$name]; } echo $valuearray[1]; echo $valuearray[2]; echo $valuearray[3]; }[/code]I must be copying over the original value in the while statement. How can i tweak this to make it work? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 The index of arrays starts at zero not one. Do you know you have at least 3 records that will be selected by your query? If you just want to dump the values in the array, use the print_r() function.[code]<?php function reorder () { $query = "SELECT group_name FROM uncgroupss"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $name = $row['group_name']; $valuearray[] = $_POST[$name]; } echo '<pre>' . print_r($valuearray,true) . '</pre>'; }?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Perad Posted December 1, 2006 Author Share Posted December 1, 2006 Ah thanks a lot for the tip, the problem is with a form which has the name "web master" It isn't showing up.Would that be because "$_POST[$name];" doesn't interpret spaces? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 Please explain what you are trying to do with this function. Please post the source of the form that is used.Ken Quote Link to comment Share on other sites More sharing options...
Perad Posted December 1, 2006 Author Share Posted December 1, 2006 This is to make an order system for my website, I was trying to make a script which moved things up and down but found it to hard when people added and removed new groups.In this it will print out each group with an order number. When you submit it i will check that all numbers are consecutive and not the same then i will enter the new orders into my database.I am just having troubles storing all the values in the array.[code]<?function ordergroup () { function arrange (){ echo '<form action="admin_members.php' . '?action=reorder" method="post">'; $membername = $_POST['membername']; $query = "SELECT * FROM uncgroupss ORDER BY group_order"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $groupname = $row['group_name']; $grouporder = $row['group_order']; echo 'Name: '.$groupname.' :: Current Order :: <input name="'.$groupname.'" type="text" size="3" maxlength="3" value="'.$grouporder.'" /><br />'; } echo '<input type="submit" name="submit3" value="Search"></form>'; } function reorder () { $numbercount = 0; $query = "SELECT group_name FROM uncgroupss ORDER BY group_order"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc ($result)) { $name = $row['group_name']; $valuearray[] = $_POST[$name]; $namearray[] = $name; $numbercount++; } echo '<pre>' . print_r($valuearray,true) . '</pre>'; } switch($_GET['action']) { case 'arrange': arrange(); break; case 'reorder': reorder(); break; default: arrange(); }}?>[/code] Quote Link to comment 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.