Irish SEO,  Marketing & Webmaster Discussion

 
Web based billing for freelancers

PHP/AJAX based display problem.

This is a discussion on PHP/AJAX based display problem. within the Coding Help forums, part of the Webmaster Help category; Heres exactly what i'm trying to do, i'm trying to modify the script you gave me a hand with a ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2008, 11:21 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default PHP/AJAX based display problem.

Heres exactly what i'm trying to do, i'm trying to modify the script you gave me a hand with a while ago(louie) which populated a second select field based on the first select field, now im trying to display results on a page based on what link option chosen but with the url not changing so it stays as /releases.htm.
I'm completely stumped!

first page:
PHP Code:
<?php
include('***');

if(isset(
$_GET['stype']))
{
    
$stype $_GET['stype'];
}
else
{
    
$stype "all";
}

dbConnect();
echo
'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>releases'
.get_prop("site_title_name").'</title>
<script type="text/javascript" language="javascript">

var loading_img = \'images/loading.gif\';
var loading_msg = \' Loading Data...\';

var xmlhttp_obj = false;
function ie_xmlhttp() {
    if (window.XMLHttpRequest) {
        xmlhttp_obj = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            
            }
        }
    } else {
        xmlhttp_obj = false;
    }
    return xmlhttp_obj;
}
function getcontent(url,containerid) {
    var xmlhttp_obj = ie_xmlhttp();
    document.getElementById(containerid).innerHTML = \'<img src="\'+loading_img+\'"/>\'+loading_msg;
    xmlhttp_obj.onreadystatechange=function() {
        loadpage(xmlhttp_obj,containerid);
    }
    xmlhttp_obj.open(\'GET\',url,true);
    xmlhttp_obj.send(null);
}
function loadpage(xmlhttp_obj,containerid) {
    if (xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200) {
        document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
    }
}
//]]>
</script>

</head>'
;
site_header();  
$rowsPerPage 10;
        
// by default we show first page
        
$pageNum 1;
        
// if $_GET['page'] defined, use it as page number
        
if(isset($_GET['page']))
        {
            
$pageNum $_GET['page'];
        }
        
$offset = ($pageNum 1) * $rowsPerPage;

        
$numrows row_count_releases();
                                        
        
// how many pages we have when using paging?
        
$maxPage ceil($numrows/$rowsPerPage);

        
// print the link to access each page
        
$self $_SERVER['PHP_SELF'];
        
$nav '';
        for(
$page 1$page <= $maxPage$page++)
        {
            if (
$page == $pageNum)
            {
                
$nav .= " [$page] ";   // no need to create a link to current page
            
}
            else
            {
                
$nav .= " <a href=\"../releases/".$page.".htm\">$page</a> ";
            }        
        }                                
        
// creating previous and next link
        // plus the link to go straight to
        // the first and last page

        
if ($pageNum 1)
        {
            
$page $pageNum 1;
             
$prev " <a href=\"$self?page=$page\">[Prev]</a> ";
    
            
$first " <a href=\"$self?page=1\">[First Page]</a> ";
        } 
        else
        {
             
$prev  '&nbsp;'// we're on page one, don't print previous link
            
$first '&nbsp;'// nor the first page link
        
}

        if (
$pageNum $maxPage)
        {
            
$page $pageNum 1;
            
$next " <a href=\"$self?page=$page\">[Next]</a> ";
    
              
$last " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
        } 
        else
        {
               
$next '&nbsp;'// we're on the last page, don't print next link
            
$last '&nbsp;'// nor the last page link
        
}
        if((isset(
$_GET['page'])) && ($_GET['page'] > 0) && ($_GET['page'] <= $maxPage) && (is_numeric($_GET['page']) == true))
        {
            echo
'<div id="releases_listing_item_wrapper_main">
                <span id="span1">
                    
                </span>
            </div>
            <div id="releases_listing_item_selection_type">
                <div id="releases_listing_item_selection_type_title">»&nbsp;search options</div>
                <div id="releases_listing_item_selection_type_options_text">alphabet</div>
                <div id="releases_listing_item_selection_type_options_body">
                    <a href="releases/1-a.htm">a</a>&nbsp;
                    <a href="releases/1-b.htm">b</a>&nbsp;
                    <a href="releases/1-c.htm">c</a>&nbsp;
                    <a href="releases/1-d.htm">d</a>&nbsp;
                    <a href="releases/1-e.htm">e</a>&nbsp;
                    <a href="releases/1-f.htm">f</a>&nbsp;
                    <a href="releases/1-g.htm">g</a>&nbsp;
                    <a href="releases/1-h.htm">h</a>&nbsp;
                    <a href="releases/1-i.htm">i</a>&nbsp;
                    <a href="releases/1-j.htm">j</a>&nbsp;
                    <a href="releases/1-k.htm">k</a>&nbsp;
                    <a href="releases/1-l.htm">l</a>&nbsp;
                    <a href="releases/1-m.htm">m</a>&nbsp;
                    <a href="releases/1-n.htm">n</a>&nbsp;
                    <a href="releases/1-o.htm">o</a>&nbsp;
                    <a href="releases/1-p.htm">p</a>&nbsp;
                    <a href="releases/1-q.htm">q</a>&nbsp;
                    <a href="releases/1-r.htm">r</a>&nbsp;
                    <a href="releases/1-r.htm">s</a>&nbsp;
                    <a href="releases/1-t.htm">t</a>&nbsp;
                    <a href="releases/1-u.htm">u</a>&nbsp;
                    <a href="releases/1-v.htm">v</a>&nbsp;
                    <a href="releases/1-w.htm">w</a>&nbsp;
                    <a href="releases/1-x.htm">x</a>&nbsp;
                    <a href="releases/1-y.htm">y</a>&nbsp;
                    <a href="releases/1-z.htm">z</a>&nbsp;
                </div>
            </div>
            <div id="pagation_wrapper"><div class="pagation_link">Page: '
.$nav.'</div></div>
</div>
                </div>
            </div>'
;
site_footer();
closeConnect();
?>
And i have the other page like so:
PHP Code:
<?php
include('db.php');
dbConnect();

$txt "";

$qs $_GET['stype'] !=  "" preg_replace("#[^0-9]#","",$_GET['stype']) : "1"//I use preg_replace to sanitse the get request

//which in this case must be numbers

//this is manually created but it can easily populated froma database

if($qs != "")
{
    
$k 0;
    
$sql mysql_query("SELECT id,name FROM releases ORDER BY name ASC LIMIT ".$offset.",".$rowsPerPage."");
    while(
$row mysql_fetch_array($sql))
    {
        
$link_name preg_replace('#[^a-zA-Z0-9]+#','-',$row['name']);
        
$i 0;
        
$j $k 1;    
        echo
'<div class="releases_listing_item_wrapper" style="background-color:#'.check_bk_colour($k).';">
            <div class="releases_listing_item_name"><div class="releases_item_front_link_'
.$j.'"><a href="game-details/'.$row['id'].'-'.$link_name.'.htm">'.$row['name'].'<a/></div></div>
        </div>
        '
;
        if(
$k == 0)
        {
$k=1;}
        else
        {
$k=0;}
    }        
}

closeConnect();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-03-2008, 11:28 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

modify the link like this:

PHP Code:
//..........
echo'<div class="releases_listing_item_wrapper" style="background-color:#'.check_bk_colour($k).';">
            <div class="releases_listing_item_name"><div class="releases_item_front_link_'
.$j.'"><a href="game-details/'.$row['id'].'-'.$link_name.'.htm" onclick="getcontent(\"game-details/'.$row['id'].'-'.$link_name.'.htm\",\"divid\");return false;">'.$row['name'].<a/></div></div>
        </
div>
//.......... 
__________________
:. Web Design & Development Web Design Ireland
:. Search Engines Optimization Search Engines Optimization
:. Directory Submission Directory Submission
:. News & Press Release Ireland GiveItSocks.com
:. Used Cars Ireland, Car Parts & Car Audio Cars For Sale, Car Parts & Accessories
:. I Have 2 Find It Directory SEF Directory
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 05-03-2008, 12:08 AM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Ok, i've gone back to basic and created a test page to get it working first, so far its working fine like below, only problem now is that for every letter of the alphabet i will need a new sql query on page 2 which isn't efficient, i was thinking of DB table with all the numbers in it referenced to the letter?

Page 1:
PHP Code:
<html>
<head>
<title></title>

<script type="text/javascript" language="javascript">

var loading_img = 'images/loading.gif';//set image path

var loading_msg = ' Loading Data...';//set loading message

var xmlhttp_obj = false;//create the XMLHttpRequest
function test_xmlhttp(){

 if (window.XMLHttpRequest){ // if Mozilla, Safari etc

  xmlhttp_obj = new XMLHttpRequest();

 }else if (window.ActiveXObject){ // if IE

  try{

   xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");

  }catch (e){

   try{

    xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");

   }catch (e){

   }

  }

 }else{

  xmlhttp_obj = false;

 }

 return xmlhttp_obj;

}   //get content via GET

function getcontent(url, containerid){

 var xmlhttp_obj = test_xmlhttp();

 document.getElementById(containerid).innerHTML = '<img src="' + loading_img + '" />' + loading_msg;

 xmlhttp_obj.onreadystatechange=function(){

         loadpage(xmlhttp_obj, containerid);

         }

 xmlhttp_obj.open('GET', url, true);

 xmlhttp_obj.send(null);

}     

function loadpage(xmlhttp_obj, containerid){

 if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 ){

  document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;

 }

}
//]]>
</script>

</head>

<body>

<form name="select_m" id="select_m" action="<?php echo $_SERVER['REQUEST_URI']."?".$_SERVER['QUERY_STRING'];?>" method="get">   

<select name="sel1" id="sel1" onchange="getcontent('page2.php?sel1='+this.value, 'span1');">

    <option value="">select…</option>
    <option value="1">all</option>
    <option value="2">a</option>
    <option value="3">c</option>
    <option value="4">t</option>

   </select>

   <span id="span1">

   <?php

   
include_once("page2.php"); 

   
//this is the page that will create the second select menu

   
?>   

   </span> 

  </form>

</body>
</html>
Page 2:
PHP Code:
<?php
include('../sys_config/db.php');

dbConnect();

$txt "";

$qs $_GET['sel1'] != "" preg_replace("#[^0-9]#","",$_GET['sel1']) : "1";//I use preg_replace to sanitze the get request

//which in this case must be numbers

//this is manually created but it can be easily populated from a database

if($qs != ""){

if(
$qs == "1"){
    
$sql mysql_query("SELECT name FROM releases WHERE date >='".date("Y-m-d")."' ORDER BY date ASC, name ASC");
    while(
$row mysql_fetch_array($sql))
    {
        echo 
$row['name'].'<br>';
    }

 }elseif(
$qs == "2"){
    
$sql mysql_query("SELECT name FROM releases WHERE date >='".date("Y-m-d")."' AND name LIKE 'a%' ORDER BY date ASC, name ASC");
    while(
$row mysql_fetch_array($sql))
    {
        echo 
$row['name'].'<br>';
    }
 }

 echo 
$txt;

}

closeConnect();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 05-03-2008, 12:38 AM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Think i got the multiple queries sorted with this code, seems to work fine.
PHP Code:
<?php
include('****');

dbConnect();

$txt "";

$qs $_GET['sel1'] != "" preg_replace("#[^0-9]#","",$_GET['sel1']) : "1";

if(
$qs != ""){
    if(
$qs == "1") {
         
$sql mysql_query("SELECT name FROM releases WHERE date >='".date("Y-m-d")."' ORDER BY date ASC, name ASC");
        while(
$row mysql_fetch_array($sql))
         {
            echo 
$row['name'].'<br>';
         }
    }
    else {
        
$letter get_search_letter($qs);
        
$sql mysql_query("SELECT name FROM releases WHERE date >='".date("Y-m-d")."' AND name LIKE '".$letter."%' ORDER BY date ASC, name ASC");
        while(
$row mysql_fetch_array($sql))
         {
            echo 
$row['name'].'<br>';
        }
    }
}

function 
get_search_letter($qs) {
    
$sql mysql_query("SELECT letter FROM search_letter WHERE num = ".$qs." AND type = 'releases' LIMIT 1");
    while(
$row mysql_fetch_array($sql))
     {
        return 
$row['letter'];
     }
}

closeConnect();
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 05-03-2008, 09:01 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

I'm having a problem using links instead of the select box to select from, i have thiis code, but it doesn't work:

PHP Code:
<a href="releases.htm"  onchange="ignie_getcontent('sys_config/getReleases.php?sel1='+this.value, 'span1');">a</a>
<
a href="releases.htm"  onchange="ignie_getcontent('sys_config/getReleases.php?sel1='+this.value, 'span1');">b</a
Is it even possible to use this way to select the data thats populated on screen?

Last edited by ziycon; 05-03-2008 at 09:08 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 05-03-2008, 09:32 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,048
Nominated 5 Times in 3 Posts
Nominated TOTW/F/M Award(s): 1
louie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enoughlouie will become famous soon enough
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

of course it is.
change the "onchange" to "onclick" and ad after ";" return false; to void the click on the link itself.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 06-03-2008, 12:39 AM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Tried this, its reloading the 'span' but doesn't seem to have a value for it?
PHP Code:
<a href="releases.htm"  onclick="ignie_getcontent('sys_config/getReleases.php?sel1='+this.value, 'span1'); return false;">a</a>
                    <
a href="releases.htm"  onclick="ignie_getcontent('sys_config/getReleases.php?sel1='+this.value, 'span1'); return false;">b</a
Instead of '+this.value' do i have to hardcode a value for each link like this?
PHP Code:
<a href="releases.htm"  onclick="ignie_getcontent('sys_config/getReleases.php?sel1=a', 'span1'); return false;">a</a
EDIT:
Got it working by adding in a,b,c etc to a new link.

Last edited by ziycon; 06-03-2008 at 12:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 06-03-2008, 08:42 AM
louie's Avatar
Senior Member