merhaba,
joomlada MySQL den veri saylayanan bir modül (kod) yazdık. ancak bu çektiğimiz veriyi ajax ile listelemek istiyoruz. yani sayfa ana sayfa değişmeden sadece çektiğimiz bu veri değişsin veya refresh olsun. kodu aşağıda veriyorum yardımcı olabilir veya yol gösterebilirmisiniz.
kodu çalışır hali: http://mitoloji.info/modules/zeus/zeus.php
sadece sayfalama yapan PHP kodu:
Bu saylama kodunu ajaxla nasıl entegre edip siteme uygulayabilirim?PHP Kodu:<?PHP
// Set flag that this is a parent file
define( '_VALID_MOS', 1 );
chdir ('../..');
include_once( "globals.PHP" );
include_once( "configuration.PHP" );
include_once( "includes/Joomla.PHP" );
include_once( "includes/database.PHP" );
require_once( $mosConfig_absolute_path .'/includes/sef.PHP' );
$option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) );
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$access = !$mainframe->getCfg( 'absolute_path' );
$nullDate = $database->getNullDate();
$now = _CURRENT_SERVER_TIME;
$gid = intval( $my->gid );
$db = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
function sayfalama($limit,$sayfano,$satir_sayisi=0,$sayfaadi='index.PHP',$adresdeger='')
{
$sayfalama = '';
if($satir_sayisi > $limit)
{
$sayfa_sayisi = $satir_sayisi / $limit;
$sayfa_sayisi = ceil($sayfa_sayisi);
if($sayfano == $sayfa_sayisi)
{
$to = $sayfa_sayisi;
} elseif($sayfano == $sayfa_sayisi - 1)
{
$to = $sayfano + 1;
} elseif($sayfano == $sayfa_sayisi - 2)
{
$to = $sayfano + 2;
} else {
$to = $sayfano + 2;
}
if($sayfano < 3)
{
$from = 1;
} else {
$from = $sayfano - 2;
}
if (3 < $sayfano)
$sayfalama .= ' <b><a href="'.$sayfaadi.'?sayfa=1'.$adresdeger.'"><b>1</b></a>..</b> ';
for($i=$from; $i <= $to; $i++)
{
if($i == $sayfano)
{
$sayfalama .= ' <b>['.$i.']</b> ';
} else {
$sayfalama .= ' <a href="'.$sayfaadi.'?sayfa='.$i.$adresdeger.'">'.$i.'</a> ';
}
}
if ($to < $sayfa_sayisi)
{
$sayfalama .= ' <b>..<a href="'.$sayfaadi.'?sayfa='.$sayfa_sayisi.$adresdeger.'"> '.$sayfa_sayisi.'</a></b> ';
}
}
if($sayfalama == "")
{
$sayfalama = 'Sayfa 1';
}
return $sayfalama;
}
///////////////////////////////////////////////////////////////////
/////FONKSİYONU KULLANACAĞIMIZ VERİYİ ALDIĞIMIZ SAYFA//////////////
//AŞAĞIDAKİ AYARLARI KENDİNİZE GÖRE DEĞİŞTİRİNİZ
$limit = 5; // Bir Sayfada Gösterilecek Kayıt Sayısı
$kosul = ''; //Kayıtları Alma Koşulunuz.. Koşul Yoksa Boş Bırakınız...
$tabloadi = 'jos_content';
//Toplam Kayıt Sayısı Alınıyor
$sorgu = mysql_query("SELECT COUNT(*) FROM $tabloadi $kosul");
$satir_sayisi = mysql_result($sorgu, 0);
//Alttaki Ayarlara Dokunmayınız...
@ $sayfa = abs(intval($_GET['sayfa']));
if(empty($sayfa) || $sayfa > ceil($satir_sayisi/$limit))
{
$sayfa = 1;
$baslangic = 0;
} else {
$baslangic = ($sayfa - 1) * $limit;
}
//Veriyi Aldığınız Kodlar.. Kendinize Göre Düzenleyiniz...
$sorgu = mysql_query("SELECT id, title FROM $tabloadi $kosul LIMIT $baslangic,$limit");
echo "<table> ";
while($tablo = mysql_fetch_array($sorgu))
{
$id = $tablo["id"];
$title = $tablo["title"];
$baslik = 30;
// get Itemid
$Itemid = $mainframe->getItemid( $id, 0, 0, $bs, $bc, $gbs );
// Blank itemid checker for SEF
if ($Itemid == NULL) {
$Itemid = '';
} else {
$Itemid = '&Itemid='.$Itemid;
}
$link = sefRelToAbs( 'index.PHP?option=com_content&task=view&id='. $id . $Itemid );
$zink = sefRelToAbs( 'index.PHP?option=com_content&task=view&id='. $zid . $Itemid );
$length=strlen($title);
if ($length > $baslik) $title=substr($title, 0, $baslik).'..';
echo "<tr><td><a href='$link'>$title</a></td></tr>";
}
echo "</table>";
//SAYFA NUMARALARINI YAZDIRAN FONKSİYONUMUZU ÇAĞIRIYORUZ
echo sayfalama($limit,$sayfa,$satir_sayisi,$null,'&islem=1');
?>
üstadım öncelikle verdiğim linkte <div> tagı yok. o link kodu verdiğim sayfalamanın çalışır halidir. emin olabilirsiniz ki buraya yazmadan evvel konuyu iyice araştırdım. yanlız bulduğum veriler hep şu yöndeydi. bir index.HTML bir adet veri.PHP ve ajax.js dosyası. evet bu üçlü ile mysqlden veri çekip onları ajaxla listelemek kolay. mesela hemen yaptığım bir örneği aktarayım http://mitoloji.info/resim/zeus/index.php ama benim anlatmak istediğim işde bu değil. bu linktede 3 dosya ile çekiyorum. sorun şu bu 3 lü ile çektiğim veri Joomla sitemin SEO linkini yakayalamıyor ve linkler normal adres satırı olarak gözüküyor. bunun olmaması için bu dosyaları modül haline getirip joomlaya yüklemem gerek. fakat Joomla modüllerinin başındakodu olma zorunluluğu nedeniyle veri.PHP den çektiğim veriyi index.PHP de <div> tagı içerisinde göstermeye kalkında otomatikman "Direct Access to this location is not allowed" hatası alıyorum çünkü dosya dışarıdan çağıralamıyor sistem gereği.PHP Kodu:defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
bu nedenlerle tüm bu işlemleri yani; veri çekmeyi, yazdırmayı ve hatta mümkünse scripti aynı dosyadan çağırmak istiyorum. fakat bunu başaramadım ve sizden bu nedenle yardım yada yol göstermenizi rica etmekteyim.
dilerim anlatabilmişimdir. ilginize teşekkür ederim
iyi çalışmalar.
Joomla da modül olarak tanıtmana gerek yok. onun yerine joomlada boş bir modül oluştur ve ajax veya JavaScript ile bu dosyayı çağır. linkleride ona göre ayarlarsan sorun olmayacaktır.
joomlada boş modül açıp veriyi ordan include ile çağırırsam dediğiniz gibi sayfa geliyor fakat Joomla artionun SEO linkleri gözükmüyor. örneklersem linkler http://mitoloji.info/yunan-mitolojisi/pandora.nedir yerine http://mitoloji.info/content/view/2402/32/ gibi gözüküyor. bu nedenle aynı dosyadan hem veri çekip hem ajaxla sayfalamak istiyorum. modül kendisi veriyi çağırırsa linklerde sorun yok ama dediğiniz gibi boş modül açıp dışardan veri çağırdığımda linklerde maalesef sorun oluşuyor.
yada soruyo şu şekilde sorayım. elimde bi ajax.js , veri.PHP ve index.HTML var. bu üçlü ile ajax saylamayı zaten yapıyorum. ama bu üçlüyü tek dosyada toplam istiyorum.
ajax.js dosyasının içinde veri.PHP yi çağıran şöyle bir kod var.
burdaki veri.PHP çağırmak yerine bu ajax.js yi veri.PHP nin içine nasıl entegre edip sayfa çağırmadan aynı sayfadan nasıl veriyi döndürmesini sağlayabilirim.?PHP Kodu:
veri.PHP kodu aşağıda
PHP Kodu:<?PHP
// Set flag that this is a parent file
define( '_VALID_MOS', 1 );
chdir ('../..');
include_once( "globals.PHP" );
include_once( "configuration.PHP" );
include_once( "includes/Joomla.PHP" );
include_once( "includes/database.PHP" );
require_once( $mosConfig_absolute_path .'/includes/sef.PHP' );
$option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) );
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$access = !$mainframe->getCfg( 'absolute_path' );
$nullDate = $database->getNullDate();
$now = _CURRENT_SERVER_TIME;
$gid = intval( $my->gid );
$db = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
function sayfalama($limit,$sayfano,$satir_sayisi=0,$sayfaadi='index.PHP',$adresdeger='')
{
$sayfalama = '';
if($satir_sayisi > $limit)
{
$sayfa_sayisi = $satir_sayisi / $limit;
$sayfa_sayisi = ceil($sayfa_sayisi);
if($sayfano == $sayfa_sayisi)
{
$to = $sayfa_sayisi;
} elseif($sayfano == $sayfa_sayisi - 1)
{
$to = $sayfano + 1;
} elseif($sayfano == $sayfa_sayisi - 2)
{
$to = $sayfano + 2;
} else {
$to = $sayfano + 2;
}
if($sayfano < 3)
{
$from = 1;
} else {
$from = $sayfano - 2;
}
if (3 < $sayfano)
$sayfalama .= ' <b><a href="'.$sayfaadi.'?sayfa=1'.$adresdeger.'"><b>1</b></a>..</b> ';
for($i=$from; $i <= $to; $i++)
{
if($i == $sayfano)
{
$sayfalama .= ' <b>['.$i.']</b> ';
} else {
$sayfalama .= ' <a href="'.$sayfaadi.'?sayfa='.$i.$adresdeger.'">'.$i.'</a> ';
}
}
if ($to < $sayfa_sayisi)
{
$sayfalama .= ' <b>..<a href="'.$sayfaadi.'?sayfa='.$sayfa_sayisi.$adresdeger.'"> '.$sayfa_sayisi.'</a></b> ';
}
}
if($sayfalama == "")
{
$sayfalama = 'Sayfa 1';
}
return $sayfalama;
}
///////////////////////////////////////////////////////////////////
/////FONKSİYONU KULLANACAĞIMIZ VERİYİ ALDIĞIMIZ SAYFA//////////////
//AŞAĞIDAKİ AYARLARI KENDİNİZE GÖRE DEĞİŞTİRİNİZ
$limit = 5; // Bir Sayfada Gösterilecek Kayıt Sayısı
$kosul = ''; //Kayıtları Alma Koşulunuz.. Koşul Yoksa Boş Bırakınız...
$tabloadi = 'jos_content';
//Toplam Kayıt Sayısı Alınıyor
$sorgu = mysql_query("SELECT COUNT(*) FROM $tabloadi $kosul");
$satir_sayisi = mysql_result($sorgu, 0);
//Alttaki Ayarlara Dokunmayınız...
@ $sayfa = abs(intval($_GET['sayfa']));
if(empty($sayfa) || $sayfa > ceil($satir_sayisi/$limit))
{
$sayfa = 1;
$baslangic = 0;
} else {
$baslangic = ($sayfa - 1) * $limit;
}
//Veriyi Aldığınız Kodlar.. Kendinize Göre Düzenleyiniz...
$sorgu = mysql_query("SELECT id, title FROM $tabloadi $kosul LIMIT $baslangic,$limit");
echo "<table> ";
while($tablo = mysql_fetch_array($sorgu))
{
$id = $tablo["id"];
$title = $tablo["title"];
$baslik = 30;
// get Itemid
$Itemid = $mainframe->getItemid( $id, 0, 0, $bs, $bc, $gbs );
// Blank itemid checker for SEF
if ($Itemid == NULL) {
$Itemid = '';
} else {
$Itemid = '&Itemid='.$Itemid;
}
$link = sefRelToAbs( 'index.PHP?option=com_content&task=view&id='. $id . $Itemid );
$zink = sefRelToAbs( 'index.PHP?option=com_content&task=view&id='. $zid . $Itemid );
$length=strlen($title);
if ($length > $baslik) $title=substr($title, 0, $baslik).'..';
echo "<tr><td><a href='$link'>$title</a></td></tr>";
}
echo "</table>";
//SAYFA NUMARALARINI YAZDIRAN FONKSİYONUMUZU ÇAĞIRIYORUZ
echo sayfalama($limit,$sayfa,$satir_sayisi,$null,'&islem=1');
?>
var url="http://mitoloji.info/resim/zeus/getuser.PHP"
url=url+"?p="+str
url=url+"&t=con"
url=url+"&sid="+Math.random()
yerine
?p=+str
&t=nav
&sid=+Math.random()
yapmakla kodu çalıştıramadım aşağıdaki gibi denedim acaba aşağıdaki tabloda bir mantık hatası mı yapıyorum.? yoksa değiştirdiğim kod kısmındamı bir sorunum var. yardımcı olabilecek kimse yok mu?
PHP Kodu:<?PHP
/*
This page will go out to a database, and grab a selection of rows.
Because we dont want to display hundreds of rows at a time we will
create dynamic paging.
*/
//############################################
//First get the page value passed to this page
$pageNum='1';
if (isset($_GET["p"])) {
$pageNum=$_GET["p"];
}
$type='';
if (isset($_GET["t"])) {
$type=$_GET["t"];
}
$tablename= 'jos_content';
$zid= '62';
#=This is the number of rows to display per page (results per page)
$RPP= '5';
#=Images for the next and back button
$PrevIc= "images/bprv.gif";
$FirstIc= "images/bfrst.gif";
$NextIc= "images/bnxt.gif";
$LastIc= "images/blst.gif";
$dPrevIc= "images/dprv.gif";
$dFirstIc= "images/dfrst.gif";
$dNextIc= "images/dnxt.gif";
$dLastIc= "images/dlst.gif";
define( '_VALID_MOS', 1 );
require_once('../../configuration.PHP');
require_once($mosConfig_absolute_path.'/includes/Joomla.PHP');
require_once($mosConfig_absolute_path.'/includes/database.PHP');
require_once($mosConfig_absolute_path.'/includes/sef.PHP');
global $database, $my;
$option = strval( strtolower( mosGetParam( $_REQUEST, 'option' ) ) );
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();
$access = !$mainframe->getCfg( 'absolute_path' );
$nullDate = $database->getNullDate();
$now = _CURRENT_SERVER_TIME;
$gid = intval( $my->gid );
$db = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
//############################################
//Get a quick count of all the rows
$querys = "SELECT COUNT(*) AS numrows FROM $tablename WHERE created_by=62 ORDER BY created DESC";
$results = mysql_query($querys) or die('Error, query failed');
$row = mysql_fetch_array($results, MYSQL_ASSOC);
$num = $row['numrows'];
mysql_query("set names 'utf8'");
//############################################
//If there are some rows then start the pagination
if ($num>0) {
//Determine the maxpage and the offset for the query
$maxPage = ceil($num/$RPP);
$offset = ($pageNum - 1) * $RPP;
//Initiate the navigation bar
$nav = '';
//get low end
$page = $pageNum-3;
//get upperbound
$upper =$pageNum+3;
if ($page <=0) {
$page=1;
}
if ($upper >$maxPage) {
$upper =$maxPage;
}
//Make sure there are 7 numbers (3 before, 3 after and current
if ($upper-$page <6){
//We know that one of the page has maxed out
//check which one it is
//echo "$upper >=$maxPage<br>";
if ($upper >=$maxPage){
//the upper end has maxed, put more on the front end
//echo "to begining<br>";
$dif =$maxPage-$page;
//echo "$dif<br>";
if ($dif==3){
$page=$page-3;
}elseif ($dif==4){
$page=$page-2;
}elseif ($dif==5){
$page=$page-1;
}
}elseif ($page <=1) {
//its the low end, add to upper end
//echo "to upper<br>";
$dif =$upper-1;
if ($dif==3){
$upper=$upper+3;
}elseif ($dif==4){
$upper=$upper+2;
}elseif ($dif==5){
$upper=$upper+1;
}
}
}
if ($page <=0) {
$page=1;
}
if ($upper >$maxPage) {
$upper =$maxPage;
}
//These are the numbered links
for($page; $page <= $upper; $page++) {
if ($page == $pageNum){
//If this is the current page then disable the link
$nav .= " <font color='red'>$page</font> ";
}else{
//If this is a different page then link to it
$nav .= " <a onclick='showPage(\"".$page."\")'>$page</a> ";
}
}
//These are the button links for first/previous enabled/disabled
if ($pageNum > 1){
$page = $pageNum - 1;
$prev = "<img border='0' src='$PrevIc' onclick='showPage(\"".$page."\")'> ";
$first = "<img border='0' src='$FirstIc' onclick='showPage(\"1\")'> ";
}else{
$prev = "<img border='0' src='$dPrevIc' > ";
$first = "<img border='0' src='$dFirstIc' > ";
}
//These are the button links for next/last enabled/disabled
if ($pageNum < $maxPage AND $upper <= $maxPage) {
$page = $pageNum + 1;
$next = " <img border='0' src='$NextIc' onclick='showPage(\"".$page."\")'>";
$last = " <img border='0' src='$LastIc' onclick='showPage(\"".$maxPage."\")'>";
} else {
$next = " <img border='0' src='$dNextIc' >";
$last = " <img border='0' src='$dLastIc' >";
}
if ($maxPage>1 AND $type=='nav') {
// print the navigation link
echo $first . $prev . $nav . $next . $last;
}elseif ($maxPage>1 AND $type=='con') {
//Build the header
echo "<table>";
echo " <tr>";
echo " <th></th>";
echo " <th></th>";
echo " </tr>";
//Get all the rows
$query="SELECT * FROM $tablename WHERE created_by=62 ORDER BY hits DESC LIMIT $offset, $RPP";
$result=mysql_query($query) or die('Failed selecting applications: ' . mysql_error());
$num=mysql_numrows($result);
//Echo each row
while($row = mysql_fetch_array($result)) {
// get Itemid
$Itemid = $mainframe->getItemid( $id, 0, 0, $bs, $bc, $gbs );
// Blank itemid checker for SEF
if ($Itemid == NULL) {
$Itemid = '';
} else {
$Itemid = '&Itemid='.$Itemid;
}
$link = sefRelToAbs( 'index.PHP?option=com_content&task=view&id='. $row['id'] . $row['Itemid'] );
echo "<tr><td>";
echo "<a href='$link'>" . $row['title'] . "</a>";
echo "</td></tr>";
}
//Close table
echo "</table>";
}else{
echo "Table doesn't contain records.";
}
}
//Close the db connection
mysql_close();
?>
<HTML>
<head>
<!-- Import external files -->
<link rel='stylesheet' type='text/CSS' href='main.CSS'>
<script>//Global vars to hold connection to web pages
var xmlHttp
var xmlHttp2
function showPage(str) {
//Function that gets called
//Currently we only call one other sub, but this could change
showStates(str)
}
function showStates(str) {
//This sub will populate a table with all the states and get the
//pagination built
//Make the ajax connection for both the navigation and content
xmlHttp=GetXmlHttpObject()
xmlHttp2=GetXmlHttpObject()
//If we cant do the request error out
if (xmlHttp==null || xmlHttp2==null ) {
alert ("Browser does not support HTTP Request")
return
}
//First build the navigation panel
?p=+str
&t=nav
&sid=+Math.random()
//Once the page finished loading put it into the div
xmlHttp2.onreadystatechange=navDone
//Get the PHP page
xmlHttp2.open("GET",url,true)
xmlHttp2.send(null)
//Build the url to call
//Pass variables through the url
?p=+str
&t=con
&sid=+Math.random()
//Once the page finished loading put it into the div
xmlHttp.onreadystatechange=stateChanged
//Get the PHP page
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function navDone() {
//IF this is getting called when the page is done loading then fill the pagination div
if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete") {
//Update the div tag with the outputted text
document.getElementById("pgNavigation").innerHTML=xmlHttp2.responseText
}
}
function stateChanged() {
//IF this is getting called when the page is done loading the states then output the div
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//Update the div tag with the outputted text
document.getElementById("pgContent").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject() {
//Determine what browser we are on and make a httprequest connection for ajax
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
//internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
//Onload start the user off on page one
window.onload = showPage("1");</script>
</head>
<body>
<!-- Create Content Holders -->
<p>
<div id="pgNavigation"><b>Yükleniyor...</b><img border="0" src="images/ajax-loader.gif"></div>
<div id="pgContent"><b>Yükleniyor...</b><img border="0" src="images/ajax-loader.gif"></div>
</p>
</body>
</HTML>