kev wood Posted October 20, 2008 Share Posted October 20, 2008 i am trying to pull rows from my mysql table and insert these into a an array so i can then out the array results into a formatted XML sheet. i have been able to pull data from the table and format it into xml with the following code. <?php //---------------------------------ENTER YOUR DATABASE DETAILS HERE(IF NOT SURE ASK YOUR HOST FOR THE DETAILS-------------// //mysql details $link = mysql_connect("localhost", "flashtest", "flash") or die("Could not connect to host."); mysql_select_db("flashtestdb") or die("Could not connect to host."); //get entries from guestbook $query = "SELECT (atricle) FROM articles"; $results = mysql_query($query); //generate the xml file echo "<?xml version = \"1.0\"?>\n"; echo "<!DOCTYPE chapter PUBLIC dtd>\n"; echo "<articles>\n"; while($line=mysql_fetch_assoc($results)) { echo "<news>".$line["article"]."</news>\n"; } #now lets end the xml file echo "</articles>\n"; ?> as you can see from this code though it only queries on column from the table. i want to now select the other columns and put them into the formatted xml sheet. from what i have been looking at i think i need to use the fetchrow_array command in mysql to accomplish this. i have never used this command before though and i keep getting errors. the code which i have produced so far is as follows but it is not doing as i would like. <?php //---------------------------------ENTER YOUR DATABASE DETAILS HERE(IF NOT SURE ASK YOUR HOST FOR THE DETAILS-------------// //mysql details $link = mysql_connect("localhost", "flashtest", "flash") or die("Could not connect to host."); mysql_select_db("flashtestdb") or die("Could not connect to host."); //get entries from guestbook $query = "SELECT (date, title, atricle) FROM articles"; $results = mysql_query($query); //generate the xml file echo "<?xml version = \"1.0\"?>\n"; echo "<!DOCTYPE chapter PUBLIC dtd>\n"; echo "<articles>\n"; while($line=fetchrow_array($results)) { echo "<date>".$line["date"]."</date>\n"; echo "<title>".$line["title"]."</title>\n"; echo "<news>".$line["article"]."</news>\n"; } #now lets end the xml file echo "</articles>\n"; ?> any help with this would be great. Quote Link to comment https://forums.phpfreaks.com/topic/129247-solved-fetchrow_array/ Share on other sites More sharing options...
Maq Posted October 20, 2008 Share Posted October 20, 2008 What's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/129247-solved-fetchrow_array/#findComment-670057 Share on other sites More sharing options...
kev wood Posted October 20, 2008 Author Share Posted October 20, 2008 i have sorted the problem out now here is the code i have produced <?php //---------------------------------ENTER YOUR DATABASE DETAILS HERE(IF NOT SURE ASK YOUR HOST FOR THE DETAILS-------------// //mysql details $link = mysql_connect(localhost, xxxxx, xxxxxx) or die("Could not connect to host."); mysql_select_db(xxxxxxxx) or die("Could not find database."); $query = "SELECT * FROM articles"; $result = mysql_query($query, $link) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<entries>\n"; for($x = 0 ; $x < mysql_num_rows($result) ; $x++) { $row = mysql_fetch_assoc($result); $xml_output .= "\t\t<date>" . $row['date'] . "</date>\n"; $xml_output .= "\t\t<title>" . $row['title'] . "</title>\n"; $xml_output .= "\t\t<article>" . $row['article'] . "</article>\n"; } $xml_output .= "</entries>"; echo $xml_output; ?> this code formats all the mysql queries into a formatted xml sheet the flash can read and display. Quote Link to comment https://forums.phpfreaks.com/topic/129247-solved-fetchrow_array/#findComment-670125 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.