12 Replies - 2229 Views - Last Post: 27 January 2011 - 05:59 AM Rate Topic: -----

#1 Guest_Xiy*


Reputation:

For each row in database

Posted 26 January 2011 - 09:52 AM

Hey,

I'm working on a personal project (just for fun), and I'm wondering is there any way to call each row from the database, but increment and display the next row each time it's refreshed.

For example:
1 table, 10 rows, 2 columns (question, question_id).

Is it possible (when a user starts the page, that it shows question (1), then on click, show question (2), etc, right up till 10; then at 10 it updates the data into the database?

Thanks

Is This A Good Question/Topic? 0

Replies To: For each row in database

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3077
  • Posts: 10,786
  • Joined: 08-August 08

Re: For each row in database

Posted 26 January 2011 - 10:07 AM

Yes, it's possible. For example, you can use sessions to keep track of where you are in the table.
Was This Post Helpful? 0
  • +
  • -

#3 Guest_Xiy*


Reputation:

Re: For each row in database

Posted 26 January 2011 - 10:09 AM

Hmm okay, glad to know it's possible. Do you have any reference/tutorial on how to do it?
Was This Post Helpful? 0

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10778
  • View blog
  • Posts: 40,134
  • Joined: 27-December 08

Re: For each row in database

Posted 26 January 2011 - 10:13 AM

You can check out the PHP Tutorials Section. Basically, store the result set and counter each as session variables. Then when the page is loaded, display the row at the counter index, then increment counter.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Xiy*


Reputation:

Re: For each row in database

Posted 26 January 2011 - 10:50 AM

Thanks for the replies.

Still a little confused on how it all works though, I know how to store info into sessions, but not show how I counter them.
Was This Post Helpful? 0

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10778
  • View blog
  • Posts: 40,134
  • Joined: 27-December 08

Re: For each row in database

Posted 26 January 2011 - 10:55 AM

Use a for loop from 0 through whatever value is in the counter variable to iterate through the result set array.
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Xiy*


Reputation:

Re: For each row in database

Posted 26 January 2011 - 11:09 AM

Hmm, still confused. I think I'll have to do some more research on it.
Was This Post Helpful? 0

#8 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3077
  • Posts: 10,786
  • Joined: 08-August 08

Re: For each row in database

Posted 26 January 2011 - 12:26 PM

Read up on the SQL command: LIMIT
Was This Post Helpful? 0
  • +
  • -

#9 Guest_Xiy*


Reputation:

Re: For each row in database

Posted 26 January 2011 - 12:50 PM

I've tried Limiting it by 1, shows the first row, but I want to click on a button and show row 2, then click again, row 3, etc.
Was This Post Helpful? 0

#10 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3077
  • Posts: 10,786
  • Joined: 08-August 08

Re: For each row in database

Posted 26 January 2011 - 02:59 PM

http://php.about.com...g/Limit_sql.htm
Was This Post Helpful? 0
  • +
  • -

#11 Guest_Xiy*


Reputation:

Re: For each row in database

Posted 26 January 2011 - 03:10 PM

I understand the limit part, just I don't understand how I can update the database for a result, then click on a 'submit button' and it then shows row 2, and then click the submit button, and then it shows row 3, and so on right up to 10. Thanks for the help btw.
Was This Post Helpful? 0

#12 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3077
  • Posts: 10,786
  • Joined: 08-August 08

Re: For each row in database

Posted 26 January 2011 - 03:52 PM

An SQL query is a string. Strings can be manipulated.

In the first session, it might be:

... LIMIT 0,1

The second would be:
... LIMIT 1,1

and so on:

... LIMIT n,1

It's up to you to vary n.
Was This Post Helpful? 3
  • +
  • -

#13 Xiy  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 33
  • Joined: 30-August 09

Re: For each row in database

Posted 27 January 2011 - 05:59 AM

Sorted it out now, works good! Thanks for the help. When I think of it of just storing the data in sessions, it became pretty simple. Thanks again!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1