herghost Posted July 20, 2011 Share Posted July 20, 2011 Hi all, For some reason I cant wrap my head around a concept, its pretty simple if I explain it English but my tired brain can't follow the path to coding it. Basically what I want to do is this count rows in database (ive got this bit ) divide rows by 20 display 1st 20 results in <div id=a> divide the remaing results by 20 and create a <div id=b> for each <div id=a> displays the 1st 20 <div id=b> displays 21-40 <div id=b> displays 41-60 etc its basically for a jquery pagination script where each set of results is held in a div Hope someone can point me in the right direction! many thanks Quote Link to comment https://forums.phpfreaks.com/topic/242397-help-with-achieving-method/ Share on other sites More sharing options...
Psycho Posted July 20, 2011 Share Posted July 20, 2011 Either I am misunderstanding what you want or the problem is super simple. You don't need to count the rows, just get all the results and process them in-line. BUt, I would highly suggest using a numeric id for the divs. It will make life so much simper. Otherwise you have to decide what happens if you were to have more than 26 divs. Do you use 'aa', 'ab', ... or what. $rows_per_div = 20; $query = "SELECT * FROM table_name"; $result = myslq_query($query); $html = ''; $rowNum = 0; while($row = mysql_fetch_assoc($result)) { $rowNum++; //Open new div if first record in set if($rowNum%$rows_per_div == 1) { $html .= "<div id=\"$rowNum\">\n"; } //Display current record $html .= "{$row['name']}<br>\n"; //Close div if max records reached if($rowNum%$rows_per_div == 0) { $html .= "</div>\n"; } } //Close last div if still open if($rowNum%$rows_per_div != 0) { $html .= "</div>\n"; } If you really, really need to use an alphabetically named id's for the divs, replace this $html .= "<div id=\"$rowNum\">\n"; with this $html .= "<div id=\"" . chr($rowNum+96) . "\">\n"; Quote Link to comment https://forums.phpfreaks.com/topic/242397-help-with-achieving-method/#findComment-1244943 Share on other sites More sharing options...
Cless Posted July 20, 2011 Share Posted July 20, 2011 Not to mention you shouldn't be using the same ID for different elements. Quote Link to comment https://forums.phpfreaks.com/topic/242397-help-with-achieving-method/#findComment-1244944 Share on other sites More sharing options...
herghost Posted July 21, 2011 Author Share Posted July 21, 2011 Thanks, basically what happens is everything apart from the 1st set of results is stored in a hidden div, and then called by the jquery. This should get me going Quote Link to comment https://forums.phpfreaks.com/topic/242397-help-with-achieving-method/#findComment-1245546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.