Jump to content

help with news ticker


ROCKINDANO

Recommended Posts

Hello, i am trying to get a news ticker working. I am using javascript to read news of a mysql db. i have it to where it reads the news and shows the first record but it doesn't change. can someone help me with this?

 

this is my javascript code:

       <script language="JavaScript" type="text/javascript">
           //<!--
           //<![CDATA[
           
           first = 1;
           last 4;
	   current = 0;
           
           function nextPicture() {
               // Hide current picture
               object = document.getElementById('slide' + current);
               object.style.display = 'none';
               
               // Show next picture, if last, loop back to front
               if (current == last) { current = 1; }
               else { current++ }
               object = document.getElementById('slide' + current);
               object.style.display = 'block';
		   setTimeout(nextPicture, 1500);
           }

           function previousPicture() {
               // Hide current picture
               object = document.getElementById('slide' + current);
               object.style.display = 'none';
               
               if (current == first) { current = last; }
               else { current--; }
               object = document.getElementById('slide' + current);
               object.style.display = 'block';
           }
           //]]>
           // -->
       </script>

 

and this is my php/mysql code:

        <?php 
	if(!($db = @ mysql_connect('localhost', 'username', 'password')))
		{
			print "Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.";
		}						
		 //select which database you want to edit
		mysql_select_db("edinburg_site"); 

		$news_id=mysql_real_escape_string($_GET[news_id]);

		$query = "SELECT * FROM events ORDER BY event_id DESC LIMIT 4";
		$result = mysql_query($query);

		//goes through all records in database and retrieves the need ones.
		while($r=mysql_fetch_array($result))
		{	
			$news_id=$r["news_id"];
			$title = $r["title"];
			$fulldesc = $r["fulldesc"];

		}//end while loop	
		    print "<div class='slideShow'>";
          		print "<div class='setTitle'><p>Special Events</p></div>";
           		print "<div id='slide1' class='slides'>";
               	print "<div class='slideTitle'>" .$title. "</div>";
               	print "".$fulldesc."";
               	print "</div>";

//           		print "<div id='slide2' class='slides'>";
//               	print "<div class='slideTitle'>" .$title. "</div>";
//               	print "".$fulldesc."";
//               	print "</div>";
//
//           		print "<div id='slide3' class='slides'>";
//               	print "<div class='slideTitle'>" .$title. "</div>";
//               	print "".$fulldesc."";
//               	print "</div>";

		   ?>
           <div class="controls">
               <a href="javascript:previousPicture()" style="margin: 10px;"> Previous</a>
               <a href="javascript:nextPicture()" style="margin: 10px;">Next</a>
           </div>
       </div>	

Link to comment
https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/
Share on other sites

I just noticed that your while loop is not correct in the php code. 

try a loop more like this

   

   

<?php 
      if(!($db = @ mysql_connect('localhost', 'username', 'password')))
         {
            print "Error: Could not connect to our database sorry for any inconvience.<br /> Please try at a later time.";
         }                  
          //select which database you want to edit
         mysql_select_db("edinburg_site"); 

         $news_id=mysql_real_escape_string($_GET[news_id]);
               
         $query = "SELECT * FROM events ORDER BY event_id DESC LIMIT 4";
         $result = mysql_query($query);
            
         //goes through all records in database and retrieves the need ones.
?>
          <div class='slideShow'>
         <div class='setTitle'><p>Special Events</p></div>

<?php
         $i = 1;
         while($r=mysql_fetch_array($result))
         {   
            $news_id=$r["news_id"];
            $title = $r["title"];
            $fulldesc = $r["fulldesc"];
?>
            <div id="slide<?php echo $i; ?>" class='slides'>
                  <div class='slideTitle'><?php echo $title;?></div>
                  <?php echo $fulldesc; ?>
                 </div>
<?php
             $i++;
          }//end while loop  ?> 
            
           <div class="controls">
               <a href="javascript:previousPicture()" style="margin: 10px;"> Previous</a>
               <a href="javascript:nextPicture()" style="margin: 10px;">Next</a>
           </div>
       </div>   

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.