Jump to content

Selecting only a single row AND single collum


Teonynn

Recommended Posts

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

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.

<?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...

 

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?

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"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.