Jump to content
rootKID

possible to get first ID out of 100?

Recommended Posts

Hi W3S!

 

Well not sure if this is possible to do in a SQL, i'm more of a "basic" guy in the SQL world...

 

Well i did ask about "tabs & panes" for my forum project, however i have some trouble with the tabs & panes.

 

So i thought, whenever a user enters my forum file (forums.php)... is it possible to get the very first ID via SQL if there is about 100 forums in there?

 

My point is really to divide all the overforums into tabs that is clickable and so on?

I did consider just to normally say "if ! isset" then take ID 1, else take the overforums where tab has been choosen.

My question now is basically if it's possible to tell the server to take the very first ID of a table if there is about 100 rows in a table?

 

I think it is possible.. but like i said, still a basic-pro guy... not a hardcore-pro hehe :P

 

Anyways, hope you can help me out! Thanks alot! :)

 

 

Share this post


Link to post
Share on other sites

Use SQL. You can order the rows by their id, then use the LIMIT clause to only show one row

Share this post


Link to post
Share on other sites

so the offset would be the number i would like right? And the count would be the id of the row right? Or missing something? :)

Share this post


Link to post
Share on other sites

In the article, offset refers to which row you start retrieving data from, count refers to how many rows you want to retrieve.

Share this post


Link to post
Share on other sites

got it, thanks! :)

 

EDIT:

 

However, i just realized something.

IF i am going to use the way with offset etc in the SQL, will i be able to still retrieve the other rows in the table? I want only the first ID of all the rows to appear so i can use that in a variable called "$first_tab" and make an if/else statement to check if it should have the "active" class orr "not_active" class... that is what the idea is anyways.

 

My question is simple, will i be able to use this SQL in a while loop, somehow only get the first ID in the variable, use that to give the class to the first "<li>" HTML and retrieve the others still to appear under it?

 

Thanks! :)

Edited by rootKID

Share this post


Link to post
Share on other sites

Then you don't need the LIMIT clause at all. There's no point in doing two queries when all the data can be obtained with one. Just select all the rows that you plan on using in the page.

 

When you fetch the rows, do one thing with the first row and another thing with all the rest.

 

Here's how the program structure would look:

if($row = fetch()) {    // First row}while($row = fetch()) {    // All the rest of the rows}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...