Nappi Posted June 24, 2010 Share Posted June 24, 2010 Hi all I have a problem with this code $mylines = new xml_line("xmlfile.xml", "hixml"); $mylines->get_record(0,"member",""); $mylines->xml_stream(); for ($i = 0; $i <= 500; $i++) { $name = $mylines->table_result[0][$i]['nickname']; $rang = $mylines->table_result[0][$i]['rank_name']; $prof = $mylines->table_result[0][$i]['profession']; $lvl = $mylines->table_result[0][$i]['level']; $res = $mylines->table_result[0][$i]['photo_url']; $image = substr($res, 47); if ($rang == 'President' or 'General') { $file = one.txt'; $filename = './templates/one.html'; } elseif ($rang == 'Squad Commander') { $file = 'two.txt'; $filename = './templates/two.html'; } else { $file = 'three.txt'; $filename = './templates/three.html'; } The variable $file and $filename is not set like i will, all entris are in the first files "one.txt and one.html" waths wrong ? Selma Link to comment https://forums.phpfreaks.com/topic/205780-if-elseif-else-not-work/ Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 This is not how you write an "if" statement with an "or" <?php if ($rang == 'President' or 'General') { ?> use <?php if ($rang == 'President' || $rang == 'General') { ?> You're missing an initial single quote here: <?php $file = one.txt'; ?> use <?php $file = 'one.txt'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/205780-if-elseif-else-not-work/#findComment-1076838 Share on other sites More sharing options...
Nappi Posted June 25, 2010 Author Share Posted June 25, 2010 Thank you for your replay, and corecting this two errors. But its not working right anyway. Thats realy a simpel code and in all Manuels is it writen like this i downt know way it wont work for me. Selma Link to comment https://forums.phpfreaks.com/topic/205780-if-elseif-else-not-work/#findComment-1077041 Share on other sites More sharing options...
kenrbnsn Posted June 25, 2010 Share Posted June 25, 2010 Please explain what is not working. Ken Link to comment https://forums.phpfreaks.com/topic/205780-if-elseif-else-not-work/#findComment-1077125 Share on other sites More sharing options...
Nappi Posted June 26, 2010 Author Share Posted June 26, 2010 Okay I'll try to explain after the loop is the only variable in what condition are as specified for the loop is. Only the entries by Squad Commander are made so by Squad Commander At the moment he write everything into the last, tree.html, file. without having made a assignment. I've also have treated each section for themselves. if ($rang == 'President' || $rang == 'General') { $file1 = './templates/one.html'; //sicher gehen, dass die Datei existiert und beschreibbar ist if (is_writable($file1)) { // Wir ffnen $filename im "Anhnge" - Modus. // Der Dateizeiger befindet sich am Ende der Datei, und // dort wird $somecontent spter mit fwrite() geschrieben. if (!$handle = fopen($file1, "w")) { exit; } // Schreibe $somecontent in die geffnete Datei. if (!fwrite($handle, $content)) { exit; } fclose($handle); } } for the second if ($rang == 'Squad Commander' && ($rang != 'President' || $rang != 'General')) { $file2= './templates/two.html'; //sicher gehen, dass die Datei existiert und beschreibbar ist if (is_writable($file2)) { // Wir ffnen $filename im "Anhnge" - Modus. // Der Dateizeiger befindet sich am Ende der Datei, und // dort wird $somecontent spter mit fwrite() geschrieben. if (!$handle = fopen($file2, "w")) { exit; } // Schreibe $somecontent in die geffnete Datei. if (!fwrite($handle, $content)) { exit; } fclose($handle); } } If I do so, I write everything from the first row to the last line of the entry in my file. But I would like only the messages of - such as "squad commander" - have, everything before and after should not be written to the file. I hope you can help me greetings Selma Link to comment https://forums.phpfreaks.com/topic/205780-if-elseif-else-not-work/#findComment-1077514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.