Teonynn Posted June 22, 2008 Share Posted June 22, 2008 I've been working on a three-layer program that combines PHP/XML, mySQL, and a Flash display. Now, I have it linked to a database using mySQL, and I've gotten the PHP script to read the mySQL database contents and display them as XML. This is the problem I'm facing... I need to format it so that Flash will be able to pick a single line in the "XML file" and read it into a variable to display. Currently, it looks like this: 2008A-200 200 In the Office off The code to display it is this: <?PHP $link = mysql_connect("localhost","********","*********"); mysql_select_db("*********"); $query = 'SELECT type FROM fla_banner'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<types>\n"; while($line = mysql_fetch_assoc($results)) { echo "<types>" . $line["type"] . "</item>\n"; } echo "</types> \n"; mysql_close($link); ?> How can I get it to either read from a single row/collum and display a single variable at a time, OR format it so Flash can read it as variables? Apache version 1.3.39 (Unix) PHP version 5.2.5 MySQL version 5.0.45-community Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 I would use a counter... Quote Link to comment Share on other sites More sharing options...
Teonynn Posted June 22, 2008 Author Share Posted June 22, 2008 "use a counter?" ??? Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 I need to format it so that Flash will be able to pick a single line in the "XML file" and read it into a variable to display. I assumed that you know which line that you want to pick out, if you put in a counter, then you will be able to pull out which line and variable on upon request. Quote Link to comment Share on other sites More sharing options...
Teonynn Posted June 22, 2008 Author Share Posted June 22, 2008 How do I use counters? Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 <?PHP $link = mysql_connect("localhost","********","*********"); mysql_select_db("*********"); $query = 'SELECT type FROM fla_banner'; $results = mysql_query($query); echo "<?xml version=\"1.0\"?>\n"; echo "<types>\n"; $counter = 0; while($line = mysql_fetch_assoc($results)) { $counter++; echo "<item>" . $line["type"] . "</item>\n"; echo "<lineno>" . $counter . "</lineno>\n"; } echo "</types> \n"; mysql_close($link); // echo out your lineno that you want... ?> It just really depends on at what point you want to pull the line and column, during the xml creation or after... Quote Link to comment Share on other sites More sharing options...
Teonynn Posted June 22, 2008 Author Share Posted June 22, 2008 So you use "counter" to compare to the UID of the row and if it matches..? Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 Yeah, I mean by adding the counter and the lineno field to the xml file, you can pull exactly which line you want... then pulling out the variable is easy once you know the line... Quote Link to comment Share on other sites More sharing options...
Teonynn Posted June 22, 2008 Author Share Posted June 22, 2008 So once you have chosen the row, have the XML "file" read that row out individually. Okay, I added your changes and it now reads like this: 2008A-200 1 200 2 In the Office 3 off 4 How do I format the XML file so it reads vertically instead of horizontally? Quote Link to comment Share on other sites More sharing options...
webent Posted June 22, 2008 Share Posted June 22, 2008 Let's see your xml parser code that you have so far... I'm going to have to go to bed for the night, hopefully someone else can help pick up with either this idea or a different one or I can check it out tomorrow... Quote Link to comment Share on other sites More sharing options...
Teonynn Posted June 22, 2008 Author Share Posted June 22, 2008 echo "<?xml version=\"1.0\"?>\n"; echo "<types>\n"; $counter = 0; while($line = mysql_fetch_assoc($results)) { $counter++; echo "<lineno>" .$counter . "</lineno>\n"; echo "<item>" . $line["type"] . "</item>\n"; } echo "</types> \n"; Small note: Switched the $counter line to fall before the "type" line, so it now reads "1 2008A-200 2 200 3 In the Office 4 off" Quote Link to comment Share on other sites More sharing options...
fenway Posted June 22, 2008 Share Posted June 22, 2008 This isn't a mysql question. Quote Link to comment 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.