rootKID Posted February 28, 2015 Share Posted February 28, 2015 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 Anyways, hope you can help me out! Thanks alot! Link to comment Share on other sites More sharing options...
Ingolme Posted February 28, 2015 Share Posted February 28, 2015 Use SQL. You can order the rows by their id, then use the LIMIT clause to only show one row Link to comment Share on other sites More sharing options...
rootKID Posted February 28, 2015 Author Share Posted February 28, 2015 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? Link to comment Share on other sites More sharing options...
Ingolme Posted February 28, 2015 Share Posted February 28, 2015 In the article, offset refers to which row you start retrieving data from, count refers to how many rows you want to retrieve. Link to comment Share on other sites More sharing options...
rootKID Posted March 1, 2015 Author Share Posted March 1, 2015 (edited) 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 March 1, 2015 by rootKID Link to comment Share on other sites More sharing options...
Ingolme Posted March 2, 2015 Share Posted March 2, 2015 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} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now