howster2011 Posted January 18, 2011 Share Posted January 18, 2011 Hi There! Hopefully someone can help. I'm looking for some php script that allows me to display mysql table data in alternating row colors (eg 5 columns and 500 rows). I would also like to add pagination and limit number of rows displayed at a time to e.g. 50. If possible I'd like to be able to sort asc/desc using titles(links) at the top of the displayed data. Hopefully someone may have a script like this that also shows the mysql connection code (sample host, pass, user etc...) - a working php file so to speak that I can edit. Would really appreciate the help. If you could recommend some software or a wizard that could generate the php code for me I would really appreciate it too! THANKS! Quote Link to comment Share on other sites More sharing options...
mikosiko Posted January 18, 2011 Share Posted January 18, 2011 is a lot of examples here for that... just search the forum. the implementation is going to depend on your expertize, now for code generators... also a search in google will give you tons of alternatives. for grids for example here is an alternative (which again is going to depend in your knowledge level or time to learn) http://dev.sencha.com/deploy/dev/examples/ Quote Link to comment Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 This link has most of what you want: http://www.phpfreaks.com/tutorial/basic-pagination You're doing to have to use the modulus operator to determine alternating rows. Quote Link to comment Share on other sites More sharing options...
ruddie Posted January 18, 2011 Share Posted January 18, 2011 Should be pretty simple, I would do it like in a while loop: $color = true; while ( $loops < $amountOfRows ) { if ( $color ) { $color = false; // echo div start .. } else { $color = true; // echo div start.. } // MYSQL code here.. // echo div end.. } And for about how the connecting works.. check out w3schools? I assume you know how to do all this, and I am not going to paste a copy & paste code here. A help forum is meant to give you help, not to give you copy and paste code really.. For the amount of row maxing ... simply change the while to something like this: while ( $loops < $amountOfRows && $loops< $maxEachPage ) Now, for the 'browsing' through these pages, I am going to give you some hints, and if you really can't figure it out, I'll explain it in detail, I would just like you to think a bit amount it first. Hints: - Try using $_GET variables to tell you the page. - You are going to need to add another while loop after this one, which will echo a few href's which link to the next / previous pages. - Change the while loop once more, taking into account which page the user is on. Good luck! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 18, 2011 Share Posted January 18, 2011 An easier way to alternate colors: <?php $color = '#0C0C0C'; //initial color while ( ... ) { // loop code echo '<span style="background-color:' . $color . '">information</span><br>'; $color = ($color == '#0C0C0C')?'#C0C0C0':'#0C0C0C'; // set to second color if already initial color, otherwise set back to initial color } ?> Ken Quote Link to comment Share on other sites More sharing options...
howster2011 Posted January 18, 2011 Author Share Posted January 18, 2011 Thanks a millions for the helpful responses guys! I'm starting out really with php code so need the basics of how to do the above. I saw lots of examples on the web but just wanted to see what yourselves with lots of experience would recommend. Will investigate all the above and again thanks for time. Have a great day! Quote Link to comment Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 Thanks a millions for the helpful responses guys! I'm starting out really with php code so need the basics of how to do the above. I saw lots of examples on the web but just wanted to see what yourselves with lots of experience would recommend. Will investigate all the above and again thanks for time. Have a great day! The tutorial and examples are pretty solid but if you have specific questions be sure to ask Quote Link to comment Share on other sites More sharing options...
howster2011 Posted January 18, 2011 Author Share Posted January 18, 2011 Hi, if i have a database called mydatabase with host = localhost, user = user1 and pass- pass1 and i have a table called people with the fields: name, age and location I'd like to achieve the below in the output: eg: #################### name asc|desc age asc|desc location asc|desc john 33 new york gray color row mary 54 london white color row alex 32 france gray color row and so on... pagination* <= previous 1|2|3 next page=> ###################### *List 50 rows at a time ...would anybody be able to advise of the entire code that would display the above.if i saw code that would do the above it would make more sense to me working backwards. I checked out the basic pagination tutorial but it has me a little bamboozled. Cheers Guys! Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 18, 2011 Share Posted January 18, 2011 ...would anybody be able to advise of the entire code that would display the above. It's been about three hours since your last post and the one before. Are you saying you have read through the tutorials that were provided and don't understand them? If so, what - specifically - do you not understand? 12. All request for code to be written for you should be posted under the freelance section. No exceptions Quote Link to comment Share on other sites More sharing options...
howster2011 Posted January 18, 2011 Author Share Posted January 18, 2011 Hi, In http://www.phpfreaks.com/tutorial/basic-pagination the code appears to pull all the data from the table 'numbers'. I would like to know how to pluck out field data from the table. ..so if the table numbers had fields like: decimals, integers, fractions I would like to display the data in eg decimals and integers. Was hoping to see a link for the output in this specific example. If you could recommend a link where i could see working examples with output I'd really appreciate it. Thanks Quote Link to comment Share on other sites More sharing options...
howster2011 Posted January 18, 2011 Author Share Posted January 18, 2011 Hi, i found what i needed http://www.phpguru.org/static/datagrid.html Thanks Quote Link to comment Share on other sites More sharing options...
Maq Posted January 18, 2011 Share Posted January 18, 2011 Hi, i found what i needed http://www.phpguru.org/static/datagrid.html Thanks Glad you found what you were looking for. If this thread is resolved please mark as so. Quote Link to comment 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.