473,385 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to use an array to auto fill a form?

I used this code to pull info from the database and into the array.
Expand|Select|Wrap|Line Numbers
  1. $stu_quary = "SELECT `uname` FROM `user` WHERE level = 'Normal' AND class = '".$_SESSION['class']."'"; 
  2.     $stu_names=mysql_query($stu_quary);
  3.     $stuArr=array();
  4.     while($get_stu_info =mysql_fetch_assoc($stu_names)) 
  5.     { 
  6.     $n = 0;
  7.     $stuArr[] = $get_stu_info['uname']; 
  8.     $_SESSION['selected_s'] = current($stuArr);
  9.     } 
  10.  
I then use the session to auto full the form.
When submited I want the next value in the array to be applied to th session.
Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['postComment']))
  2. {
  3.     $query = "INSERT INTO ".$_POST['student_name']."_".$_POST['class']." SET name='".$_POST['student_name']."',title='".$_POST['student_name']." Report for Week: ".$_POST['week']."',subject='".$_POST['subject']."',class='".$_POST['class']."',author='".$_POST['author']."',week='".$_POST['week']."',par='".$_POST['par']."',beh='".$_POST['beh']."',lis='".$_POST['lis']."',spe='".$_POST['spe']."',mot='".$_POST['mot']."',ret='".$_POST['ret']."',comments='".$_POST['comment']."',";
  4.     $query .="date_posted=NOW(),categoryID='".$_POST['select']."',artchild='0'";
  5.     if(!mysql_query($query))
  6.     {        
  7.         echo mysql_error();
  8.     }
  9.     else
  10.     {
  11.         $_SESSION['selected_s'] = next($stuArr);
  12.     }
  13.  
I use this code but it only works for the first time a form is submited afterwards the value stays the same.
Is is next() the right function?
What would be the bst way to achieve this?
Thanks in advance.
Jan 24 '11 #1
1 2222
mfaisalwarraich
194 100+
i think u need to get relative values. try with this one. i have altered this function to get its relative values instead of keys.:

Expand|Select|Wrap|Line Numbers
  1. function array_key_relative($array, $current_key, $offset = 1)
  2. {
  3.      // create key map
  4.      $keys = array_values($array);
  5.      // find current key
  6.      $current_key_index = array_search($current_key, $keys);
  7.      // return desired offset, if in array, or false if not
  8.      if(isset($keys[$current_key_index + $offset]))
  9.      {
  10.          return $keys[$current_key_index + $offset];
  11.      }
  12.      return false;
  13. }
  14. //next value :
  15. array_key_relative($$stuArr,$current_value,1);
  16. //previous value
  17. array_key_relative($$stuArr,$current_value,-1);
  18.  
Jan 25 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Maurice Mertens | last post by:
Does anyone know how to get an auto-filling combobox on a form? When I add a combobox to a form I can set the DropDownStyle property to DropDownList. This will make the combobox auto-filling. But...
1
by: mikeybe | last post by:
Making a very simple library circulation database for a school project. I have a Patron Information table(patronID, first name, last name, phone) , an item information table (bookID, book title,...
3
by: MatGyver | last post by:
I am going nuts trying to figure this out, any help will be appreciated. I have an existing table called "Parts". And in this table I have the following columns: "ID" "Part Number" "Part...
2
by: Joanne Lewis | last post by:
I am having a great deal of difficulty with a form. Basically, I would like to enter an account # and have the account #, patient first name, and patient last name automatically fill. The form...
0
by: KelHemp | last post by:
Greetings, I've been using this site for lots of access help in the past, and it's very helpful! I have a new complexity for you all. Reworking a form to record 70-80 years of oil production on...
1
by: camphor | last post by:
hi, I need help with some code for an e-commerce site and am not sure which forum this question falls into but this is what I am after: the buyer goes through the shopping cart stage, he/she has...
2
by: mxdllc | last post by:
i would like to create an admin panel for my business. because i have 5 or 6 suppliers and to order i have to lookup which supplier it is then find the url, so to make things a little easier im going...
3
by: Steve67 | last post by:
I didn't see a search feature in these forums, so I couldn't look up this question and I am sure it is a common questions. I am trying to auto fill some information on an form. Here is what I have...
2
by: Xaysana12345 | last post by:
Please help. I have been developing a financial database, now I have been in last bit to finish. i do not know much technical terms, but i am trying to explain what i need. so please be with me. ...
106
by: bonneylake | last post by:
Hey Everyone, Well i don't know if my question should be in javascript/ajax or coldfusion, i figure this is more of a coldfusion question. But if this is in the wrong section let me know an all...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.