Closed Thread Icon

Topic awaiting preservation: setting array (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12338" title="Pages that link to Topic awaiting preservation: setting array (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: setting array <span class="small">(Page 1 of 1)</span>\

 
Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 07-30-2002 23:13

Ok, I'm not much on programming so I'm a little confused here.
Have a php script that builds arrays to generate xml to be displayed in Flash.
I got ahead of myself and threw in the databse connection and bogus arrays!~LOL
The original script built arrays manually like
$NameArr = array("This is story number1","this is story numbers","and so on");
How do I properly get the NameArr, DataArr, & TDate

It's a simple database that holds personal entries. 4 fields (id[int], title[text], story[text], date[datetime]

This is what I did, please don't laugh!~LOL

// connect $db = mysql_connect("myhost", "user", "pass");

mysql_select_db("mydb",$db);
// Select rows
$sql = "SELECT * FROM citynews order by id DESC LIMIT 5";
$result = mysql_query($sql,$db);
$row = mysql_fetch_array($result);
$title = $row["title"];
$story = $row["story"];
$date = $row["date"];


$TextColor = "0x000066";
$BGColor = "0x990000";
$NameArr = array("$title");
$DataArr = array("$story");
$tDate = array("$date");


$numReturn = count($NameArr);
$i = 0;

// Prints out the necessary XML
print "<dataSet>";
while ($i < $numReturn) {
print "<data>";
print "<name>".$NameArr[$i]."</name>";
print "<dataRow>".$DataArr[$i]."</dataRow>";
print "<textColor>".$TextColor."</textColor>";
print "<BGColor>".$BGColor."</BGColor>";
print "<tDate>".$tDate[$i]."</tDate>";
print "</data>";
$i++;
}
print "</dataSet>";

~Peace~
Gary
City Style Creations

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-30-2002 23:33

Little hazy on the question here but I think I got it.

What you want to use is the array_push function. which will add items on to the end of an array. So then what you could do is for each record in the result you go (for example) array_push($NameArr, $title) and that will add $title to the end of $NameArr.

Of course you really don't need to be creating all them thar array's anyway PHP already did it for you with the mysql_fetch_array func. Here's a simpler way to do it with one loop.


code:
$db = mysql_connect("myhost", "user", "pass"); 
mysql_select_db("mydb",$db);
$sql = "SELECT * FROM citynews order by id DESC LIMIT 5";
$result = mysql_query($sql,$db);
// Okay same thing through here.

// These are constants so as Ron says we'll just set 'em and forget 'em.
$TextColor = "0x000066";
$BGColor = "0x990000";

// Array?!? We don't need no stinking arrays!
print "<dataSet>";
// One loop that does it all for us.
// (for good looks I'd add "\n" line breaks after these but that's up to you)
while($row = mysql_fetch_array($result)) {
print "<data>";
print "<name>".$row["title"]."</name>";
print "<dataRow>".row["story"]."</dataRow>";
print "<textColor>".$TextColor."</textColor>";
print "<BGColor>".$BGColor."</BGColor>";
print "<tDate>".$row["date"]."</tDate>";
print "</data>";
}
print "</dataSet>";





.:[ Never resist a perfect moment ]:.

[This message has been edited by bitdamaged (edited 07-30-2002).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-30-2002 23:40

Gynot: I've done this a couple of times now and the solution is different each time but try loading the data into an array and then processing - your requirements look fairly straightforward so try something like this:

code:
<?php

header("Content-Type: text/xml");

$text_color = "0x000066";
$bg_color = "0x990000";

// connect $db = mysql_connect("myhost", "user", "pass");

mysql_select_db("mydb",$db);
// Select rows
$sql = "SELECT * FROM citynews order by id DESC LIMIT 5";
$result = mysql_query($sql,$db);

$person_count = 0;

while ($row = mysql_fetch_array($result)) {

$person_array[$person_count]['title'] = $row['title'];
$person_array[$person_count]['story'] = $row['story'];
$person_array[$person_count]['date'] = $row['date'];

$person_count++;

}

$output .= '<dataset>';

for ($i = 0; $i < sizeof($person_array); $i++) {

$current_name = $person_array[$i]['title'];
$current_story = $person_array[$i]['story'];
$current_date = $person_array[$i]['date'];

$output .= '<data $name=\"$current_name\" story=\"$current_story\" textcolor=\"text_color\" bgcolor=\"bg_color \" date=\"$current_date\">';

}

$output .= '</dataset>';

echo $output;

?>



Its slightly 'verbose' but that should help make clear what is going on.

[edit: Yes my example is more complex than is needed for this and bitdamaged's looks more compact - I would do as I've done and have the data stored as attributes as it makes Flash happier ]

___________________
Emps

FAQs: Emperor

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 07-31-2002 00:40

I'm seriously lost here. I've tried both of your methods and neither is working.

If it helps, here is the action script that's in the Flash movie.

/* Incoming data is in the form
<dataSet>
<data>
<name></name>
<dataRow></dataRow>
</data>
</dataSet>

*/
function convertXML () {
mainTag = new XML();
elementTag = new XML();
dataList = new Array();
elementList = new Array();
mainTag = this.firstChild;
if (dataXML.loaded) {
if (mainTag.nodeName == "dataSet") {
dataList = mainTag.childNodes;
for (i=0; i<=dataList.length; i++) {
if (dataList[i].nodeName == "data") {
elementList = dataList[i].childNodes;
for (j=0; j<=elementList.length; j++) {
elementTag = elementList[j];
elementType = elementTag.nodeName;
if (elementType == "name") {
Name = elementTag.firstChild.nodeValue;
}
if (elementType == "dataRow") {
Info = elementTag.firstChild.nodeValue;
}
if (elementType == "textColor") {
textTColor = elementTag.firstChild.nodeValue;
}
if (elementType == "BGColor") {
BGColor = elementTag.firstChild.nodeValue;
}
if (elementType == "tDate") {
tDate = elementTag.firstChild.nodeValue;
}
}
// Adds new Data Provider Object to Ticker
var TickerData = { text:Name, info:Info, tickerDate:tDate, textColor:textTColor, background:true, backgroundColor:BGColor, underline:true };
Ticker.addItem(TickerData);
}
}
}
}
}
// Sets the change handler for the Ticker - this passes the Ticker index and sets the click handler.
Ticker.setClickHandler("SelectItem");

function SelectItem(Ticker, index) {
DataBox = Ticker.getItemAt(index).info;
tickerDate = Ticker.getItemAt(index).tickerDate;
}


=====================================================================
And here is the way the php was originally written before I tried going dynamic. This works fine

<?php
// This array would normally be coming from a database - ie MySQL, MS SQL, Oracle
// We just simplified it by putting it in an Array for now.

$TextColor = "0x000066";
$BGColor = "0x990000";
$NameArr = array("Added New Section", "Site Launched", "Site Contruction","Project Awarded","Looking for Project");
$DataArr = array("The Newest section called comTech was added to the main site.", "The new site was just launched", "Site started construction today", "The project was awarded to ABC Dezine to start asap.","ABC Dezine is looking for a new Project.");
$tDate = array("6/22/02","5/30/02","4/23/02","3/14/02","2/12/02");


$numReturn = count($NameArr);
$i = 0;

// Prints out the necessary XML
print "<dataSet>";
while ($i < $numReturn) {
print "<data>";
print "<name>".$NameArr[$i]."</name>";
print "<dataRow>".$DataArr[$i]."</dataRow>";
print "<textColor>".$TextColor."</textColor>";
print "<BGColor>".$BGColor."</BGColor>";
print "<tDate>".$tDate[$i]."</tDate>";
print "</data>";
$i++;
}
print "</dataSet>";
?>

Sorry to clutter up with all this code, just afraid if I leave a bit out, that will be the part you needed to see.
Told you I was lost here!~LOL

~Peace~
Gary
City Style Creations

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 07-31-2002 00:58

Have you looked at the XML file output by your script and the one I did for any differences?

Can you post the two?



.:[ Never resist a perfect moment ]:.

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 07-31-2002 01:13

It doesn't create an XML file, it picks it up in Flash, with this actionscript

dataXML = new XML();
dataXML.onLoad = convertXML;

// Just change this to your file that generates or contains the XML your going to use.
// Make sure to change the real path to the file
dataXML.load("Ticker_XML_News.php");

And the actionscript posted above, that's all there is.
here's the complete zip file as I got it, not set dynamically as far as link values.

http://citystylecreations.com/v4/Ticker_XML_News.zip
Again, just want to make the NameArr, DataArr, & TDate pick up the values of the fields: title, story, & date, and show 5 at a time in the flash

~Peace~
Gary
City Style Creations

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-31-2002 01:24

Gynot: I think what bd meant was can you see the XML generated by the PHP script when you go to the page generating it? If you can the problem is with the Flash if you can't then the problem is with the PHP.

___________________
Emps

FAQs: Emperor

Gynot
Bipolar (III) Inmate

From: Brooklyn, NY
Insane since: Jan 2002

posted posted 07-31-2002 01:41

Ok, it's working, I used bitmaps method. http://citystylecreations.com/v4/news.php
Just BS test data, I need to redesign and add actual content to database.
Just working on a new look and really wanted a compact way to present my newest ramblings

If I tell you where I went wrong on his method, you'll laugh me out of the group and never answer me again!~LOL
OK, I'll tell.............. I mispelled my server name!~LOL

Now that I got that working, I'm going to take a closer look at Emporers method as well

Thank you all, sorry for being a putz!~LOL

~Peace~
Gary
City Style Creations

« BackwardsOnwards »

Show Forum Drop Down Menu