-
[F8] WebBible (reading PHP-mySQL)
Hi,
I am trying to make a bible program in flash 8. I can connect fine and read the database fine.
Here are my questions.
I want to be able to get a text var from the tree control (no problem there) then send it to my PHP file and have my SELECT find the record.
I have tested it hard coding the values, so i know the connection and data can be gotten.
How do I do that?
Here is my code to start with that works.
PHP Code:
$query = 'SELECT BibRead FROM Bible WHERE BibRead = "Genesis 1"';
$results = mysql_query($query);
echo "<?xml version=\"1.0\"?>\n";
echo "<bible>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["BibRead"] . "</item>\n";
}
echo "</bible>\n";
Here is my Flash Code
Code:
on(release){
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
theXML.load("http://bible.word-spirit.org/test.php");
}
Again... I want to send the text (book/chapter) to the PHP file and retreive each scripture that falls under that variable.
Thanks
-
Do you think I am doing this the most efficent way?
In my example I am using PHP to create an XML then load it in a list box.
What I really want to do is, Load my scriptures in the TextArea control formatted with html like thus.. "1 In the beginning..."
I also want my scriptures to use <BR> so there are no extra lines inbetween lines.
What do you think?
-
After working with my PHP and AS, I know the PHP is working.
However I can not seem to pass the variable I want to the PHP file.
Here is my AS (on button)
Code:
on(release){
var my_br:LoadVars = new LoadVars();
my_br.br = "Genesis 5";
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.sendAndLoad("http://bible.word-spirit.org/test.php",br,"POST");
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
}
Am I using the sendAndLoad correctly on an XMl load??
-
Any help would be appreciated
-
FK'n_dog
not tested here, but the logic appears sound -
PHP Code:
var my_br:LoadVars = new LoadVars();
my_br.br = "Genesis 5";
my_br.sendAndLoad("http://bible.word-spirit.org/test.php",my_br,"POST");
my_br.onLoad = function() {
var str:String = unescape(this);
var theXML:XML = new XML(str);
theXML.ignoreWhite = true;
// loop thro' the nodes
}
does this work for you ?
-
Well... it kinda of works... weirdly
When you click the 1st button nothing happens. But then, click the 2nd button, it works. The 1st button sends the var "Genesis 5" to the PHP, but doesn't finish up with the XML. The 2nd button runs the plain old XMl, but is getting the var "Genesis 5" that was sent by the 1st button.
So, it seems the PHP is getting the var, but my AS in the 1st button isn't working.
See this link...
http://bible.word-spirit.org/test.html
The first button is the one I am trying to send variable to the PHP.
The second button is kust plain old Load on an XML object.
Code for PHP:
PHP Code:
<?PHP
$link = mysql_connect("****","****","****");
mysql_select_db("****");
$brStr = $_POST['br'];
$query = "SELECT BibRead, Verse, Scripture FROM Bible WHERE BibRead = '$brStr'";
$results = mysql_query($query);
echo "<?xml version=\"1.0\"?>\n";
echo "<bible>\n";
while($line = mysql_fetch_assoc($results)) {
echo "<item>" . $line["Verse"] . " " . $line[Scripture] . "</item>\n";
}
echo "</bible>\n";
mysql_close($link);
?>
BUTTON ONE (sendAndLoad)
Code:
on(release){
var my_br:LoadVars = new LoadVars();
my_br.br = "Genesis 5";
my_br.sendAndLoad("http://bible.word-spirit.org/test.php",my_br,"POST");
my_br.onLoad = function() {
var str:String = unescape(this);
var theXML:XML = new XML(str);
theXML.ignoreWhite = true;
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
}
BUTTON TWO (Load)
Code:
on(release){
var theXML:XML = new XML();
theXML.ignoreWhite = true;
theXML.load("http://bible.word-spirit.org/test.php");
theXML.onLoad = function() {
var nodes = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++) {
theList.addItem(nodes[i].firstChild.nodeValue,i);
}
}
}
What do you think?
-
FK'n_dog
i looked at an array split method with some success -
PHP Code:
function find_br(BR){
theList.removeAll();
var my_br:LoadVars = new LoadVars();
my_br.br = BR;
my_br.sendAndLoad("http://bible.word-spirit.org/test.php",my_br,"POST");
my_br.onLoad = function(){
arr = unescape(this).split("&onLoad");
arr.pop();
arr[0] = arr[0].split("\n<item>");
len = arr[0].length;
for(var n=0;n!=len;n++){
arr[0][n] = arr[0][n].split("</item>");
}
arr[0][0].pop();
for(i=1;i<len;i++) {
trace("arr[0]["+i+"][0] - "+arr[0][i][0])
theList.addItem(arr[0][i][0],i);
}
};
};
btn_find.onRelease = function(){ find_br(inp.text) }; // input textfield
find_br("Genesis 1"); // initiate
if you edit your php, this will simplify the above
-
ModDog... I will give it a try.
FYI... In my Flash Bible App, I want to use the TextArea to display complete chapters. And I am going to have another window that will use a search function that will list in the ListBox.
Here is what I did in ASP.NET. I want to convert the same idea to Flash.
http://webbible.ourwebzone.com/
The array syntax seams to do away with XML(?)... which is fine by me.
Will I be able to adapt your suggestion for both controls?
Last edited by FHilton; 02-01-2008 at 07:33 PM.
-
Works perfectly!!
See it... http://bible.word-spirit.org/test.html
But it seems to complex for a simple query. Why can't we use the simpler form of XML to load the PHP output?
Now....
I need to convert it so I can load it into a TextArea control that will format the text to html.
Example output...
1 In the beginning...
2 And the earth was without...
Will this be a problem?
Thanks for your help Mod_Dog!
-
Okay...
1) I got the search to work with the listbox. I am using the sql statement LIKE to do the search. Works! (of course I need to refine this for hackers and a progress display when a search is taking place)
2) Now... I need to convert above code to load into a TextArea instead of the Listbox... here is my code.... doesn't look right in the TextArea control though.
PHP Code:
function find_br(BR){
txtArea.text = "";
var my_br:LoadVars = new LoadVars();
my_br.br = BR;
my_br.sendAndLoad("http://bible.word-spirit.org/test.php",my_br,"POST");
my_br.onLoad = function(){
arr = unescape(this).split("&onLoad");
arr.pop();
arr[0] = arr[0].split("\n<item>");
len = arr[0].length;
for(var n=0;n!=len;n++){
arr[0][n] = arr[0][n].split("</item>");
}
arr[0][0].pop(my_br);
//for(i=1;i<len;i++) {
//trace("arr[0]["+i+"][0] - "+arr[0][i][0])
//theList.addItem(arr[0][i][0],i);
//}
txtArea.text = arr;
};
};
I want my text to be html formated with bold verse numbers as stated above.
The text in the textArea doesn't look quite right.
http://bible.word-spirit.org/test.html
Last edited by FHilton; 02-01-2008 at 09:28 PM.
-
Okay...
I got the bold formating to work and I added the <BR> to the PHP code for the line breaks.
Now... why do I have commas at the start of each verse? Those are not in the database.
-
Yea!!!! I got it!
I had to remove the "\n" at the end of the </item> line in my AS.
Here is the finished AS.
PHP Code:
function find_br(BR){
txtArea.text = "";
//theList.removeAll();
var my_br:LoadVars = new LoadVars();
my_br.br = BR;
my_br.sendAndLoad("http://bible.word-spirit.org/test.php",my_br,"POST");
my_br.onLoad = function(){
arr = unescape(this).split("&onLoad");
arr.pop();
arr[0] = arr[0].split("\n<item>");
len = arr[0].length;
for(var n=0;n!=len;n++){
arr[0][n] = arr[0][n].split("</item>\n");
}
txtArea.text = arr;
};
};
Thanks Mod_Dog... I think I can move forward now.
Last edited by FHilton; 02-01-2008 at 10:06 PM.
-
Next....
How do I prevent people from running SQL injections in my search input box so they do not mess up my database?
Here is my search syntax in my PHP
PHP Code:
$query = "SELECT BibRead, Verse, Scripture FROM Bible WHERE Scripture LIKE '%$srchStr%'";
Last edited by FHilton; 02-01-2008 at 10:30 PM.
-
I put some input box validation. Hopefully that will help in minimising SQl Injections.
-
Here is a link to the live production copy.
http://bible.word-spirit.org/
However... I haven't put the search functions in yet. Just wanted to get it going and see what everyone thinks.
-
When you click on folders - it says loading, so we think it does, and it looks like a bug. Clicking on a folder should do exactly what the arrow does: toggle open/close. appart from that seems to work well and fast.
gparis
-
Originally Posted by gparis
When you click on folders - it says loading, so we think it does, and it looks like a bug. Clicking on a folder should do exactly what the arrow does: toggle open/close. appart from that seems to work well and fast.
gparis
Yep.... I see what you are talking about. I will fix it.
Thanks
-
Is there a "complete" (when done loading) listener for the TextArea like there is for the scrollpane??
I want to use my progbar to display then disapear when the TA is done loading.
-
I don't think there is a "complete" listener.
However, I was able to fix the progbar to display correctly now.
-
Okay...
I have added the search function now.
Can ya all let me know of any bugs??
I am noticing one problem.
If you type the word "and" in the search box.... it takes for ever.
What C=can I do about common words?
See updated version here
http://bible.word-spirit.org/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|