AE117 Posted April 20, 2009 Share Posted April 20, 2009 Heres the code to start with <?php $host = ""; $user = ""; $pass = ""; $database = "; if(!$dbconnect = mysql_connect($host, $user, $pass)) { echo "Connection failed to the host 'localhost'."; exit; } // if if (!mysql_select_db($database)) { echo "Cannot connect to database"; exit; } // if header("Content-Type: text/xml"); $table_id = 'ost_media'; $query = "SELECT * FROM $table_id"; $dbresult = mysql_query($query, $dbconnect); $outer_table = 'ost_media'; $query = "SELECT * FROM ost_media WHERE media_title='1997 Eagle Talon"; $resouter = mysql_query($query, $dbconnect); $inner_table = 'ost_media'; $query = "SELECT * FROM $inner_table WHERE media_access='private'"; $resinner = mysql_query($query, $dbconnect); $dom = new DomDocument('1.0','utf-8'); $root = $dom->createElement('featureset'); $root = $dom->appendChild($root); $row = @mysql_fetch_assoc($resouter); // process all rows of the inner/many/child table while ($row = @mysql_fetch_assoc($resinner)) { // add node for each record $outer = $dom->createElement('album'); $outer = $root->appendChild($outer); $outer->setAttribute('name', 'Shock Value'); $outer->setAttribute('author', 'Timbaland'); $outer->setAttribute('imageUrl', 'images/Timbaland/image.jpg'); $outer->setAttribute('link', 'http://flabell.com/'); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $inner = $dom->createElement('song'); $inner = $outer->appendChild($inner); $inner->setAttribute('name', 'name'); $inner->setAttribute('duration', '3:15'); $inner->setAttribute('buy', 'false'); $inner->setAttribute('download', 'true'); $inner->setAttribute('downloadsource', 'download/song1.mp3'); $value = $dom->createTextNode('songs/song1.mp3'); $value = $inner->appendChild($value); } // foreach } // while // get completed xml document $xml_string = $dom->saveXML(); echo $xml_string; ?> and here is what is outputs <featureset> − <album name="Shock Value" author="Timbaland" imageUrl="images/Timbaland/image.jpg" link="http://flabell.com/"> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> <song name="name" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song> </album> </featureset> What the probelm is that is is creating a new song row for every column there is in the table, What i need it do do is only create a song row if it matches a certain element, can anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/ Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 What are you trying to match it to? Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814686 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 What are you trying to match it to? well the foreach is looking at $row which is a mysql that is looking for a title in a table called "1997 Eagle Talon" And i want that foreach to stop when i matchs that title, However i do think my foreach statement is off. I have tried foreach ($row = $value) $value = '1997 Eagle talon'; but i get errors left and right including a DOM exception Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814701 Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 A brief look over this suggests that you should probably be doing the record selection in the SQL (which you nearly are I think). You've got two queries, querying the same table. What is the inner query for? Looks as though if you just used the outer query everything would work fine. Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814703 Share on other sites More sharing options...
mrMarcus Posted April 20, 2009 Share Posted April 20, 2009 this has a syntax error in it .. do you have error_reporting on? $query = "SELECT * FROM ost_media WHERE media_title='1997 Eagle Talon"; missing an ending ' after 1997 Eagle Talon Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814705 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 A brief look over this suggests that you should probably be doing the record selection in the SQL (which you nearly are I think). You've got two queries, querying the same table. What is the inner query for? Looks as though if you just used the outer query everything would work fine. The inner table is actually for the album selction so if i want more then one album level I change it using that mysql call. Then the outer is to select the songs orignally i wrote it wron so i know they are switched around Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814716 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 this has a syntax error in it .. do you have error_reporting on? $query = "SELECT * FROM ost_media WHERE media_title='1997 Eagle Talon"; missing an ending ' after 1997 Eagle Talon Totally missed that one and i guess i dont becuase i didnt pull any error in dw or log. But I did change that and it didnt make a difference it is still pulling every column Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814720 Share on other sites More sharing options...
soak Posted April 20, 2009 Share Posted April 20, 2009 Looks as though if you just used the outer query everything would work fine. Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814727 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 Looks as though if you just used the outer query everything would work fine. Not sure what you mean by this the while statement uses the resinner query to create the levels at albumn So right now i have the query set to private which i have entry however if i set it to public where i have over 100 entry then 100 levels of album are created. My problem is that i need the songs inside the album to only show if the are equal to a certain element, Currently the songs that are showing is becuase the foreach statement is creating a song for each column that is in the table ost_media. What I am trying to get it to do is call the query outer where the query is set to media_title "1997 Eagle Talon". There are two of these values with in the column within the table hence 2 songs should show not 22. And I did change the it to outer and that doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814736 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 No other suggestions??? Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814808 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 Why not just select that/them record(s) then, rather than sifting through every record? Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814813 Share on other sites More sharing options...
AE117 Posted April 20, 2009 Author Share Posted April 20, 2009 Why not just select that/them record(s) then, rather than sifting through every record? not sure what you mean by that one jack can you elaborate?? Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814837 Share on other sites More sharing options...
jackpf Posted April 20, 2009 Share Posted April 20, 2009 I'm confusing myself actually...Idk. Ignore me. Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-814972 Share on other sites More sharing options...
AE117 Posted April 21, 2009 Author Share Posted April 21, 2009 Just to let those who want to know what I did to solve this is i changed the foreach into a for Then it was able to stop now i Have a new problem which is under another topic to Ill post this as solved Quote Link to comment https://forums.phpfreaks.com/topic/154893-solved-foreach-statement-wont-stop/#findComment-815181 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.