Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question One more PHP query to java array problem...

    Ok, let's look at my check list:
    SQL programming ability: Super-duper
    HTML ability: Not too bad
    PHP ability: just barely fair
    Java ability: Don't Ask!

    So, I have this PHP query:
    Code:
    <?php
    include '../config.php';
    include '../opendb.php';
    $query = 'select identity,headline,article,hyperlink,linktxt from scroller where StartDate <= date_format(now(),\'%Y-%m-%d\') and EndDate >= date_format(now(),\'%Y-%m-%d\') ORDER BY identity ASC'; 
    $result=mysql_query($query) OR die();
    $num_rows = (mysql_num_rows($result)-1);
    $i = 0;
    ?>
    And this java array:
    Code:
    <script type="text/javascript">
    
    /*Example message arrays for the two demo scrollers*/
    
    var pausecontent=new Array()
    <<<HOW THE HECK DO I GET MY QUERY INTO THIS FIRST ARRAY???>>>
    
    var pausecontent2=new Array()
    pausecontent2[0]='<b>Welcome to Chung Ma'+"'"+'s Taekwondo Institute</b>- Recreational and Olympic Style Taekwondo. Excellent fitness for any age or ability.'
    pausecontent2[1]='<b>Check out the News Wire Scroller</b>- Located on the lower left of every page. Current events, Important dates, and all the Chung Ma'+"'"+'s News that'+"'"+'s fit to print.'
    pausecontent2[2]='<b>Self Defense, Fitness and Competitive Sparring</b> - Excellent self defense training along with quality workouts and the availability of competitive sparring make Chung Ma'+"'"+'s Taekwondo an outstanding choice for the entire family!'
    pausecontent2[3]='<b>The Forum is up and running!</b>- Check it out by clicking on '+"'"+'The Forum'+"'"+' button!'
    pausecontent2[4]='<b>Chung Ma'+"'"+'s Taekwondo 11th Annual Championship Tournament</b> - Saturday, November 11, 2006... See the <a href="events.htm"><u><font color=##0066CC>events page</a></u></font> for more info or download your registration packet by clicking here:<a href="downloads/2006tourny.pdf"><u><font color=#0066CC>Tournament Registration</a></u></font>'
    pausecontent2[5]='<br><center><A HREF="http://www.bluedomino.com/join/index.bml?AffID=562714&LinkName=blue domino graphic link"><IMG SRC="http://www.bluedomino.com/affiliate/banners/147" border="0"></A></center><br><br>'
    pausecontent2[6]='<b>World Class training that'+"'"+'s not a world away</b>- Conveniently located in Kingston NY and Mahopac NY '
    pausecontent2[7]='<b>Questions or Comments?</b>- Feel free to <a href="contact_us.htm"><u><font color=##0066CC>contact us</a></u></font> any time!'
    
    </script>
    The java script resides on an html page; I would like to put the PHP code in a page that I can call from several pages, and then have that query returned in the first java array, but it could go in each page if need be. I have looked all over this site and the web, and have seen what I THINK are some proper examples, but I am lost. Absolutely NO idea how to do this! Can someone please give me some guidance? The second array has the same format of the data that I want in the first array. The text between the <b></b> tags would be the headline, then the article. hyperlink is the href link in each row and linktext is the href text to show.
    WAAAAHHH!!! I need a beer....
    (Management+Coworkers)<>Logic

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I'm assuming you mean Javascript, not Java? They are two entirely different languages.

    You can put all the PHP into a file and then use include() in the pages you want to run the query.

    To build a Javascript array using PHP, simply echo the Javascript syntax from PHP, and use the variables from your query.

    PHP Code:
    for ($i 0$i mysql_num_rows($result); $i++ ) {
        
    $headlineData mysql_fetch_assoc($result);

        print 
    "pausecontent[$i]='<b>{$headlineData['headline']}</b>{$headlineData['linktxt']}';\n";


  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Fumigator,
    Yeah, Javascript. I keep forgetting to put the whole word in there (damned lazy hands!)...
    I kinda figured there was a simple answer to this, but I really am one green toad when it comes to PHP and Javascript (Hah! nailed it!). I'll give this a shot and let you know how I make out. You get a thumbs up rate for this!
    Andy
    (Management+Coworkers)<>Logic

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I'm close, but not quite, there...
    Here is the code for my PHP array page:
    Code:
    <?php
    // Connecting, selecting database
    $link = mysql_connect('xxxxxxxx', 'xxxxxxx', 'xxxxxxx')
       or die('Could not connect: ' . mysql_error());
    
    mysql_select_db('scroller') or die('Could not select database');
    
    // Performing SQL query
    $query = 'select identity,headline,article from scroller where StartDate <= date_format(now(),\'%Y-%m-%d\') and EndDate >= date_format(now(),\'%Y-%m-%d\') ORDER BY identity ASC';$result = mysql_query($query) or die('Query failed: ' . mysql_error());
    
    for ($i = 0; $i < mysql_num_rows($result); $i++ ) { 
        $headlineData = mysql_fetch_assoc($result); 
    
        print "pausecontent[$i]='<b>{$headlineData['headline']}</b>{$headlineData['linktxt']}';\n"; 
    }
    ?>
    If I preview this (quote.php is the page name) it returns a page with the array data correctly formatted. I'm still stuck as to how I would call this in the javascript:
    Code:
    var pausecontent=new Array()
    SYNTAX FOR include(./quote.php) GOES HERE
    I will keep plodding away at it, learning all the while...
    (Management+Coworkers)<>Logic

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You can't call a PHP function within Javascript code. You have to separate the two languages out in your mind. When someone requests your page, the browser sends the request to your server. PHP intercepts the request and parses the entire file. The web server then sends the file to the browser. The browser then builds the page, and runs any Javascript that's found. At this point, it's impossible to make a call to a PHP function-- the file has been parsed and spit out long ago.

    So what you're doing is you're imbedding a PHP print command inside the code within <script> tags, and building Javascript code using PHP. When the browser runs the Javascript, it has no idea how the code got there, but you know PHP built it, and it runs just as if someone coded it by hand.

    Maybe I over-explained just now... but it simply means you stick the PHP code that prints the Javascript stuff inside <script> tags.

    PHP Code:
    <script type="text/Javascript">
    //this is the Javascript code area
    var pausecontent=new Array();
    <?php
    //imbed PHP code here to build the Javascript code
    include ("./quote.php");
    ?>
    </script>

  • #6
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok, I think I see where you're going. Take a look:
    Here is the current code for the array script in my HTML page:
    Code:
    <script type="text/javascript">
    
    
    var pausecontent=new Array()
    
    pausecontent[0]='<b>Welcome to Chung Ma'+"'"+'s Taekwondo Institute</b>- Recreational and Olympic Style Taekwondo. Excellent fitness for any age or ability.'
    pausecontent[1]='<b>Check out the News Wire Scroller</b>- Located on the lower left of every page. Current events, Important dates, and all the Chung Ma'+"'"+'s News that'+"'"+'s fit to print.'
    pausecontent[2]='<b>Self Defense, Fitness and Competitive Sparring</b> - Excellent self defense training along with quality workouts and the availability of competitive sparring make Chung Ma'+"'"+'s Taekwondo an outstanding choice for the entire family!'
    pausecontent[3]='<b>The Forum is up and running!</b>- Check it out by clicking on '+"'"+'The Forum'+"'"+' button!'
    pausecontent[4]='<b>Chung Ma'+"'"+'s Taekwondo 11th Annual Championship Tournament</b> - Saturday, November 11, 2006... See the <a href="events.htm"><u><font color=##0066CC>events page</a></u></font> for more info or download your registration packet by clicking here:<a href="downloads/2006tourny.pdf"><u><font color=#0066CC>Tournament Registration</a></u></font>'
    pausecontent[5]='<br><center><A HREF="http://www.bluedomino.com/join/index.bml?AffID=562714&LinkName=blue domino graphic link"><IMG SRC="http://www.bluedomino.com/affiliate/banners/147" border="0"></A></center><br><br>'
    pausecontent[6]='<b>World Class training that'+"'"+'s not a world away</b>- Conveniently located in Kingston NY and Mahopac NY '
    pausecontent[7]='<b>Questions or Comments?</b>- Feel free to <a href="contact_us.htm"><u><font color=##0066CC>contact us</a></u></font> any time!'
    
    
    var pausecontent2=new Array()
    pausecontent2[0]='<a href="http://www.usa-taekwondo.us" target="_blank">Quicklink: <u><font color=#0066CC>Click here to go to USA Taekwondo</u></font></a>'
    pausecontent2[1]='<a href="http://www.cnn.com" target="_blank">Quicklink: <u><font color=#0066CC>CNN: Headline and breaking news 24/7</a></u></font>'
    pausecontent2[2]='<a href="mailto:chungmastkd@verizon.net">Quicklink: <u><font color=#0066CC>Contact Chung Ma'+"'"+'s Taekwondo Web development Team</font></a></p></u>'
    pausecontent2[3]='<a href="http://www.tkdm.com" target="_blank">Quicklink: <u><font color=#0066CC>TKDM: World Tae Kwon Do Online Magazine</a></u></font>'
    </script>
    And Here is my PHP page:
    Code:
    <?php
    // Connecting, selecting database
    $link = mysql_connect('xxxxxx', 'xxxxxx', 'xxxxxx')
       or die('Could not connect: ' . mysql_error());
    
    mysql_select_db('scroller') or die('Could not select database');
    
    // Performing SQL query
    $query = 'select identity,headline,article from scroller where StartDate <= date_format(now(),\'%Y-%m-%d\') and EndDate >= date_format(now(),\'%Y-%m-%d\') ORDER BY identity ASC';$result = mysql_query($query) or die('Query failed: ' . mysql_error());
    
    for ($i = 0; $i < mysql_num_rows($result); $i++ ) { 
        $headlineData = mysql_fetch_assoc($result); 
    
        print "pausecontent[$i]='<b>{$headlineData['headline']}</b>{$headlineData['linktxt']}';\n"; 
    }
    ?>
    And what I NEED is something like:
    Code:
    <?php
    // Connecting, selecting database
    $link = mysql_connect('mysql.bluedomino.com', 'chungmanews', '1mallet1')
       or die('Could not connect: ' . mysql_error());
    
    mysql_select_db('scroller') or die('Could not select database');
    
    // Performing SQL query
    $query = 'select identity,headline,article from scroller where StartDate <= date_format(now(),\'%Y-%m-%d\') and EndDate >= date_format(now(),\'%Y-%m-%d\') ORDER BY identity ASC';$result = mysql_query($query) or die('Query failed: ' . mysql_error());
    ?>
    <script type="text/javascript">
    
    /*Example message arrays for the two demo scrollers*/
    
    var pausecontent=new Array()
    <?php
    for ($i = 0; $i < mysql_num_rows($result); $i++ ) { 
        $headlineData = mysql_fetch_assoc($result); 
    
        echo "pausecontent[$i]='<b>{$headlineData['headline']}</b>{$headlineData['linktxt']}';\n"; 
    }
    ?>
    var pausecontent2=new Array()
    pausecontent2[0]='<a href="http://www.usa-taekwondo.us" target="_blank">Quicklink: <u><font color=#0066CC>Click here to go to USA Taekwondo</u></font></a>'
    pausecontent2[1]='<a href="http://www.cnn.com" target="_blank">Quicklink: <u><font color=#0066CC>CNN: Headline and breaking news 24/7</a></u></font>'
    pausecontent2[2]='<a href="mailto:chungmastkd@verizon.net">Quicklink: <u><font color=#0066CC>Contact Chung Ma'+"'"+'s Taekwondo Web development Team</font></a></p></u>'
    pausecontent2[3]='<a href="http://www.tkdm.com" target="_blank">Quicklink: <u><font color=#0066CC>TKDM: World Tae Kwon Do Online Magazine</a></u></font>'
    </script>
    Is this close? If it is, then all I need is an include in my HTML page? I hate to sound like a complete doof on this, but coffee and liquer haven't fixed it in my mind yet!
    Ok, after my edit I think I am closer still. It looks to me like this code is creating what I need;
    Now can I call this directly from my HTML page in here?
    Code:
    new pausescroller(somehow call the php here, "pscroller1", "someclass", 3000)
    Last edited by steamngn; 11-10-2006 at 05:50 PM.
    (Management+Coworkers)<>Logic

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I think you are going one step too far. You are successfully imbedding the PHP code inside your Javascript code, so stop right there-- does it work? It should.

    Why are you trying to call PHP from Javscript still?

  • #8
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Maybe because I'm looney?
    When I preview the quote.php page in a browser, the page itself is blank. If I view the source code, it looks like this:
    Code:
    window.onerror = SymError;
    
    var SymRealWinOpen = window.open;
    
    function SymWinOpen(url, name, attributes)
    {
      return (new Object());
    }
    
    window.open = SymWinOpen;
    
    //-->
    </script>
    
    <script type="text/javascript">
    
    /*Example message arrays for the two demo scrollers*/
    
    var pausecontent=new Array()
    pausecontent[0]='<b>Welcome to the Chung Ma\'s Taekwondo NewsWire</b>';
    pausecontent[1]='<b>Chung Ma\'s Taekwondo Tournament Saturday, Nov 11 2006</b>';
    pausecontent[2]='<b>Color Belt Promotion Test Friday, Nov 17 2006 in Kingston</b>';
    pausecontent[3]='<b>The Forum is Live!</b>';
    var pausecontent2=new Array()
    pausecontent2[0]='<a href="http://www.usa-taekwondo.us" target="_blank">Quicklink: <u><font color=#0066CC>Click here to go to USA Taekwondo</u></font></a>'
    pausecontent2[1]='<a href="http://www.cnn.com" target="_blank">Quicklink: <u><font color=#0066CC>CNN: Headline and breaking news 24/7</a></u></font>'
    pausecontent2[2]='<a href="mailto:chungmastkd@verizon.net">Quicklink: <u><font color=#0066CC>Contact Chung Ma'+"'"+'s Taekwondo Web development Team</font></a></p></u>'
    pausecontent2[3]='<a href="http://www.tkdm.com" target="_blank">Quicklink: <u><font color=#0066CC>TKDM: World Tae Kwon Do Online Magazine</a></u></font>'
    </script>
    
    <script language="JavaScript">
    <!--
    var SymRealOnLoad;
    var SymRealOnUnload;
    
    function SymOnUnload()
    {
      window.open = SymWinOpen;
      if(SymRealOnUnload != null)
         SymRealOnUnload();
    }
    
    function SymOnLoad()
    {
      if(SymRealOnLoad != null)
         SymRealOnLoad();
      window.open = SymRealWinOpen;
      SymRealOnUnload = window.onunload;
      window.onunload = SymOnUnload;
    }
    
    SymRealOnLoad = window.onload;
    window.onload = SymOnLoad;
    
    //-->
    </script>
    This looks Ok as far as the array part goes (I assume the rest of it is ok). What I don't understand (and maybe I am using the wrong words) is how I get this into my HTML pages. The line of code that runs the scroller in my HTML page is:
    Code:
    									<script type="text/javascript">
    
    //new pausescroller(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)
    
    new pausescroller(pausecontent, "pscroller1", "someclass", 3000)
    document.write("<br />")
    new pausescroller(pausecontent2, "pscroller2", "someclass", 2000)
    </script></p>
    How do I get the quote.php output into the places where each scroller is calling for pausecontent and pausecontent2? I ***ume that the HTML page needs to load the PHP stuff somehow...
    Thanks very much for your help. As I said, this is new and foreign to me!
    Andy
    (Management+Coworkers)<>Logic

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    Hudson Valley, NY
    Posts
    147
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey Fumigator,
    answered my own stupidity. I took the <sript></script> stuff out of my php page, and then used this to insert into my HTML pages:
    Code:
    <script type="text/javascript" src="test/headlines.php">
     
      </script>
    Works like a charm, and seems to load quickly as well. Thanks so much for your help, I'll get it yet!
    Andy
    (Management+Coworkers)<>Logic


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •