Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP/MySQL Form question - can multiple records be displayed?

Status
Not open for further replies.

peterv12

Technical User
Dec 31, 2008
108
US
I have a PHP form that I'm using to process 2 MySQL tables. When I do a search, if one row is returned, the data is displayed in the same form that the input data was entered into. If multiple rows are returned, however, I'd like to be able to do one of 2 things.

1. Display the multiple rows in a table format. (I have code to do that, but it displays the table, then the form below it. It's using PHP_SELF.) Obviously I need to figure out how not to display the form in that case.

2. Be able to scroll through the rows one at a time in the form. I don't know if PHP has the capability to do this. I know Visual Basic 6.0 has a scrolling mechanism which would be perfect for this, but I want to do it in PHP.

If anyone has any ideas, I'd appreciate hearing them.
Thanks!
 
for item 1 take a look at my code here:


it's a bit old, and i would do certain things differently now but it will give you a good understanding of how to achieve self-processing forms and basic CRUD applications.

for item 2, there are a number of approaches:

1. output the form X times, where X is the number of records. Wrap each in a separate div so that you can style them. you could make all but one div hidden and then use javascript buttons to make each visible/invisible. this breaks down in its usefulness if there are too many records.
2. have one form and use ajax to populate its fields and updates its data. this is the optimum solution.

there are probably other approaches that are equally worthy. another might be to have the data in each row of the table, editable inline
 
Thanks for the reply. I'm looking at your CRUD example right now. As for item 2, your solutions are too advanced for me at this point in time. I'd have to learn javascript (which I'm planning to do in the near future) and ajax.
Peter V.
 
ajax is not a language. it is just javascript communicating with a remote server.

if you use a development frameork like jQuery you can code an ajax solution like the one you are talking about in a few minutes.

another solution is to have the rows showing as the main page and then a thickbox (web dialog) 'pop-up' with the data in editable form. saving the record both updates the underlying html table and the remote database table. it sounds complex, but in reality it's 10 minutes coding.
 
w3c has some samples of AJAX with PHP.

You can use the sample, toy with it and extend with other parametres, new js functions, etc.

Also you would want to add at least another readystate (3(waiting)). I usually dont add the readystate 1 or 2, since they go by so fast, that it will just confuse the user. (sending data, etc.)

Olav Alexander Mjelde
 
Yes, in today's Internet, you need to use AJAX. It is the best solution to flip through records (and many, many other things). AJAX is easy and can be learned in less than a day. Here is another resource for basic examples: w3schools.com

Creator of - Movie Reviews, Movie Lists, and much more!
 
Thanks to jpadie, DaButcher, and barryna, I will look into the w3schools information on Ajax and give it a try!
Peter V.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top