Autor Zpráva
Pepan23
Profil *
Dobrý den,
potřeboval bych nějak upravit tento kód aby mi vypisoval z DB.
Když mám tak le ten to kód tak mi to hazí chybu.
Parse error: syntax error, unexpected T_WHILE, expecting ')' in /home/users/manikbla/witpek.cz/web/vn.php on line 16


Zkoušel jsem hodně způsobů, ale vždy stejná chyba.

<?php


$host="localhost"; // Host name 
$username="username"; // Mysql username 
$password="password"; // Mysql password 
$db_name="db_name"; // Database name 
$tbl_name="tbl_name"; // Table name
 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$aUsers = array( 
while($rows=mysql_fetch_array($result)){
 


  "$rows[title]",
 			
}
 );
 
	
	
	$input = strtolower( $_GET['input'] );
	$len = strlen($input);
	
	
	$aResults = array();
	
	if ($len)
	{
		for ($i=0;$i<count($aUsers);$i++)
		{
			// had to use utf_decode, here
			// not necessary if the results are coming from mysql
			//                                                
			if (strtolower(substr(utf8_decode($aUsers[$i]),0,$len)) == $input)
				$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
			
			//if (stripos(utf8_decode($aUsers[$i]), $input) !== false)
			//	$aResults[] = array( "id"=>($i+1) ,"value"=>htmlspecialchars($aUsers[$i]), "info"=>htmlspecialchars($aInfo[$i]) );
		}
	}
	
	
	
	
	
	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
	header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header ("Pragma: no-cache"); // HTTP/1.0
	

	if (isset($_REQUEST['json']))
	{
		header("Content-Type: application/json");
	
		echo "{\"results\": [";
		$arr = array();
		for ($i=0;$i<count($aResults);$i++)
		{  
			$arr[] = "{\"id\": \"".$aResults[$i]['id']."\", \"value\": \"".$aResults[$i]['value']."\", \"info\": \"\"}";
		}
		echo implode(", ", $arr);
		echo "]}";
	}
	else
	{
		header("Content-Type: text/xml charset=windows-1250");

		echo "<?xml version=\"1.0\" encoding=\"windows-1250\" ?><results>";

   
		for ($i=0;$i<count($aResults);$i++)
		{
			echo "<rs id=\"".$aResults[$i]['id']."\" info=\"".$aResults[$i]['info']."\">".$aResults[$i]['value']."</rs>";
		}
	
	
		echo "</results>";
	}
?>
Keeehi
Profil
Problém je v této části:
$aUsers = array( 
while($rows=mysql_fetch_array($result)){
 


  "$rows[title]",
             
}
 );

Asi by to mělo být takto:
$aUsers = array();
while($rows=mysql_fetch_array($result))
  $aUsers[]=$rows["title"];
Pepan23
Profil *
Díky, už to funguje. Moc jsi mě pomohl. Fakt díky.
Pepan23
Profil *
Jěšte malí problém, s kódováním píšemi to čtverečky místo čárek a háčků.
Kajman_
Profil *
http://diskuse.jakpsatweb.cz/?action=vthread&forum=28&topic=37836

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:

0