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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.