Autor Zpráva
slovakCZ
Profil
Zdravim Vas,

resim problem s autodoplnovanim. Nejdrive uvedu zdorjove soubory a kody a ke po nich az dotaz + obrazek uplne dole. zaklad jsem si stahl z:
Ukazka - vpiste neco do inputu na strance

a nyni mam v kodu toto:
<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript">
	function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
			$('#query').show();
			$('#strankovani').show();
		} else {    
			$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#query').hide();
					$('#strankovani').hide();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup               
	    
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 999200);
	}
</script>


v html pote (divy kam se ma zobrazovat vysledek v kodu neuvadim, to neni tak podstatne, jde spis o princip):
<form>
  <fieldset class="filtrovat"> 
      <legend>Filtrovat podle:</legend> 
      <label>
        <select name="option" > 
          <option value="nick">Uživatelského jména</option>
          <option value="cas">Poslední přihlášení</option>
        </select>
      </label>
        <br> 
      <input class="box-medium" type="text" size="30" value="" id="inputString" onkeyup="lookup(this.value);" onblur="fill();"></td></tr> 
  </fieldset>
</form>


no a stranka rpc.php vypada takto:
<?php	
	// PHP5 Implementation - uses MySQLi.
	// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
	$db = new mysqli('localhost', 'root' ,'', 'rs');
	
	if(!$db) {
		// Show error if we cannot connect.
		echo 'ERROR: Could not connect to the database.';
	} else {
		// Is there a posted query string?
		if(isset($_POST['queryString'])) {
			$queryString = $db->real_escape_string($_POST['queryString']);
			
			// Is the string length greater than 0?
			
			if(strlen($queryString) >0) {
				// Run the query: We use LIKE '$queryString%'
				// The percentage sign is a wild-card, in my example of countries it works like this...
				// $queryString = 'Uni';
				// Returned data = 'United States, United Kindom';
				
				// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
				// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
				
				$query = $db->query("SELECT * FROM users WHERE nick LIKE '%$queryString%' LIMIT 10");
				if($query) {
				
					// While there are results loop through them - fetching an Object (i like PHP5 btw!).
					while ($result = $query ->fetch_object()) {
						// Format the results, im using <li> for the list, you can change it.
						// The onClick function fills the textbox with the result.
						
						// YOU MUST CHANGE: $result->value to $result->your_colum
	         			//echo '<li onClick="fill(\''.$result->nick.'\');">'.$result->nick.'</li>';
	         			
	         			echo "".$result->nick."";
	         		}
				} else {
					echo 'ERROR: There was a problem with the query.';
				}
			} else {
				// Dont do anything.
			} // There is a queryString.
		} else {
			echo 'There should be no direct access to this script!';
		}
	}
?>


A o co se mi vlatne jedna? Kdyz se kouknete na HTML tak vidite nejaky select a nejaky input.. nyni, kdyz do inputu vlozim nejake slovo (pismeno nebo znak) tak se provede:
SELECT * FROM users WHERE nick LIKE '%$queryString%' LIMIT 10

ovsem ten select tam mam proto, ze bych rad rozlisil v jakem sloupci hledat.. v mem pripade mam select:
- uzivatelske jmeno (name=nick)
- posledni prihlaseni (name=cas)
potrebuji tedy upravit javascript tak, aby spolu s hodnotou inputu odesilal i jmeno selectu (bud nick nebo cas), ktery si pote doplnim do:
SELECT * FROM users WHERE ".$OdeslanyNazevSelectu." LIKE '%$queryString%' LIMIT 10


takze vysledny PHP kod by mohl vypadat nejak takto (zmena na 11.,13.,26.radku):
<?php	
	// PHP5 Implementation - uses MySQLi.
	// mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
	$db = new mysqli('localhost', 'root' ,'', 'rs');
	
	if(!$db) {
		// Show error if we cannot connect.
		echo 'ERROR: Could not connect to the database.';
	} else {
		// Is there a posted query string?
		if(isset($_POST['queryString']) AND isset($_POST['queryName'])) {
			$queryString = $db->real_escape_string($_POST['queryString']);
			$queryName = $db->real_escape_string($_POST['queryName']);
			
			// Is the string length greater than 0?
			
			if(strlen($queryString) >0) {
				// Run the query: We use LIKE '$queryString%'
				// The percentage sign is a wild-card, in my example of countries it works like this...
				// $queryString = 'Uni';
				// Returned data = 'United States, United Kindom';
				
				// YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
				// eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
				
				$query = $db->query("SELECT * FROM users WHERE ".$queryName." LIKE '%$queryString%' LIMIT 10");
				if($query) {
				
					// While there are results loop through them - fetching an Object (i like PHP5 btw!).
					while ($result = $query ->fetch_object()) {
						// Format the results, im using <li> for the list, you can change it.
						// The onClick function fills the textbox with the result.
						
						// YOU MUST CHANGE: $result->value to $result->your_colum
	         			//echo '<li onClick="fill(\''.$result->nick.'\');">'.$result->nick.'</li>';
	         			
	         			echo "".$result->nick."";
	         		}
				} else {
					echo 'ERROR: There was a problem with the query.';
				}
			} else {
				// Dont do anything.
			} // There is a queryString.
		} else {
			echo 'There should be no direct access to this script!';
		}
	}
?>


Predem dekuji za pomoc

a jeste ilustracni obrazek pro uplne pochopeni
slovakCZ
Profil
nejak jsem se do toho zamotal :( tady podle tohoto prikladu:
http://www.danvega.org/examples/jquery/select.htm
se mi povedlo vybrat value daneho selectu.. ovsem nedokazu ho predat dal na php stranku :(
slovakCZ
Profil
Tak sem to vyresil, tak jednoduche to bylo :D... nemam sily to sem pridavat, jsou 4 rano, tak se jdu na chvili prostpat ;)

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: