csv file, ajax, php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cali_dotcom
Forum Commoner
Posts: 49
Joined: Fri Aug 22, 2008 7:28 pm
Location: Rancho Cucamonga, CA

csv file, ajax, php

Post by cali_dotcom »

i'm parsing a csv file with ajax and php, although i think i did everything right, nothing happens when i click on the link.

here is the code:

Code: Select all

 
here is the html:
<div id="brandContainer">
<ul id="brandNav">
<li class="categorypage" id="face"><a href="javascript&#058;showCD('a','brandPage')">A</a></li>
</ul>
<div id="brandPage"></div>
</div>
 
here is the ajax/javascript&#058;
 
var xmlhttp
 
function showCD(str, div)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var url="getbrands.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged(div);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
 
function stateChanged(div)
{
if (xmlhttp.readyState==4)
{
document.getElementById(div).innerHTML=xmlhttp.responseText;
}
}
 
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
 
 
 
and here is the php(getbrands.php):
 
<?php
 
$q=$_GET["q"];
 
$handle = fopen("http://www.totalbeauty.com/resource/lists", "r");
while (($data = fgetcsv($handle, ";;")) !== FALSE) {
    $brands= $data[0];
    }
$brand = explode(",", $brands);
for ($i=0; $i<=count($brand); $i++){
    
    $a=strtolower($brand[$i]);
    $display = "<ul>";
    if ($q = $a[0]){
        $display .= "<li>'".$a."'</li>";
    }
    $display .="</ul>";
    echo $display;
}
 
 
?>
 
 
 

can anyone please tell me what is wrong with this code?
thanks...
Post Reply