SQL Seleziona non funzionante nell'array mysql_assoc
Domanda
Non riesco a trovare l'errore nel seguente script.Ho controllato mentre ora.Scusa, sono davvero nuovo a SQL e PHP.
$tCompany_SQLselect = "SELECT ";
$tCompany_SQLselect .= "ID, preNAME, Name, RegType ";
$tCompany_SQLselect .= "FROM ";
$tCompany_SQLselect .= "tCompany ";
$tCompany_SQLselect_Query = mysql_query($tCompany_SQLselect);
$index = 1;
while ($row = mysql_fetch_array($tCompany_SQLselect_Query, MYSQL_ASSOC)) {
$preNAME = $row['preNAME'];
$Name = $row['Name'];
$RegType = $row['RegType'];
echo $index.".".$preNAME."".$Name."".$RegType" <br />;
$index++;
}
. Soluzione
Il problema è nel modo in cui concatenato le variabili.
Hai dimenticato un punto e una citazione.Cambia .$RegType" <br />;
in . $RegType . "<br />";
echo $index . "." . $preNAME . " " . $Name . " " . $RegType "<br /> ;
^ dot ^ quote
.
echo $index . "." . $preNAME . " " . $Name . " " . $RegType . "<br />";
.
Altri suggerimenti
Primo: puoi usare:
$tCompany_SQLselect_Query = mysql_query($tCompany_SQLselect) or die(mysql_error());
.
Ciò consentirà di eseguire il debug dell'errore.
Secondo: puoi usare:
$row = mysql_fetch_assoc($tCompany_SQLselect_Query)
.
per abbreviare la sintassi.
La linea echo
dovrebbe essere:
echo $index.".".$preNAME." ".$Name." ".$RegType." . "<br />";
.
Ti mancavano citazioni intorno a <br />
e il .
per la concatenazione prima di esso.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow