View Full Version : ticker news + Mysql
rash44
پنج شنبه 09 خرداد 1392, 12:01 عصر
سلام
اگر امکان داره این کد رو اصلاح کنید که عنواین خبری از دیتابیس خونده بشه
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>www.darkcms.ir</title>
</head>
<body>
<center>
<a id="tickerAnchor" style="font:12px Tahoma; color:red; text-decoration:none;" dir="rtl"></a>
</center>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class=\"tickls\">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}
if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 6;
theSummaries[0] = "به سایت ما خوش آمدید.";
theSiteLinks[0] = "http://www.darkcms.ir/";
theSummaries[1] = "طراحی کد های خود را به ما بسپارید.";
theSiteLinks[1] = "http://www.darkcms.ir/";
theSummaries[2] = "هر جور کدی خواستین این جا هست.";
theSiteLinks[2] = "http://www.darksoftware.org/";
theSummaries[3] = "ترفند های جالب و چیز هایی که تا به حال حتی بهش فکر هم نکرده اید.";
theSiteLinks[3] = "http://www.darksoftware.ir/";
theSummaries[4] = "آموزش کدنویسی و نوشتن کد را با ما تجربه کنید.";
theSiteLinks[4] = "http://www.google.com/";
theSummaries[5] = "و از همه مهم تر آزمایش کد های HTML به صورت آنی و آنلاین و البته با نسخه آفلاین";
theSiteLinks[5] = "http://www.yahoo.com/";
startTicker();
//-->
</script>
</body>
</html>
sh.n.n786
پنج شنبه 09 خرداد 1392, 19:55 عصر
درود و ...
عمو برای ارتباط با SQL نیاز به کد PHP دارین نه JS اینو ببین ...
http://w3schools.com/ajax/ajax_aspphp.asp
موفق باشی
rash44
جمعه 10 خرداد 1392, 09:29 صبح
درود و ...
عمو برای ارتباط با SQL نیاز به کد PHP دارین نه JS اینو ببین ...
http://w3schools.com/ajax/ajax_aspphp.asp
موفق باشی
سلام می دونم نیاز به php هست .
مشکل اینه که نمیدونم باید کدوم بخش کد بالا رو تغییر بدم که محتویاتی که از databse با php خوندم توی کدوم بخش کد js قرار بدم
ayub_coder
جمعه 10 خرداد 1392, 10:30 صبح
theSummaries[0] = "به سایت ما خوش آمدید.";
theSiteLinks[0] = "http://www.darkcms.ir/";
theSummaries[1] = "طراحی کد های خود را به ما بسپارید.";
theSiteLinks[1] = "http://www.darkcms.ir/";
theSummaries[2] = "هر جور کدی خواستین این جا هست.";
theSiteLinks[2] = "http://www.darksoftware.org/";
theSummaries[3] = "ترفند های جالب و چیز هایی که تا به حال حتی بهش فکر هم نکرده اید.";
theSiteLinks[3] = "http://www.darksoftware.ir/";
theSummaries[4] = "آموزش کدنویسی و نوشتن کد را با ما تجربه کنید.";
theSiteLinks[4] = "http://www.google.com/";
theSummaries[5] = "و از همه مهم تر آزمایش کد های HTML به صورت آنی و آنلاین و البته با نسخه آفلاین";
theSiteLinks[5] = "http://www.yahoo.com/";
شما باید این بخش رو از دیتابیس بخونی و بذاری اینجا.
rash44
جمعه 10 خرداد 1392, 10:33 صبح
theSummaries[0] = "به سایت ما خوش آمدید.";
theSiteLinks[0] = "http://www.darkcms.ir/";
theSummaries[1] = "طراحی کد های خود را به ما بسپارید.";
theSiteLinks[1] = "http://www.darkcms.ir/";
theSummaries[2] = "هر جور کدی خواستین این جا هست.";
theSiteLinks[2] = "http://www.darksoftware.org/";
theSummaries[3] = "ترفند های جالب و چیز هایی که تا به حال حتی بهش فکر هم نکرده اید.";
theSiteLinks[3] = "http://www.darksoftware.ir/";
theSummaries[4] = "آموزش کدنویسی و نوشتن کد را با ما تجربه کنید.";
theSiteLinks[4] = "http://www.google.com/";
theSummaries[5] = "و از همه مهم تر آزمایش کد های HTML به صورت آنی و آنلاین و البته با نسخه آفلاین";
theSiteLinks[5] = "http://www.yahoo.com/";
شما باید این بخش رو از دیتابیس بخونی و بذاری اینجا.
ممنون
چه جوری این بخش رو مقدار دهی کنم ؟
فرض کنید مقادیر مورد نظر در line$ قرار داره
rash44
جمعه 10 خرداد 1392, 11:37 صبح
لطفا راهنمائی کنید
rash44
جمعه 10 خرداد 1392, 18:25 عصر
لطفا راهنمایی کنید
MMSHFE
شنبه 11 خرداد 1392, 00:16 صبح
خوب اگه آرایه هست، با foreach پیمایش کنید و یکی یکی اینجا درجش کنید و اگه نیست، با explode تبدیل به آرایه کنید و بعد، با همون حلقه foreach یا for پیمایش کرده و توی JS بنویسید.
rash44
شنبه 11 خرداد 1392, 17:00 عصر
خوب اگه آرایه هست، با foreach پیمایش کنید و یکی یکی اینجا درجش کنید و اگه نیست، با explode تبدیل به آرایه کنید و بعد، با همون حلقه foreach یا for پیمایش کرده و توی JS بنویسید.
ممنون
نمی دونم باید چه جوری php و Js رو با هم ادغام کنم
rash44
شنبه 11 خرداد 1392, 17:12 عصر
مشکل این کد چیه ؟
<?php
require_once('db.php');
$q="select `id`,`title` from `post`";
$r=mysql_query($q);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>www.darkcms.ir</title>
</head>
<body>
<center>
<a id="tickerAnchor" style="font:12px Tahoma; color:red; text-decoration:none;" dir="rtl"></a>
</center>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko{border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class=\"tickls\">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}
if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 6; </script>
<?php while ($line=mysql_fetch_assoc($r)) { ?>
<script>
theSummaries[<?php echo $line['id']; ?>] = "<?php echo $line['title']; ?>";</script>
<?php } ?>
<script>
theSiteLinks[0] = "http://www.darkcms.ir/";
startTicker();
//-->
</script>
</body>
</html>
Tarragon
شنبه 11 خرداد 1392, 19:11 عصر
بفرمایید:
<?php
require_once('db.php');
$sql=mysql_query("select `id`,`title`,`link` from `post`");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>www.darkcms.ir</title>
</head>
<body>
<center>
<a id="tickerAnchor" style="font:12px Tahoma; color:red; text-decoration:none;" dir="rtl"></a>
</center>
<script language="JavaScript" type="text/javascript">
<!--
// Ticker startup
function startTicker()
{
// Define run time values
theCurrentStory = -1;
theCurrentLength = 0;
// Locate base objects
if (document.getElementById) {
theAnchorObject = document.getElementById("tickerAnchor");
runTheTicker();
}
else {
document.write("<style>.ticki{display:none;}.ticko {border:0px; padding:0px;}</style>");
return true;
}
}
// Ticker main run loop
function runTheTicker()
{
var myTimeout;
// Go for the next story data block
if(theCurrentLength == 0)
{
theCurrentStory++;
theCurrentStory = theCurrentStory % theItemCount;
theStorySummary = theSummaries[theCurrentStory].replace(/"/g,'"');
theTargetLink = theSiteLinks[theCurrentStory];
theAnchorObject.href = theTargetLink;
thePrefix = "<span class=\"tickls\">" + theLeadString + "</span>";
}
// Stuff the current ticker text into the anchor
theAnchorObject.innerHTML = thePrefix +
theStorySummary.substring(0,theCurrentLength) + whatWidget();
// Modify the length for the substring and define the timer
if(theCurrentLength != theStorySummary.length)
{
theCurrentLength++;
myTimeout = theCharacterTimeout;
}
else
{
theCurrentLength = 0;
myTimeout = theStoryTimeout;
}
// Call up the next cycle of the ticker
setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
if(theCurrentLength == theStorySummary.length)
{
return theWidgetNone;
}
if((theCurrentLength % 2) == 1)
{
return theWidgetOne;
}
else
{
return theWidgetTwo;
}
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
var theCharacterTimeout = 50;
var theStoryTimeout = 5000;
var theWidgetOne = "_";
var theWidgetTwo = "-";
var theWidgetNone = "";
var theLeadString = "";
var theSummaries = new Array();
var theSiteLinks = new Array();
var theItemCount = 6;
<?php while ($row=mysql_fetch_assoc($sql)) {
echo "theSummaries[{$row['id']}] = \"{$row['title']}\";".PHP_EOL;
echo "theSiteLinks[{$row['id']}] = \"{$row['link']}\";" . PHP_EOL . PHP_EOL;
} ?>
theSiteLinks[0] = "http://www.darkcms.ir/";
startTicker();
//-->
</script>
</body>
</html>
rash44
شنبه 11 خرداد 1392, 20:09 عصر
سلام
ممنون
جواب نداد و
Message: Syntax error
Line: 100
Char: 27
Code: 0
URI: http://127.0.0.1/tick/index.php
این خط میشه :
var theItemCount = 6;
آیا بین تگ اسکریپت میشه از PHP استفاده و کرد و نیازی به بستن تگ اسکریپت نیست ؟
Tarragon
شنبه 11 خرداد 1392, 21:23 عصر
مطمئنید خط 99 می شه اون؟
از چه نرم افزاری استفاده می کنید؟
بله با echo.
rash44
یک شنبه 12 خرداد 1392, 08:54 صبح
برای طراحی از Front Page و برای تست هم از IE 8 و Fire Fox
MMSHFE
یک شنبه 12 خرداد 1392, 09:30 صبح
لطفاً متون طولانی رو وقتی که جواب رو مستقیماً میخواین بعدش یا با فاصله کم بنویسید و مشخصه که جوابتون در پاسخ به کدوم پست هست، نقل قول نکنید یا حداقل کمی از ابتداش رو نقل قول کرده و بقیه رو ... بگذارین.
rash44
یک شنبه 12 خرداد 1392, 16:12 عصر
لطفا راهنمائی کنید
Tarragon
یک شنبه 12 خرداد 1392, 16:37 عصر
با چه نرم اقزاری اجراش می کنید؟
خط 100 مشکلی نداره.
بقیه دوستان امید وارد راهنمایی کنند.
rash44
یک شنبه 12 خرداد 1392, 17:34 عصر
با چه نرم اقزاری اجراش می کنید؟
خط 100 مشکلی نداره.
بقیه دوستان امید وارد راهنمایی کنند.
سلام
Easy Php
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.