[JS i PHP] Problem z połączeniem JS z PHP

HTML to podstawy w dziedzinie tworzenia stron WWW, Style CSS warto opanować, bowiem za ich pomocą można dostosować odpowiednio wygląd swojej witryny WWW. Zagłębiamy się dalej i udostępniamy w tym forum możliwość zadawania pytań o JavaScript.
ODPOWIEDZ
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

[JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

Witajcie,
Znalazlem w sieci pewien skrypt scrollera, który chciałbym wykorzystać na stronie. Chciałbym zrobić jakby taki pasek newsów, który pobiera z bazy MySQL tytuły newsów i później wyświetla je w tym scrollerze.

Problem w tym, że nie wiem jak połączyć PHP z JavaScriptem, ponieważ w PHP musze zastosować zmienne i nie wiem jak je połączyć z tym scrollem.

Skrypt ten wartości do wyświetlania ma tak ustawiane:

Kod: Zaznacz cały

<script type="text/javascript" language="JavaScript">        
Article = new Array;
i=0;

  Article[i] = new Array ("tekst", "http://ricom.co.uk", "_blank");i++  
  Article[i] = new Array ("tekst2", "http://ricom.co.uk/resources.php", "_blank");i++
  Article[i] = new Array ("tekst3", "http://ricom.co.uk/contacts.php", "_blank");i++
</script>
A między znacznik <script> a </script> nie mogę wstawić znaczników PHP <?php ?> bo nie będzie działać.

Widziałem takie połączenie na jednej stronie, ale nie wiem jak oni to zrobili.

W JS nie siedze, nie orientuje się, więc mam pytanie jak sobie z tym poradzić???

Proszę o pomoc.
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

moze nie zmieniles rozszerzenia pliku na php?
nie ma znaczenia gdzie wstawisz <? ?> na stronie - zawsze bedzie dzialac..
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

Plik ma rozszerzenie .php i wstawiłem kod <? ?> pomiędzy kod javy i nie działa... nic sie nie pojawia....
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

napsiz jak to robisz..
zamiesc tu kod..
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

Proszę, oto cały kod wraz z kodem skryptu (trochę długie):

Kod: Zaznacz cały

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
<meta name="Authoring_tool" content="Pajaczek NxG STD v5.3.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>:: Pasek newsow ::</title>
<LINK href="styl.css" rel="StyleSheet" type="text/css">
<script type="text/javascript" language="JavaScript">
                                     
Article = new Array;
i=0;

<? 
@ $polaczenie = mysql_pconnect($host, $db_user, $db_pass);
if (!polaczenie) 
 {
  echo "Nie udało się nawiązać połączenia z serwerem.";
  exit;
 }
mysql_select_db($db);

$sql = mysql_query("SELECT * FROM `news` ORDER BY `data` DESC LIMIT 0,10");
$ile = mysql_num_rows($sql);

for($a=0; $a<$ile; $a++)
{
 $dane = mysql_fetch_array($sql);
 $id = stripslashes($dane['id']);
 $tytul = stripslashes($dane['tytul']);
}

  
?>

  Article[i] = new Array ("tekst", "http://ricom.co.uk", "_blank");i++  
  Article[i] = new Array ("tekst2", "http://ricom.co.uk/resources.php", "_blank");i++
  Article[i] = new Array ("tekst3", "http://ricom.co.uk/contacts.php", "_blank");i++
  
////// SCROLLER CONFIGURATION ///////////////////////////////////////////////////////////////////  
orientation = "horizontal"        // Orientation of scroller (Horizontal or vertical)
scrollerWidth = "250"             // Width of entire scroller.
scrollerHeight = "25"             // Height of Scroller.
borderWidth = 1                   // Width of border. (use 0 for no border).
borderColour = "#006600"          // Colour of scroller border. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red") 
backColour = "beige"              // Colour of scroller background. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red") 
staticColour = "#000000"          // Colour of scroller items that are NOT a link. (including scrollerDivider characters)
stopScroll = 1                    // Pause the scroller on mouseOver. (use 0 for no.)
textAlignment="center"            // Alignment of each scroller item.  Only really makes a difference on vertical scroller
                                  // (center, left, right, justify)

// Scroller Links
linkFont = "arial"                // Font of scroller links;
linkWeight = "normal"             // Weight of scroller links;
linkColour = "#006600"            // Colour of scroller links
linkSize = "10"                   // Size of links (in points)
linkDecoration = "none"           // Decoration of links. (underline, overline, none)

// Scroller Links On MouseOver
slinkFont = "arial"               // Font of scroller links;
slinkWeight = "normal"            // Weight of scroller links;
slinkColour = "#AFAF9D"           // Colour of scroller links
slinkSize = "10"                  // Size of links (in points)
slinkDecoration = "underline"     // Decoration of links. (underline, overline, none)

scrollerDivider = " - " // Character to place between each scroller item. 
                                  // <img> tags can be used if an image is required. 
                                  // Use "0" for nothing.  For Vertical scrollers, it is best to use "<br>"
/* 
  Because Netscape version 4 does not support this scroller, configure the values below so NS4 users do not see an error. 
  In the scroller's place will be a static title which can be a link if require.  The appearance of the static text (colour, scroller border etc)
  will be exactly the same as for the working version in other browsers.
*/
ns4Text = "Click Here to view our articles";  // Alternative text to display in Netscape 4.
ns4URL = "http://www.ricom.co.uk";            // URL of link in NS4. If no URL is required, enter "none"
ns4Target = "_top";                           // Frame target for link in NS4


////// DO NOT EDIT BELOW THIS LINE  ///////////////////////////////////////////////////////////////////

//Browser Sniffer
var isIE = (document.getElementById && document.all)?true:false;
var isNS4 = (document.layers)?true:false;
var isNS6 = (document.getElementById && !document.all)?true:false;
var isLoaded=false;

style='<style type="text/css">';
style+='p{font-family:'+linkFont+'; color:'+staticColour+'; font-size:'+linkSize+'pt; font-weight:'+linkWeight+'; text-align:'+textAlignment+'}';
style+='a.rcScroller,a.rcScroller:active,a.rcScroller:visited{color:'+linkColour+';text-decoration:'+linkDecoration+'; font-weight:'+linkWeight+'}';
style+='a.rcScroller:hover{color:'+slinkColour+';text-decoration:'+slinkDecoration+'; font-weight:'+slinkWeight+'}';
style+='rcScrollerHoverNS{color:red;text-decoration:'+slinkDecoration+'; font-weight:'+slinkWeight+'}';
style+='<\/style>';
document.writeln(style);

// Build the scroller and place it on the page
function buildScroller()
{
  boundry='<div name="boundry" id="boundry" style="position:relative"></div>';
  document.writeln(boundry);
}

function loadScroller(){
  if(isNS4){
    scroller='<table border="0" cellpadding="0" cellspacing="0" width="'+scrollerWidth+'" bgcolor="'+borderColour+'"><tr><td>'
    scroller+='<table border="0" cellpadding="3" cellspacing="1" width="100%" height="'+scrollerHeight+'" bgcolor="'+backColour+'"><tr><td align="center" nowrap><p>';
    if(ns4URL.toLowerCase()!="none"){scroller+='<a href="'+ns4URL+'" class="rcScroller" target="'+ns4Target+'">'+ns4Text+'</a>';}
    else{scroller+=ns4Text;} 
    scroller+='</p></td></tr></table></td></tr></table>'   
  }else{
    scroller='<table border="0" cellpadding="0" cellspacing="0" style="width:'+scrollerWidth+';height:'+scrollerHeight+';border:'+borderWidth+'px solid '+borderColour+';background-color:'+backColour+'">';
    scroller+='<tr valign="middle"><td><div id="div" style="';
    if(orientation.toLowerCase()=="vertical"){scroller+='height:'+scrollerHeight+';';}
    scroller+='width:'+scrollerWidth+'; position:relative; background-color:'+backColour+'; overflow:hidden">';
    scroller+='<div id="div1" style="position:relative; left:0; z-index:1">';
    scroller+='<table border="0" name="table" id="table"';
    if(orientation.toLowerCase()=="vertical"){scroller+='style="width:'+scrollerWidth+'"';}
    scroller+='><tr>';
    y=0;
    while (y<4)
    {
      for (x=0; x<(Article.length); x++)
      {
        if(orientation.toLowerCase()=="vertical"){scroller+='<tr>';}
        scroller+='<td ';
        if(orientation.toLowerCase()=="horizontal"){scroller+='nowrap';} if(stopScroll==1){scroller+=' onMouseOver="stopScroller();" onMouseOut="setWidth()"';}
        scroller+='><p>';
        if(Article[x][1].toLowerCase()!="none"){scroller+='<a class="rcScroller" href="'+Article[x][1]+'" target="'+Article[x][2]+'" >'+Article[x][0]+'<\/a>';
        }else{scroller+=Article[x][0];}          
        scroller+='</p><\/td>';
        
        if(orientation.toLowerCase()=="vertical"){scroller+='<\/tr>';}
              
        if(scrollerDivider.toLowerCase() != "none"){scroller+='<td nowrap><p>'+scrollerDivider+'<\/p><\/td>';}
      }
      y++
    }
    scroller+='<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>';  
  }
  document.getElementById("boundry").innerHTML=scroller;
  setWidth();
}


// Ensure the width of the scroller is divisible by 2. This allows smooth flowing of the scrolled content
function setWidth()
{ 
  tableObj=(isIE)?document.all("table"):document.getElementById("table"); 
  obj=(isIE)?document.all.div1:document.getElementById("div1");   
  objWidth=(orientation.toLowerCase()=="horizontal")?getOffset(tableObj,"width"):getOffset(tableObj,"height");
  HalfWidth=Math.floor(objWidth/2);
  newWidth = (HalfWidth*2)+2;
  obj.style.width=newWidth
  moveLayer(obj, newWidth);
  
}

// Move the layer by one pixel to the left
function moveLayer(obj, width)
{
  
  maxLeft = (0-(width/2)+2)/2
  if(orientation.toLowerCase()=="horizontal"){
    obj.style.left=(parseInt(obj.style.left) <= maxLeft)?0:parseInt(obj.style.left)-1
  }else{
    if(obj.style.top==""){obj.style.top=0;}
   // alert(obj.style.top)
    if (parseInt(obj.style.top)<(0-(width/2)+6)){
      obj.style.top = 0
    }else{
      obj.style.top = parseInt(obj.style.top)-1
    }
  }
  timer = setTimeout ("moveLayer(obj, "+width+");", 25); 
}

// Get width and height of layer
function getOffset(obj, dim) 
{
  if(dim=="width")
  {
    oWidth = obj.offsetWidth
    return oWidth
  }  
  else if(dim=="height")
  {
    oHeight = obj.offsetHeight
    return oHeight
  }    
}

function stopScroller()
{
  clearTimeout(timer)  
}

////// END OF SCRIPT  ///////////////////////////////////////////////////////////////////
//-->
</script> 
            
            
</head>

<body link="#ffffff" alink="#ffffff" vlink="#ffffff" onLoad="loadScroller()">
<script type="text/javascript" language="JavaScript">buildScroller()</script>
 <br>
</body>
</html>
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

no dobra wyciagasz cos z mysql ale gdzie checsz to wstawic?
daj tak i powinno dzialac:

Kod: Zaznacz cały

<script type="text/javascript" language="JavaScript"> 
                                      
Article = new Array; 
i=0; 

<? 
@ $polaczenie = mysql_pconnect($host, $db_user, $db_pass); 
if (!polaczenie) 
 { 
  echo "Nie udało się nawiązać połączenia z serwerem."; 
  exit; 
 } 
mysql_select_db($db); 

$sql = mysql_query("SELECT * FROM `news` ORDER BY `data` DESC LIMIT 0,10"); 
$ile = mysql_num_rows($sql); 

 $dane = mysql_fetch_array($sql);
 $id = stripslashes($dane['id']); // przyjalem ze to jest link
 $tytul = stripslashes($dane['tytul']); // a to tytul

for($a=0; $a<$ile; $a++) 
{
echo "Article[i] = new Array (\"$tytul[$a]\", \"$id[$a]\", \"_blank\");i++";
} 
  
?>

////// SCROLLER CONFIGURATION ///////////////////////////////////////////////////////////////////  
orientation = "horizontal"        // Orientation of scroller (Horizontal or vertical)  
ale nie gwaratnutej ze to bedzie dzialac..
Ostatnio zmieniony sob paź 01, 2005 11:13 pm przez Asit, łącznie zmieniany 4 razy.
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

No właśnie tu jest drugi problem bo jak przekopiuje to

Kod: Zaznacz cały

 Article[i] = new Array ("tekst", "http://ricom.co.uk", "_blank");i++  
i wstawie między <? ?> to wyskoczy błąd, że występuje nieznany "[" w kodzie.... :/
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

Niestety, nie działa....
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

co to jest u Ciebie $id i $tytul?
nie wiem dlaczego u Ciebie nie dziala ale ja specjalnie zrobilem sobie tabele w sqlu i smiga mi jak trzeba.. zrobilem cos takiego:
[php]<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">
<meta http-equiv="Content-Language" content="pl">
<meta name="Authoring_tool" content="Pajaczek NxG STD v5.3.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>:: Pasek newsow ::</title>
<LINK href="styl.css" rel="StyleSheet" type="text/css">
<?
@ $polaczenie = mysql_pconnect($host, $db_user, $db_pass);
if (!polaczenie)
{
echo "Nie udało się nawiązać połączenia z serwerem.";
exit;
}
mysql_select_db($db);

$sql = mysql_query("SELECT * FROM `id` ORDER BY `data` DESC LIMIT 0,10");
$ile = mysql_num_rows($sql);

$dane = mysql_fetch_array($sql);
$id = stripslashes($dane['id']);
$tytul = stripslashes($dane['tytul']);
?>
<script type="text/javascript" language="JavaScript">

Article = new Array;
i=0;

<?
for($a=0; $a<$ile; $a++)
{
echo "Article = new Array (\"$tytul[$a]\", \"$id[$a]\", \"_blank\");i++";
}
?>

////// SCROLLER CONFIGURATION ///////////////////////////////////////////////////////////////////
orientation = "horizontal" // Orientation of scroller (Horizontal or vertical)
scrollerWidth = "250" // Width of entire scroller.
scrollerHeight = "25" // Height of Scroller.
borderWidth = 1 // Width of border. (use 0 for no border).
borderColour = "#006600" // Colour of scroller border. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red")
backColour = "beige" // Colour of scroller background. (Use either hexadecimal or text values. e.g. "#FF0000" or "Red")
staticColour = "#000000" // Colour of scroller items that are NOT a link. (including scrollerDivider characters)
stopScroll = 1 // Pause the scroller on mouseOver. (use 0 for no.)
textAlignment="center" // Alignment of each scroller item. Only really makes a difference on vertical scroller
// (center, left, right, justify)

// Scroller Links
linkFont = "arial" // Font of scroller links;
linkWeight = "normal" // Weight of scroller links;
linkColour = "#006600" // Colour of scroller links
linkSize = "10" // Size of links (in points)
linkDecoration = "none" // Decoration of links. (underline, overline, none)

// Scroller Links On MouseOver
slinkFont = "arial" // Font of scroller links;
slinkWeight = "normal" // Weight of scroller links;
slinkColour = "#AFAF9D" // Colour of scroller links
slinkSize = "10" // Size of links (in points)
slinkDecoration = "underline" // Decoration of links. (underline, overline, none)

scrollerDivider = " - " // Character to place between each scroller item.
// <img> tags can be used if an image is required.
// Use "0" for nothing. For Vertical scrollers, it is best to use "<br>"
/*
Because Netscape version 4 does not support this scroller, configure the values below so NS4 users do not see an error.
In the scroller's place will be a static title which can be a link if require. The appearance of the static text (colour, scroller border etc)
will be exactly the same as for the working version in other browsers.
*/
ns4Text = "Click Here to view our articles"; // Alternative text to display in Netscape 4.
ns4URL = "http://www.ricom.co.uk"; // URL of link in NS4. If no URL is required, enter "none"
ns4Target = "_top"; // Frame target for link in NS4


////// DO NOT EDIT BELOW THIS LINE ///////////////////////////////////////////////////////////////////

//Browser Sniffer
var isIE = (document.getElementById && document.all)?true:false;
var isNS4 = (document.layers)?true:false;
var isNS6 = (document.getElementById && !document.all)?true:false;
var isLoaded=false;

style='<style type="text/css">';
style+='p{font-family:'+linkFont+'; color:'+staticColour+'; font-size:'+linkSize+'pt; font-weight:'+linkWeight+'; text-align:'+textAlignment+'}';
style+='a.rcScroller,a.rcScroller:active,a.rcScroller:visited{color:'+linkColour+';text-decoration:'+linkDecoration+'; font-weight:'+linkWeight+'}';
style+='a.rcScroller:hover{color:'+slinkColour+';text-decoration:'+slinkDecoration+'; font-weight:'+slinkWeight+'}';
style+='rcScrollerHoverNS{color:red;text-decoration:'+slinkDecoration+'; font-weight:'+slinkWeight+'}';
style+='<\/style>';
document.writeln(style);

// Build the scroller and place it on the page
function buildScroller()
{
boundry='<div name="boundry" id="boundry" style="position:relative"></div>';
document.writeln(boundry);
}

function loadScroller(){
if(isNS4){
scroller='<table border="0" cellpadding="0" cellspacing="0" width="'+scrollerWidth+'" bgcolor="'+borderColour+'"><tr><td>'
scroller+='<table border="0" cellpadding="3" cellspacing="1" width="100%" height="'+scrollerHeight+'" bgcolor="'+backColour+'"><tr><td align="center" nowrap><p>';
if(ns4URL.toLowerCase()!="none"){scroller+='<a href="'+ns4URL+'" class="rcScroller" target="'+ns4Target+'">'+ns4Text+'</a>';}
else{scroller+=ns4Text;}
scroller+='</p></td></tr></table></td></tr></table>'
}else{
scroller='<table border="0" cellpadding="0" cellspacing="0" style="width:'+scrollerWidth+';height:'+scrollerHeight+';border:'+borderWidth+'px solid '+borderColour+';background-color:'+backColour+'">';
scroller+='<tr valign="middle"><td><div id="div" style="';
if(orientation.toLowerCase()=="vertical"){scroller+='height:'+scrollerHeight+';';}
scroller+='width:'+scrollerWidth+'; position:relative; background-color:'+backColour+'; overflow:hidden">';
scroller+='<div id="div1" style="position:relative; left:0; z-index:1">';
scroller+='<table border="0" name="table" id="table"';
if(orientation.toLowerCase()=="vertical"){scroller+='style="width:'+scrollerWidth+'"';}
scroller+='><tr>';
y=0;
while (y<4)
{
for (x=0; x<(Article.length); x++)
{
if(orientation.toLowerCase()=="vertical"){scroller+='<tr>';}
scroller+='<td ';
if(orientation.toLowerCase()=="horizontal"){scroller+='nowrap';} if(stopScroll==1){scroller+=' onMouseOver="stopScroller();" onMouseOut="setWidth()"';}
scroller+='><p>';
if(Article[x][1].toLowerCase()!="none"){scroller+='<a class="rcScroller" href="'+Article[x][1]+'" target="'+Article[x][2]+'" >'+Article[x][0]+'<\/a>';
}else{scroller+=Article[x][0];}
scroller+='</p><\/td>';

if(orientation.toLowerCase()=="vertical"){scroller+='<\/tr>';}

if(scrollerDivider.toLowerCase() != "none"){scroller+='<td nowrap><p>'+scrollerDivider+'<\/p><\/td>';}
}
y++
}
scroller+='<\/tr><\/table><\/div><\/div><\/td><\/tr><\/table>';
}
document.getElementById("boundry").innerHTML=scroller;
setWidth();
}


// Ensure the width of the scroller is divisible by 2. This allows smooth flowing of the scrolled content
function setWidth()
{
tableObj=(isIE)?document.all("table"):document.getElementById("table");
obj=(isIE)?document.all.div1:document.getElementById("div1");
objWidth=(orientation.toLowerCase()=="horizontal")?getOffset(tableObj,"width"):getOffset(tableObj,"height");
HalfWidth=Math.floor(objWidth/2);
newWidth = (HalfWidth*2)+2;
obj.style.width=newWidth
moveLayer(obj, newWidth);

}

// Move the layer by one pixel to the left
function moveLayer(obj, width)
{

maxLeft = (0-(width/2)+2)/2
if(orientation.toLowerCase()=="horizontal"){
obj.style.left=(parseInt(obj.style.left) <= maxLeft)?0:parseInt(obj.style.left)-1
}else{
if(obj.style.top==""){obj.style.top=0;}
// alert(obj.style.top)
if (parseInt(obj.style.top)<(0-(width/2)+6)){
obj.style.top = 0
}else{
obj.style.top = parseInt(obj.style.top)-1
}
}
timer = setTimeout ("moveLayer(obj, "+width+");", 25);
}

// Get width and height of layer
function getOffset(obj, dim)
{
if(dim=="width")
{
oWidth = obj.offsetWidth
return oWidth
}
else if(dim=="height")
{
oHeight = obj.offsetHeight
return oHeight
}
}

function stopScroller()
{
clearTimeout(timer)
}

////// END OF SCRIPT ///////////////////////////////////////////////////////////////////
//-->
</script>


</head>

<body link="#ffffff" alink="#ffffff" vlink="#ffffff" onLoad="loadScroller()">
<script type="text/javascript" language="JavaScript">buildScroller()</script>
<br>
</body>
</html>[/php]
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

To ja nie wiem co jest grane, bo nic mi sie na stronie nie pokazuje... kompletnie nic.... :/
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

moze nie masz takiej tabeli w mysql..
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

Mam taka tabele.
To co mi dałeś to nie działa, ale zrobiłem tak:

Kod: Zaznacz cały

<script type="text/javascript" language="JavaScript">
                                      
Article = new Array;
i=0;

<?
$host = "localhost";
$db_user = "root";
$db_pass = "krasnal";
$db = "united";

$polaczenie = mysql_pconnect($host, $db_user, $db_pass);
if (!$polaczenie)
{
  echo "Nie udało się nawiązać połączenia z serwerem.";
  exit;
}
mysql_select_db($db);

// 1
$sql1 = mysql_query("SELECT * FROM `news` ORDER BY `data` DESC LIMIT 0,1");
$dane1 = mysql_fetch_array($sql1);
$id1 = stripslashes($dane1['id']);
$tytul1 = stripslashes($dane1['tytul']);

echo "Article[i] = new Array (\"$tytul1\", \"http://ricom.co.uk\", \"_blank\");i++";

// 2
$sql2 = mysql_query("SELECT * FROM `news` ORDER BY `data` DESC LIMIT 1,1");
$dane2 = mysql_fetch_array($sql2);
$id2 = stripslashes($dane2['id']);
$tytul2 = stripslashes($dane2['tytul']);

echo "Article[i] = new Array (\"$tytul2\", \"http://ricom.co.uk\", \"_blank\");i++";
?>
Jednak to mi się tez nie wyświetla. A gdy dam jedno tylko (bo w powyższym dałem 2) to nie działa i nic się nie pojawia. Nie wiem dlaczego to nie działa....Chore...
Asit
Zaczyna działać
Zaczyna działać
Posty: 402
Rejestracja: ndz lis 28, 2004 9:17 pm
Kontakt:

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Asit »

[php]$host = "localhost";
$db_user = "root";
$db_pass = "krasnal";
$db = "united";

@ $polaczenie = mysql_pconnect($host, $db_user, $db_pass);
if (!polaczenie)
{
echo "Nie udało się nawišzać połšczenia z serwerem.";
exit;
}
mysql_select_db($db);

$sql = mysql_query("SELECT * FROM `id` ORDER BY `data` DESC LIMIT 0,10");
$ile = mysql_num_rows($sql);

$dane = mysql_fetch_array($sql);
$id = stripslashes($dane['id']);
$tytul = stripslashes($dane['tytul']);


for($a=0; $a<$ile; $a++)
{
echo "tytul = $tytul[$a], id = $id[$a]";
}
[/php]
zobacz czy teraz cos Ci wyswietla.. jesli nic to znaczy ze albo masz inne tabele w mysqlu albo zapisane pod innymi nazwami..
proponuje zobaczyc zawartosc bazy przez phpmyadmin..
Majzer
Posty: 17
Rejestracja: sob wrz 10, 2005 11:00 pm

Re: [JS i PHP] Problem z połączeniem JS z PHP

Post autor: Majzer »

No i nic! Ja nie wiem co jest grane.... :/
ODPOWIEDZ