PDA

View Full Version : [Resolved] Looking for Script to sort table data (& populate database)



toastysquirrel
10-10-2006, 05:51 PM
I'm wondering if anyone might know of a prebuilt script that I can use to do the following:

There are two things I want to do: (1) Make the data in a table on one of my pages sortable. (2-optional) Update/enter the data in a MySQL database.

Currently I have a page on my site that displays data in a table consisting of five colums that include values of text (including an href), numeric/decimal, and date. Right now, whenever I need to update the table I have to add a new row and populate the colums with their data (via php). All the info is housed on that webpage.

This seems like it should be something fairly simple, however I'm having a hellofa time finding a prebaked database/script to impliment at least one of these features. If I had the time I would learn how to code it all myself, but I'm looking at a time frame of a couple days before I need it online.

Does anyone have any ideas of a script that, at the very least, would do the table sorting? Preferably handling the database as well (though optional, like I mentioned). Did I mention "free" would also be a nice feature? :D I've searched online and found a few that handle the sorting but their coding seems a bit off and usually ends up screwing up the java on the rest of my page.

I'm open to any thoughts or suggestions and I really appreciate even the most miniscule amount of help :)

nelis
10-10-2006, 06:56 PM
Why not just have a link above each table column pointing to the page and have a sort argument for the query...


Example

<A href="testpage.php?sortby=date">Date</A>

then in the query do

SELECT * FROM table1 WHERE etcetc... ORDER BY $_GET['sortby']

Of course I would do some error checking in there.. but it's fairly simple to do.

So when they click on a given column, it will sort by that column type.

toastysquirrel
10-10-2006, 07:28 PM
Why not just have a link above each table column pointing to the page and have a sort argument for the query...


Example

<A href="testpage.php?sortby=date">Date</A>

then in the query do

SELECT * FROM table1 WHERE etcetc... ORDER BY $_GET['sortby']

Of course I would do some error checking in there.. but it's fairly simple to do.

So when they click on a given column, it will sort by that column type.

Hey Nelis,

Thanks for the suggesion, it sounds like a fairly easy enough fix for it However, from my severly limited experience with creating DBs I'm guessing that the query code you referenced is for querying a MySQL DB. Right now I'm not using one, everything's simple text fields within a PHP page plugged into nothing more then a table.


<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" align="left" valign="top" class="sr_game_name">Game Name</td>
<td align="left" valign="top" class="sr_archive_divider"><img src="../images/reviews/archive_dividers.gif" alt="divider" width="1" height="19" /></td>
<td align="center" valign="top" class="sr_platform">Platform</td>
<td align="left" valign="top" class="sr_archive_divider"><img src="../images/reviews/archive_dividers.gif" alt="divider" width="1" height="19" /></td>
<td align="center" valign="top" class="sr_platform">Rating</td>
<td align="left" valign="top" class="sr_archive_divider"><img src="../images/reviews/archive_dividers.gif" alt="divider" width="1" height="19" /></td>
<td align="center" valign="top" class="sr_date">Date</td>
<td align="left" valign="top" class="sr_archive_divider"><img src="../images/reviews/archive_dividers.gif" alt="divider" width="1" height="19" /></td>
<td align="right" valign="top" class="sr_download">Download</td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle" class="sr_gametd"><a href="#" class="sr_gametext">Tony Hawk's Pro Skater 3</a></td>
<td colspan="2" align="center" valign="middle" class="sr_platformtd">PS2</td>
<td colspan="2" align="center" valign="middle" class="sr_platformtd"><strong>10.0</strong></td>
<td colspan="2" align="right" valign="middle" class="sr_datetd">Oct 29, 2004</td>
<td align="right" valign="middle" class="sr_downloadtd"><a href="#" class="sr_gametext">48.0 mb</a></td>
</tr>
<tr>
<td colspan="2" align="left" valign="middle" class="sr_gametd"><a href="#" class="sr_gametext">Chrono Cross </a></td>
<td colspan="2" align="center" valign="middle" class="sr_platformtd">PS</td>
<td colspan="2" align="center" valign="middle" class="sr_platformtd"><strong>10.0</strong></td>
<td colspan="2" align="right" valign="middle" class="sr_datetd">Jan 6, 2000</td>
<td align="right" valign="middle" class="sr_downloadtd"><a href="#" class="sr_gametext">43.1 mb</a></td>
</tr>

:(

codeexploiter
10-11-2006, 04:16 AM
Posted: toastysquirrel
Right now I'm not using one, everything's simple text fields within a PHP page plugged into nothing more then a table.

Are you refering HTML tables using which you've performed the alignment/formatting of your form elements? If yes then where exactly are you going to store the data from the user that has been entered into the form elements?

You need to insert the data into the database firstly then only you can retrive them later for processing.

Have you implemented the insertion of data into the database?

The code you placed in your latest post is just shows an HTML table based one rather than a PHP one?

toastysquirrel
10-11-2006, 05:26 AM
Sorry, I guess I could have been clearer in my post, it was a bit confusing.

1) Users will not be able to enter any data, rather they will only be able to view the data that I enter.
2) Currently there is no database, that's something I'm looking for. Perhaps I'm asking too much for something prebaked. It just seems like some an empty database with fields ripe for populating would be out there along with a simple PHP front end for viewing it on a webpage in a table.

Since I currently don't have a database I'm fighting tooth-and-nail with a javascript to get it to work appear correctly on my site.

I hope this post makes my plight a little clearer. :)

djr33
10-11-2006, 05:55 AM
databases don't come set up.
That's pointless.
you make the tables, rows, cells, etc.
that's why they're useful.
take a look here and see if it may help:
http://php-mysql-tutorial.com

toastysquirrel
10-11-2006, 04:49 PM
Yeah, I somewhat figured a "generic database" wasn't something I'd be likely to find, not a good quality one anyway. I use about three other databases on my site (or is it four?) and was hoping, "hey, maybe some else has created something for what I'm looking for?" Anyway, someone pointed me to a decent javascript that handles the sorting very nicely... I had to monkey my way around it and figure out how to maintain the reference to my CSS's classes since the javascript required assigning its own classes to those columns... but I finally got it working good enough. So, one more milestone behind me.

I really appreciate the help you guys sent my way, every little bit does help; thanks everyone!