debuggen der sql-anweisungen

main
radiskull 13 years ago
parent 745408426d
commit 22df503494

@ -12,6 +12,7 @@
include_once(ROOT_PATH.'/include/attackenset.inc.php'); include_once(ROOT_PATH.'/include/attackenset.inc.php');
include_once(ROOT_PATH.'/include/erstellfunctions.inc.php'); include_once(ROOT_PATH.'/include/erstellfunctions.inc.php');
include_once(ROOT_PATH.'/include/designfunctions.inc.php'); include_once(ROOT_PATH.'/include/designfunctions.inc.php');
include_once(ROOT_PATH.'/include/sqlwrapper.inc.php');
define('ACTION_EDIT', 'edit'); define('ACTION_EDIT', 'edit');
define('ACTION_CREATE', 'create'); define('ACTION_CREATE', 'create');
@ -29,7 +30,7 @@ function getDropItemsAsOptions(){
union union
SELECT id, item AS name, \'wochen_ware\' as tablename FROM wochen_markt w;'; SELECT id, item AS name, \'wochen_ware\' as tablename FROM wochen_markt w;';
$qry = mysql_query($query); $qry = db_query($query);
// Damit waeren alle noetigen Datenbankaufrufe erledigt! // Damit waeren alle noetigen Datenbankaufrufe erledigt!
while($row = mysql_fetch_assoc($qry)){ while($row = mysql_fetch_assoc($qry)){
$result[$index++] = '<option value=\''.$row['id'].','.$row['tablename'].'\'>'.$row['name'].'</option>'; $result[$index++] = '<option value=\''.$row['id'].','.$row['tablename'].'\'>'.$row['name'].'</option>';
@ -55,12 +56,12 @@ function istrinstr($source, $insert, $search) {
} }
function getNPCUser() { function getNPCUser() {
$qry = mysql_query('SELECT * FROM user WHERE nickname = "'.NPC_USER_NAME.'";'); $qry = db_query('SELECT * FROM user WHERE nickname = "'.NPC_USER_NAME.'";');
return mysql_fetch_assoc($qry); return mysql_fetch_assoc($qry);
} }
function getNPCAttacks() { function getNPCAttacks() {
$qry = mysql_query('SELECT name,id FROM attacken a WHERE info like "%NPC%";'); $qry = db_query('SELECT name,id FROM attacken a WHERE info like "%NPC%";');
$set = array(); $set = array();
while ($result = mysql_fetch_assoc($qry)) { while ($result = mysql_fetch_assoc($qry)) {
@ -73,7 +74,7 @@ function getNPCAttacks() {
function learnNewAttacks($charid, $att_ids) { function learnNewAttacks($charid, $att_ids) {
//auslesen der gelernten Attacken //auslesen der gelernten Attacken
$sql = 'SELECT at_id, id FROM lernen WHERE besitzer = '.$charid.' AND at_id in ('.implode(',', $att_ids).');'; $sql = 'SELECT at_id, id FROM lernen WHERE besitzer = '.$charid.' AND at_id in ('.implode(',', $att_ids).');';
$qry = mysql_query($sql); $qry = db_query($sql);
$learned_atts = array(); $learned_atts = array();
while($result = mysql_fetch_assoc($qry)) { while($result = mysql_fetch_assoc($qry)) {
@ -82,7 +83,7 @@ function learnNewAttacks($charid, $att_ids) {
//Namen der Attacken auslesen //Namen der Attacken auslesen
$sql = 'SELECT id,name FROM attacken WHERE id in ('.implode(',', $att_ids).');'; $sql = 'SELECT id,name FROM attacken WHERE id in ('.implode(',', $att_ids).');';
$qry = mysql_query($sql); $qry = db_query($sql);
$att_names = array(); $att_names = array();
while($result = mysql_fetch_assoc($qry)) { while($result = mysql_fetch_assoc($qry)) {
@ -95,14 +96,14 @@ function learnNewAttacks($charid, $att_ids) {
* Keine Gute Lösung, es wird zwar von der db verhindert, dass doppelte Einträge gespeichert werden * Keine Gute Lösung, es wird zwar von der db verhindert, dass doppelte Einträge gespeichert werden
* aber ungebrauchte Attacken werden so auch nicht gelöscht (höchstens der NPC wird gelöscht) * aber ungebrauchte Attacken werden so auch nicht gelöscht (höchstens der NPC wird gelöscht)
*/ */
mysql_query('INSERT INTO lernen(name,at_id,besitzer,aktiv) VALUES(\''.$att_names[$att].'\','.$att.','.$charid.',1);'); db_query('INSERT INTO lernen(name,at_id,besitzer,aktiv) VALUES(\''.$att_names[$att].'\','.$att.','.$charid.',1);');
} }
} }
} }
function getAttackSet($charid, $att_ids) { function getAttackSet($charid, $att_ids) {
$sql = 'SELECT at_id, id FROM lernen WHERE besitzer = '.$charid.' AND at_id in ('.implode(',', $att_ids).');'; $sql = 'SELECT at_id, id FROM lernen WHERE besitzer = '.$charid.' AND at_id in ('.implode(',', $att_ids).');';
$qry = mysql_query($sql); $qry = db_query($sql);
$learned_atts = array(); $learned_atts = array();
while($result = mysql_fetch_assoc($qry)) { while($result = mysql_fetch_assoc($qry)) {
@ -149,7 +150,7 @@ function displayNPCInfo($action, $task, $charid) {
$sql = 'SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter WHERE c.id ='.$charid; $sql = 'SELECT * FROM chars c inner join npc_item ni on ni.charakter = c.id inner join kampf_list kl on ni.charakter = kl.charakter WHERE c.id ='.$charid;
//$sql = 'SELECT * FROM chars c inner join kampf_list kl on c.id = kl.charakter WHERE c.id ='.$charid; //$sql = 'SELECT * FROM chars c inner join kampf_list kl on c.id = kl.charakter WHERE c.id ='.$charid;
$qry = mysql_query($sql); $qry = db_query($sql);
$row = mysql_fetch_assoc($qry); $row = mysql_fetch_assoc($qry);
} }
@ -250,7 +251,7 @@ function editNPC($charid, $data, $att_ids) {
$sql .= ' WHERE c.id=\''.$charid.'\''; $sql .= ' WHERE c.id=\''.$charid.'\'';
//echo $sql; //echo $sql;
$u = mysql_query($sql); $u = db_query($sql);
$log = 0; $log = 0;
if(mysql_affected_rows() == 0 || $u === FALSE) { if(mysql_affected_rows() == 0 || $u === FALSE) {
@ -265,7 +266,7 @@ function editNPC($charid, $data, $att_ids) {
//alter müll //alter müll
$qry = 'UPDATE chars SET attacken=\''.implode(',', $attset).'\', '. $qry = 'UPDATE chars SET attacken=\''.implode(',', $attset).'\', '.
'attacken2=\''.implode(',', $attset).'\' WHERE id='.$charid.' LIMIT 1'; 'attacken2=\''.implode(',', $attset).'\' WHERE id='.$charid.' LIMIT 1';
mysql_query($qry); db_query($qry);
$log++; $log++;
echo "\t\t\t".'<tr><td colspan="2">Attacken übernommen!</td></tr>'; echo "\t\t\t".'<tr><td colspan="2">Attacken übernommen!</td></tr>';
} else { } else {
@ -292,14 +293,14 @@ function createNPC($data, $att_ids) {
if($success) { if($success) {
//Char ID holen //Char ID holen
$qry = mysql_query('SELECT id FROM chars c WHERE name = "'.$data['name'].'";'); $qry = db_query('SELECT id FROM chars c WHERE name = "'.$data['name'].'";');
$result = mysql_fetch_assoc($qry); $result = mysql_fetch_assoc($qry);
$char_id = $result['id']; $char_id = $result['id'];
//zur Kampfliste hinzufügen :) //zur Kampfliste hinzufügen :)
$sql = 'INSERT INTO kampf_list(kampfname,charakter,rasse,besitzer,zeit,zeit_rec,lvlmax,ip,lvlmin) VALUES("NPC Kampf",'.$char_id.',"NPC","'.NPC_USER_NAME.'",0,'. $sql = 'INSERT INTO kampf_list(kampfname,charakter,rasse,besitzer,zeit,zeit_rec,lvlmax,ip,lvlmin) VALUES("NPC Kampf",'.$char_id.',"NPC","'.NPC_USER_NAME.'",0,'.
$data['zeit_rec'].','.$data['lvlmax'].',0,'.$data['lvlmin'].');'; $data['zeit_rec'].','.$data['lvlmax'].',0,'.$data['lvlmin'].');';
mysql_query($sql); db_query($sql);
//drops hinzufügen :D //drops hinzufügen :D
$sql = 'INSERT INTO npc_item(charakter,item,feld,mal,datensatz,wieviel,preis) VALUES('.$char_id; $sql = 'INSERT INTO npc_item(charakter,item,feld,mal,datensatz,wieviel,preis) VALUES('.$char_id;
@ -311,7 +312,7 @@ function createNPC($data, $att_ids) {
} }
$sql .= ','.$data['drop_max'].',\''.$info[1].'\','.$data['drop_anzahl'].','.$data['preis'].');'; $sql .= ','.$data['drop_max'].',\''.$info[1].'\','.$data['drop_anzahl'].','.$data['preis'].');';
echo $sql; echo $sql;
mysql_query($sql); db_query($sql);
//Attacksets soweit einbinden //Attacksets soweit einbinden
$attset = buildAttackSet($char_id, $att_ids); $attset = buildAttackSet($char_id, $att_ids);
@ -326,7 +327,7 @@ function createNPC($data, $att_ids) {
//alter müll //alter müll
$qry = 'UPDATE chars SET attacken=\''.implode(',', $attset).'\', '. $qry = 'UPDATE chars SET attacken=\''.implode(',', $attset).'\', '.
'attacken2=\''.implode(',', $attset).'\' WHERE id='.$char_id.' LIMIT 1'; 'attacken2=\''.implode(',', $attset).'\' WHERE id='.$char_id.' LIMIT 1';
mysql_query($qry); db_query($qry);
} }
} }
echo "\t".'<tr><td colspan="2" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc">NPC Übersicht</a></td></tr>'."\n"; echo "\t".'<tr><td colspan="2" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'?choose=npc">NPC Übersicht</a></td></tr>'."\n";
@ -336,7 +337,7 @@ function displayDeleteNPC($charid) {
$colspan = 1; $colspan = 1;
$sql = 'SELECT * FROM chars WHERE id = '.$charid; $sql = 'SELECT * FROM chars WHERE id = '.$charid;
$qry = mysql_query($sql); $qry = db_query($sql);
$row = mysql_fetch_assoc($qry); $row = mysql_fetch_assoc($qry);
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">NPC löschen</h1></td></tr>'."\n"; echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">NPC löschen</h1></td></tr>'."\n";
@ -347,7 +348,7 @@ function displayDeleteNPC($charid) {
function deleteNPC($charid) { function deleteNPC($charid) {
$colspan = 1; $colspan = 1;
$sql = 'DELETE FROM chars WHERE id = '.$charid.';'; $sql = 'DELETE FROM chars WHERE id = '.$charid.';';
$qry = mysql_query($sql); $qry = db_query($sql);
if($qry === FALSE || mysql_affected_rows() <= 0){ if($qry === FALSE || mysql_affected_rows() <= 0){
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center;color:red">Der NPC '.$row['name'].' konnte nicht gelöscht werden!</td></tr>'."\n";; echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center;color:red">Der NPC '.$row['name'].' konnte nicht gelöscht werden!</td></tr>'."\n";;
} else { } else {
@ -361,7 +362,7 @@ function displayNPCOverview($page) {
$desc_array = array('id', 'Name', 'Level'); $desc_array = array('id', 'Name', 'Level');
$sql = 'SELECT '.join($d_array,',').' from chars where rasse = \'NPC\' ORDER BY level, Name LIMIT '.($page*20).', 20'; $sql = 'SELECT '.join($d_array,',').' from chars where rasse = \'NPC\' ORDER BY level, Name LIMIT '.($page*20).', 20';
$qry = mysql_query($sql); $qry = db_query($sql);
$colspan = count($d_array); $colspan = count($d_array);
echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">Übersicht</h1></td></tr>'."\n";; echo "\t".'<tr><td colspan="'.$colspan.'"><h1 style="text-align:center">Übersicht</h1></td></tr>'."\n";;
echo "\t".'<tr>'."\n"; echo "\t".'<tr>'."\n";
@ -389,7 +390,7 @@ function displayNPCOverview($page) {
echo "\t".'</tr>'."\n"; echo "\t".'</tr>'."\n";
} }
$total = mysql_num_rows(mysql_query('SELECT '.join($d_array,',').' from chars where rasse = \'NPC\'')); $total = mysql_num_rows(db_query('SELECT '.join($d_array,',').' from chars where rasse = \'NPC\''));
$url = '<a href="'.$_SERVER['PHP_SELF'].'?choose=npc&page=###PAGE###">###LABEL###</a>'; $url = '<a href="'.$_SERVER['PHP_SELF'].'?choose=npc&page=###PAGE###">###LABEL###</a>';
echo "\t".'<tr><td colspan="'.$colspan.'"><hr></td></tr>'."\n"; echo "\t".'<tr><td colspan="'.$colspan.'"><hr></td></tr>'."\n";
echo "\t".'<tr><td colspan="'.$colspan.'">'.displayPagelinksNew(20, $total, $page, $url).'</td></tr>'."\n"; echo "\t".'<tr><td colspan="'.$colspan.'">'.displayPagelinksNew(20, $total, $page, $url).'</td></tr>'."\n";
@ -403,7 +404,8 @@ function displayNPC($action, $task, $charid, $table, $page, $data, $att_ids){
echo "\t".'<input type="hidden" name="choose" value="npc"></input>'."\n"; echo "\t".'<input type="hidden" name="choose" value="npc"></input>'."\n";
echo "\t".'<input type="hidden" name="charid" value="'.$charid.'"></input>'."\n"; echo "\t".'<input type="hidden" name="charid" value="'.$charid.'"></input>'."\n";
echo "\t".'<table width="80%" border="0">'."\n"; echo "\t".'<table width="80%" border="0">'."\n";
if($action == ACTION_EDIT){ switch ($action) {
case ACTION_EDIT:
echo "\t".'<input type="hidden" name="action" value="'.ACTION_EDIT.'"></input>'."\n"; echo "\t".'<input type="hidden" name="action" value="'.ACTION_EDIT.'"></input>'."\n";
if($task == TASK_EDIT) { if($task == TASK_EDIT) {
editNPC($charid, $data, $att_ids); editNPC($charid, $data, $att_ids);
@ -411,20 +413,23 @@ function displayNPC($action, $task, $charid, $table, $page, $data, $att_ids){
} else { } else {
displayNPCInfo(ACTION_EDIT, TASK_EDIT, $charid); displayNPCInfo(ACTION_EDIT, TASK_EDIT, $charid);
} }
} else if($action == ACTION_CREATE){ break;
case ACTION_CREATE:
echo "\t".'<input type="hidden" name="action" value="'.ACTION_CREATE.'"></input>'."\n"; echo "\t".'<input type="hidden" name="action" value="'.ACTION_CREATE.'"></input>'."\n";
if($task == TASK_CREATE) { if($task == TASK_CREATE) {
createNPC($data, $att_ids); createNPC($data, $att_ids);
} else { } else {
displayNPCInfo(ACTION_CREATE, TASK_CREATE, $charid); displayNPCInfo(ACTION_CREATE, TASK_CREATE, $charid);
} }
} else if($action == 'delete'){ break;
case 'delete':
if($task == 'dodelete') { if($task == 'dodelete') {
deleteNPC($charid); deleteNPC($charid);
} else { } else {
displayDeleteNPC($charid); displayDeleteNPC($charid);
} }
} else{ break;
default:
displayNPCOverview($page); displayNPCOverview($page);
} }
echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'">Zum Hauptmenu</a></td></tr>'."\n"; echo "\t".'<tr><td colspan="'.$colspan.'" style="text-align:center"><a href="'.$_SERVER['PHP_SELF'].'">Zum Hauptmenu</a></td></tr>'."\n";

Loading…
Cancel
Save