Results 1 to 9 of 9

Thread: Script: George's Expandable Ticker

  1. #1
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default Script: George's Expandable Ticker

    http://www.dynamicdrive.com/dynamici...andticker2.htm

    I am trying to modify the ticker that George provided to pull the ticker contents from a mysql database. I have done this before in other tickers but for some reason I just can't get this one to work. I am not the best with javascript so feel free to laugh.

    top of the page
    PHP Code:
    <?php
    $ticker 
    mysql_query("SELECT * FROM table_ticker WHERE display =1 ORDER BY display_order");
    if (
    mysql_num_rows($ticker)>0) {
    then body and style... then script

    Code:
    <script language="JavaScript1.2">
    
    /***********************************************
    * George's Expandable Ticker- © Dynamic Drive (www.dynamicdrive.com)
    * This notice must stay intact for use
    * Visit http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    //configure tickercontents[] to set the messges you wish be displayed (HTML codes accepted)
    
     var tickercontents=new Array()
     <?php
     $i = 0;
     while ($tick = mysql_fetch_array($ticker)) {
     ?>
         tickercontents[<?php echo $i?>]='<?php echo $tick['content']?>'
     <?php
         $i++;
     }
     ?>
    This is how it is originally done in the ticker
    Code:
    var tickercontents=new Array()
    tickercontents[0]='enter text here'
    tickercontents[1]='more text here'
    any help or ideas would be greatly appreciated.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The output of that script is a bit vague to me, so I'd rewrite it a bit to make it clearer:
    PHP Code:
    var tickercontents=new Array()
    <?php
    for ($i 0$tick mysql_fetch_array($ticker); $i++) {
         echo 
    "     tickercontents[$i]='".$tick['content']."'\n";
    ?>
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    are you saying to try this?

    PHP Code:

    var tickercontents=new Array()
    <?php
       $i 
    0;
       while (
    $tick mysql_fetch_array($ticker)) {
         echo 
    "tickercontents[$i]='".$tick['content']."'\n";
         
    $i++;
       }
    ?>
    just tried it and it didnt work either. i moved the php code out of the javascript block to make sure it was returning values and it does return what is to be displayed. appears for some reason I can not get the php and jscript to communicate.
    Last edited by gpigate; 07-16-2007 at 04:04 PM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    appears for some reason I can not get the php and jscript to communicate.
    There is no communication. PHP is server side and parsed when the page is requested. The text output after that no longer has any PHP involved. It is simply plain text, with a mix of html, javascript, css, etc.
    PHP can output javascript just as it outputs html, but you must do so correctly.

    To help fix the problem, please post what it is outputting.

    A while loop and a for loop are the same (if the while loop has the third for loop parameter in it and the first before it), but I thought it was more readable to put them in the same line. That's your choice.

    The only real guess I have at this point is that $tick['content'] isn't set correctly... that the database isn't outputting it, or something along those lines.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    sorry about that I did not notice your use of the for loop instead of the while.

    the output here isnt really bothering me. should the below not work. all that is in the db table is some html tags for images and other rows with text. to make things simple, i removed the db from the picture and I am simply trying with variables and text.


    Code:
    <script language="JavaScript1.2">
    var tickercontents=new Array()
    
    <?php 
       $i = 'abcd'; 
       $j = 'efgh';
    
    ?>
    
    tickercontents[0]='<?php echo $i;?>'
    tickercontents[1]='<?php echo $j;?>'
    ............
    </script>

  6. #6
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    i also moved the php block out of the script block and it was able to load the sql, the contents from the table and echo them to the page.

  7. #7
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    ok I finally got it to work. not sure what i did different. code is this
    Code:
    var tickercontents=new Array()
    <?php
         for ($i=0;$tick = mysql_fetch_array($ticker);$i++) 
         {
    ?>
         tickercontents[<?php echo $i;?>]='<?php echo $tick['content']?>'
    <?php  }  ?>
    now the thing is, I am using TinyMCE to manage the back end and create content in the table this reads form.

    If I update the row in the table using TinyMCE it causes the ticker to stop working. even though in the database there are no differences. It is not adding tags or anything, just straight text "Hello World".

    if i insert hello world via the db it shows

    if I insert hello world via the admin panel using TinyMCE it quits working. Really odd, does anyone have any ideas?

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm glad the code is working now.
    This may have something to do with not ending your lines with semicolons, though I'm not sure why, then, the new script does work.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Jul 2007
    Location
    Irmo, SC
    Posts
    96
    Thanks
    10
    Thanked 7 Times in 7 Posts

    Default

    well the lines without the semicolons are in the script block and not the php block.

    but hey its working, so im leaving it alone.

    the only other thing that is bugging me is I would like to have 2 of them, and if I put in another script it works but the first one doesnt. does this have anything to do with double declaration in jscript?

Bookmarks

Posting Permissions

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