kito2
www.masteria.net
It would work but would take more time to load.
I don't care about that xD
It would work but would take more time to load.
Same script, but rewrited.
PHP:<?php $ots = POT::getInstance(); $ots->connect(POT::DB_MYSQL, connection()); $SQL = $ots->getDBHandle(); $vocations = array('None', 'Sorcerer', 'Druid', 'Paladin', 'Knight', 'Master Sorcerer', 'Elder Druid', 'Royal Paladin', 'Elite Knight'); echo '<FORM ACTION="" METHOD=post> <TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%> <TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B>Spell Search</B></TD></TR> <TR BGCOLOR='.$config['site']['darkborder'].'><TD>Only for vocation: <SELECT NAME="vocation_id">'; foreach($vocations as $id => $vocation) echo '<option value="'.$id.'">'.$vocation.'</option>'; echo '</SELECT> <INPUT TYPE=submit NAME="Submit" ALT="Submit" ></TD><TR> </TABLE></FORM><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%><TR BGCOLOR='.$config['site']['vdarkborder'].'><TD CLASS=white><B><font CLASS=white><font color="yellow">Name</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Sentence</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Type<br/>(count)</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Mana</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Exp.<br/>Level</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Magic<br/>Level</font></B></TD><TD CLASS=white><B><font CLASS=white><font color="yellow">Soul</font></B></TD><TD CLASS=white><B><font color="yellow">PACC</font></B></TD><TD CLASS=white><B><font color="yellow">For<br/>Vocations:</font></B></TD></TR>'; $spells = $SQL->query('SELECT * FROM z_spells WHERE hide_spell = 0 ORDER BY name'); foreach($spells as $spell) { $spell_vocations = explode(';', $spell['vocations']); $vocs = ''; foreach($spell_vocations as $allowed) $vocs .= $vocations[$allowed].'<br />'; if($_POST['vocation_id']) { $voc = $_POST['vocation_id']; $promoted = $voc > 4 ? $voc - 4 : false; if(in_array($voc, $spell_vocations) || in_array($promoted, $spell_vocations)) echo '<tr bgcolor=""><td>'.$spell['name'].'</td><td>'.$spell['spell'].'</td><td>'.$spell['spell_type']. ($spell['conj_count'] ? '('.$spell['conj_count'].')' : '').'</td><td>'.$spell['mana'].'</td><td>'.$spell['lvl'].'</td><td></td><td>'.$spell['soul'].'</td><td>'.($spell['pacc'] ? 'yes' : 'no' ).'</td><td>'.$vocs.'</td></tr>'; }else echo '<tr bgcolor=""><td>'.$spell['name'].'</td><td>'.$spell['spell'].'</td><td>'.$spell['spell_type'].'</td><td>'.$spell['mana'].'</td><td>'.$spell['lvl'].'</td><td></td><td>'.$spell['soul'].'</td><td>'.($spell['pacc'] ? 'yes' : 'no' ).'</td><td>'.$vocs.'</td></tr>'; } echo '</TABLE>'; ?>
you must run it first to read spells.xml
PHP:<?php $ots = POT::getInstance(); $ots->connect(POT::DB_MYSQL, connection()); $SQL = $ots->getDBHandle(); $path = 'path/to/spells.xml'; $xml = simplexml_load_file($path); $data = array(); foreach($xml->instant as $item) { $data['spell_type'] = 'instant'; $data['name'] = $item['name']; $data['spell'] = $item['words']; $data['lvl'] = $item['lvl']; $data['mana'] = $item['mana']; $data['pacc'] = $item['prem'] ? $item['prem'] : 0; $data['vocations'] = ''; if($item->vocation) foreach($item->vocation as $voc) $data['vocations'] .= $voc['id'].';'; $data['vocations'] = substr($data['vocations'], 0, -1); $SQL->query(sprintf('INSERT INTO `%s` (`%s`) VALUES ("%s")', 'z_spells', implode('`, `', array_keys($data)), implode('", "', $data))); } $data = array(); foreach($xml->conjure as $item) { $data['spell_type'] = 'conjure'; $data['name'] = $item['name']; $data['spell'] = $item['words']; $data['lvl'] = $item['lvl']; $data['soul'] = $item['soul']; $data['conj_count'] = $item['conjureCount']; $data['mana'] = $item['mana']; $data['pacc'] = $item['prem'] ? $item['prem'] : 0; $data['vocations'] = ''; if($item->vocation) foreach($item->vocation as $voc) $data['vocations'] .= $voc['id'].';'; $data['vocations'] = substr($data['vocations'], 0, -1); $SQL->query(sprintf('INSERT INTO `%s` (`%s`) VALUES ("%s")', 'z_spells', implode('`, `', array_keys($data)), implode('", "', $data))); }?>
For who dont understand this second script, you have to run it one time only, just to add the spells to database, and the first one is to show the spells added to data base by this script.
A PHP Error was encountered
Severity: Warning
Message: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "home/serv/data/spells/spells.xml"
Filename: pages/1.php
Line Number: 7
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: pages/1.php
Line Number: 10
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: pages/1.php
Line Number: 28
If you're talking about load time and that the file is going to be update maybe once a year, then; Why having a whole table for such easy task? I'd rather make a static file acting 'cache' alike. or if you just dislike having static files as cache then; use memcache. But the simple fact of having a whole table just for showing spells is just plain stupid.Dude we are talking about loading time, and its not better you could simply reload the spells.xml to add the new spells to sql table. Update is like once in a year, would it be hard for you to just simply click on a button to reload new spells?
You misunderstood every single part of my post. I never said parsing spells.xml every time the page loaded was faster nor mentioned it as an 'option' for keeping performance & resource usage low. Please, re-read my post. Also, my method is API friendly in case you want to have multiples web pages with that same exact data.But you know that spells.xml would load every time someone goes on that pages. I'm not talking about how bad that is. I'm talking about load time. SQL is much faster to get information from than a .xml file.
We can try it if you want
Yeah ok, but I was talking about loading timeYou misunderstood every single part of my post. I never said parsing spells.xml every time the page loaded was faster nor mentioned it as an 'option' for keeping performance & resource usage low. Please, re-read my post. Also, my method is API friendly in case you want to have multiples web pages with that same exact data.
I'm talking about load time too. Please, re-read my post.Yeah ok, but I was talking about loading time
Tested it and got some errors:
Code:A PHP Error was encountered Severity: Warning Message: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "home/serv/data/spells/spells.xml" Filename: pages/1.php Line Number: 7 A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: pages/1.php Line Number: 10 A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: pages/1.php Line Number: 28
@tatu
Now I fixed that problem, but now seeing mtibia - the fenix version! when you choose a vocation it doesn't show them all...
no, :x its very difficult sorting xml parsed values of files, so SQL is best option