Confusion about AJAX and OOP php5 code

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
christus
Forum Newbie
Posts: 5
Joined: Wed Jun 06, 2007 2:03 pm

Confusion about AJAX and OOP php5 code

Post by christus »

Okay, I've been trying to build a (relatively) simple ajax app that simply returns values when someone types in a box. There are five files that I use to build this functionality. I'll post the snippets from each file that serve the functionality:

From startPage.php:

Code: Select all

<form> 
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>

<p>Suggestions: <span id="txtHint"></span></p>
This goes to the javascript file, which I know is in working order; it returns a value to the html page.

The javascript file references search.ajax.php, which executes this code (a snippet of the main code):

Code: Select all

<?php
$sqlDb->query("query is here");
	
	$ajax = new ajaxScript;
	
	$array = $sqlDb->parseArraySingleField("name");
	$count = $sqlDb->countParseArraySingle("name");
	
//get the q parameter from URL
	$query = $ajax->setParamFromUrl("query");
	
	echo $ajax->returnArrayValuesAsString($array, $query, $count);
?>
I know the query works. This file references two class files, with the following functionality:
ajax.class.php:

Code: Select all

<?php
	include "mssql.class.php";
	
	class ajaxScript {
	
	//get the q parameter from URL
		function setParamFromUrl($param) {
			$get = $_GET[$param];
			return $get;
		}
		
		function returnArrayValuesAsString($array, $query, $count) {
	
			if (strlen($query) > 0) {
  				$hint = "";
				//$hint = "$array[0]";
				//$hint = "$count";
				$count = 30;

  				for($i=0; $i < $count; $i++) {
  					if (strtolower($query) == strtolower(substr($array[$i], 0, strlen($query)))) {
    					if ($hint == "") {
     						$hint = $array[$i];
      					} else {
      						$hint = $hint." , ".$array[$i];
      					}
    				}
  				}
  				
  				if ($hint == "") {
					$response = "no user by this login";
				} else {
					$response = $hint;
				}
			}
			
			return $response;
		}
	}
?>
and mssql.class.php (all class mssql)

Code: Select all

function parseArraySingleField($field) {
			$counter = 0;
			while ($results = $this->fetchArray()) {
				$array[$counter] = $results[$field];
				$counter++;
				
			}
			return $array;
		}
		
		function countParseArraySingle($field) {
			$counter = 0;
			while ($results = $this->fetchArray()) {
				$array[$counter] = $results[$field];
				$counter++;
			}
			return $counter;
		}
All I get is "no user by this login" I'm completely stumped as to what I'm doing wrong here... I'm about to go insane! I've been trying to figure it out for the past day or so. I know this is a long post, but if someone could help me, I would be extremely grateful. I hope I included enough information. Thank you in advance.

Jimmy
Last edited by christus on Wed Jun 20, 2007 10:17 am, edited 2 times in total.
christus
Forum Newbie
Posts: 5
Joined: Wed Jun 06, 2007 2:03 pm

Re: Confusion about AJAX and OOP php5 code

Post by christus »

Accidentally posted twice
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

what is the purpose of this line:

Code: Select all

if (strtolower($query) == strtolower(substr($array[$i], 0, strlen($query)))) {
?
Post Reply