ROCKINDANO Posted December 7, 2009 Share Posted December 7, 2009 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 More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 First I would remove the CDATA tags. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972796 Share on other sites More sharing options...
ROCKINDANO Posted December 7, 2009 Author Share Posted December 7, 2009 ok, thanks but that still won't make it work. for some reason it doesn't move to the next story. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972810 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 Also did you notice your missing an '=' for the "last" var. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972813 Share on other sites More sharing options...
ROCKINDANO Posted December 7, 2009 Author Share Posted December 7, 2009 yes thank you, well i have it to where it changes but once it gets to the last news it stops. it doesn't want to loop back to the first one. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972819 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 try adding alert(current) directly after the if/else statement to see what it gets set to after hitting the last item. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972822 Share on other sites More sharing options...
ROCKINDANO Posted December 7, 2009 Author Share Posted December 7, 2009 ok, it counts currectly but it only displays one news and its not the first news in the db. its the third. do you think if i add a if statement down where it prints the news Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972832 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 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> Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972840 Share on other sites More sharing options...
ROCKINDANO Posted December 7, 2009 Author Share Posted December 7, 2009 hey it worked!!!!!!! ah. thank you Justlikelcarus. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972844 Share on other sites More sharing options...
JustLikeIcarus Posted December 7, 2009 Share Posted December 7, 2009 haha sweet. Glad to be of help. Link to comment https://forums.phpfreaks.com/topic/184267-help-with-news-ticker/#findComment-972846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.