The page at http://www.eqtraders.com/articles/ar...hp?article=g84 lists the zone to find trade supplies in. The list is across four columns and is sorted by row. When I am looking for a particular zone, I search through the first column, then the 2nd, then the 3rd, and finally the 4th until I find the zone I'm looking for. It would be easier if they were sorted by column so one would just have to look across the tops of each column and know which column the zone that they're looking for is in, then search through just that one column.
Announcement
Collapse
No announcement yet.
Trade supply page
Collapse
X
-
Trade supply page
-- Mewkus: 2100 dings on the server formerly known as Solusek Ro
try: Inventory/Flags/Spells tracker program - (sample output)Tags: None
-
Give me code that will do that.
It needs to take an alphabetically sorted list of unknown length, and output it left to right (that is the only way to draw table in html left to right... you have NO other choice) in a way that gets it in colums like you want.Ngreth Thergn
Ngreth nice Ogre. Ngreth not eat you. Well.... Ngreth not eat you if you still wiggle!
Grandmaster Smith 250
Master Tailor 200
Ogres not dumb - we not lose entire city to froggies
-
Tricky... I think this should work.
In C. Assume the list is in an array and the number of elements in the list is stored in variable listLength.
Code:if(listLength%4==0){ newListLength=listLength; else{ newListLength=listLength + 4 - listLength%4; } /*define the size of the table to be listLength rounded up to the nearest multiple of 4 */ for(i=0;i<newListLength/4;i++){ for(j=0;j<4;j++){ if((i+j*newListLength/4)<listLength){ /*insert item (i+j*newListLength/4) into the table*/ } } }
Last edited by Qaladar Bragollach; 02-07-2006, 09:59 AM.
Comment
-
Actually it is worse than that.
It is not even an array.
what I do right now it LIKE (code not handy... so this is just an example, and just psudocode)
start table.
count = 0
while (data = getDBdata) {
Format data to have proper link and assign it to data_with_link
output "< td >".data_with_link."< /td >"
count ++;
if count > 3 output "< /tr ><tr>";
}
php gets the output from a query one "row" at a time, and I am getting that row and outputting it immediately, never hitting an array.
I guess it would be possible to first output it all to an array, but that is using more memory than my current method.Ngreth Thergn
Ngreth nice Ogre. Ngreth not eat you. Well.... Ngreth not eat you if you still wiggle!
Grandmaster Smith 250
Master Tailor 200
Ogres not dumb - we not lose entire city to froggies
Comment
-
I'm not familiar with php... whatever datastructure your data is currently in surely has an array inside of it somewhere. Is it not possible to access it in an arraylike fashion?
Maybe its in a linked list of some sort (which strikes me as dumb... but *shrug*). In that case you'd have to dump it into an array first. Otherwise you won't know the size of the list.
Comment
-
Linked list sounds right!
and yeah, that is the way PHP and MySQL work together. It is actually a linked list of associative arrays. that array is of the columns, the list is each row.Ngreth Thergn
Ngreth nice Ogre. Ngreth not eat you. Well.... Ngreth not eat you if you still wiggle!
Grandmaster Smith 250
Master Tailor 200
Ogres not dumb - we not lose entire city to froggies
Comment
-
It aint purdy and there's prolly a much better way of doing it, but you'd want to get the output to look like this...
Code:<table> <tr> <td> first<br> second<br> third<br> </td> <td> forth<br> fifth<br> sixth<br> </td> <td> seventh<br> eighth<br> nineth<br> </td> <td> tenth<br> eleventh<br> twelvth<br> </td> </tr> </table>
attempt at pseudo code:
Code:start table. count = 0 zonesPerColumn = 64 /* current zones per column - pre PoR ^/ zonesPerColumn = int((NUMBER_OF_ZONES + 3)/4) /*if you have access to NUMBER_OF_ZONES as a variable/constant */ output "<table><tr>"; while (data = getDBdata) { Format data to have proper link and assign it to data_with_link output " ".data_with_link."<br>" count ++; if count > zonesPerColumn { output "</td><td>"; count = 0; } } output "</tr></table>";
You'll need to add the parameters to the <table> to give it the kind of spacing you want, but those parameters should be the same as what you're already using.
edit: slight code changeLast edited by mewkus; 02-09-2006, 02:39 AM.-- Mewkus: 2100 dings on the server formerly known as Solusek Ro
try: Inventory/Flags/Spells tracker program - (sample output)
Comment
-
Any solution of this sort will require knowing in advance how many zones there are, and if I understood Ngreth right, he doesn't have that information in the page. It would require an additional database query, or a lot of back-and-forth in the script to traverse the list to the end (to count the zones), go back to the start of the list, then print the zones.Sir KyrosKrane Sylvanblade
Master Artisan (300 + GM Trophy in all) of Luclin (Veeshan)
Master Fisherman (200) and possibly Drunk (2xx + 20%), not sober enough to tell!
Lightbringer, Redeemer, and Valiant servant of Erollisi Marr
Comment
-
While it may not be eligant, it should be easy enough to just set it as a constant and update it with each expansion. The impact of not updating the constant once more zones get added is just that you'll start having five columns instead of four until it gets adjusted. I wouldn't see that as a serious flaw, and I doubt your grades will be docked too much because of it.-- Mewkus: 2100 dings on the server formerly known as Solusek Ro
try: Inventory/Flags/Spells tracker program - (sample output)
Comment
-
That raises a different problem, though. I don't think every zone in the game is in the list already. As more and more obscure items are found, more zones have to be added -- not just when a new expansion is released. Manual updating becomes seven kinds of headaches -- you have to update that constant every time a zone is added or deleted.Sir KyrosKrane Sylvanblade
Master Artisan (300 + GM Trophy in all) of Luclin (Veeshan)
Master Fisherman (200) and possibly Drunk (2xx + 20%), not sober enough to tell!
Lightbringer, Redeemer, and Valiant servant of Erollisi Marr
Comment
-
Make the constant 10 or 15 more than what the current number of zones are. All that'd mean is that the last column wouldn't be as long as the first 3, until the number of zones catches up.
Having the last column shorter than the first three or having a fifth column for a period of time I think is much less cumbersome than having to search through four columns to find the zone you're looking for.-- Mewkus: 2100 dings on the server formerly known as Solusek Ro
try: Inventory/Flags/Spells tracker program - (sample output)
Comment
-
I am not really familiar with php, but why not use something like the following ?
Code:SELECT COUNT(*) FROM table_with_zone_names
Code:$query = "SELECT COUNT(*) FROM table_with_zone_names"; $result = mysql_query($query);
Just an idea and probably totaly off.LazyLizard Saruton
Dreadlord of Greenmist
Keeper of the Lost tome of complete and utterly nonsense
Master Linguist
Comment
-
That works, but that's an extra database query.
Actually, what I'm thinking may work is to just modify the code a little bit. Instead of writing the links and whatnot directly to the page, instead "write" them in an array. That way, you only have to cycle through the DB results once and you wouldn't need an extra DB query. You could get the total number of items quite easily, and a simple calculation tells you how many items should be in each column. Use a loop to output them, with a counter of some sort to tell you when you need a new column.
It would be a tiny bit more processing in the Web page, but the impact should be close to nil. PHP is pretty darn optimized for stuff like this.Sir KyrosKrane Sylvanblade
Master Artisan (300 + GM Trophy in all) of Luclin (Veeshan)
Master Fisherman (200) and possibly Drunk (2xx + 20%), not sober enough to tell!
Lightbringer, Redeemer, and Valiant servant of Erollisi Marr
Comment
Comment