A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 33

Thread: [F8] WebBible (reading PHP-mySQL)

  1. #1
    Senior Member
    Join Date
    Sep 2003
    Posts
    356

    [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

  2. #2
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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?


  3. #3
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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??


  4. #4
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Any help would be appreciated


  5. #5
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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 ?

  6. #6
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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?

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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

  8. #8
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.

  9. #9
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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!

  10. #10
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.

  11. #11
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.


  12. #12
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.

  13. #13
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.

  14. #14
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    I put some input box validation. Hopefully that will help in minimising SQl Injections.


  15. #15
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.


  16. #16
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    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

  17. #17
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    Quote 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

  18. #18
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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.


  19. #19
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    I don't think there is a "complete" listener.

    However, I was able to fix the progbar to display correctly now.


  20. #20
    Senior Member
    Join Date
    Sep 2003
    Posts
    356
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center