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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View Reocords (rows) one at a time

Status
Not open for further replies.

casabella

Programmer
Aug 30, 2007
59
US
I am working on a PHP script where a data grid is shown; from here, user can select a row (or record) which is then opened in a window.

Once in the window, user can edit and save the record. Saving the record barely flashes and shows message saying that record has been successfully changed.

I want to give the user the option to click on a NEXT button to move to next record in the table or PREVIOUS to move to previous record in the table while in "full record view mode".

Here is the catch, the data grid holds the recordID which is used to open record by windowed script. On the grid, the records are sorted by NAME and so when pressing NEXT and/or PREV, I need to go to the record corresponding to the alphabetical order not the ID.

To make matter worst, the NAME is not UNIQUE.

My initial idea is to query by name where id equals ID start x,y but I get the feeling that this is not right, I just cannot put my finger on it.

Any suggestions?

Regards,


Jose
 
what about creating a js array with the elements ids in name order? Then you can access the array with the current value to get the next/previous records

Bastien

I wish my computer would do what I want it to do,
instead of what I tell it to do...
 
Bastien,

That is exactly what I ended up doing. I did not want this approach fearing

"Once table reaches X of 1000s of records, the loop will slow processing down"

For now, with less than 1000 records it moves pretty well. I am going to limit my search to matching names to the alphabet letters A through Z. In other words, the user will have A B C D E F ... Z as links to filter/group records to load data grid. Having chosen a letter, my queries will be limited to names who's first initial matches the chosen letter. This, I hope, will keep breathing room thus minimizing the effect of the constant loop.

Thanks,


Jose



 
Casabella
If you want to do it in PHP your questions will get a better response in forum434. If you simply want an index field on a recordset try
Code:
Select pictitle,description, @row_index:=@row_index+1 row_index from pics  ,(select @row_index:=0) ri
You can add a WHERE clause as required, and that query will produce a recordset containing pictitle, description and row_index field, where row_index is generated for each live query.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
johnwm,

There were two pieces to the puzzle.

1) How can I move record pointer back and forth one record
at a time in MySQL

2) How can I dump an entire MySQL query into an array in PHP

The first part is purely MySQL which is why I posted this question. The second, I posted it in forum434:pHP, there I got the same suggestion as Bastien posted here.

I really had it covered as far as PHP was concerned I just did not want to use the 'loop' since I feel that it will eventually hog a lot of CPU/Memory. Imagine sever dozen users looping through several thousand records every couple of seconds ...

Regards,


Jose

 
I think you are worrying unduly.

Ask the dBase server to return the results in order in the first place, then just write all the results to a list.

Depending on your enviroment - you can share the list between users, and create a copy of the information for editing when you need to (to maintian thread-safety).

This 'DataSet' mentality is a big facting in ADO.net. Getting information form memory will pretty much ALWAYS be faster than finding it in a database - even with cursors (Database Cursors)


Yet another unchecked rambling brought to you by:
Oddball
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top