Pergunta

Não consigo encontrar o erro no script abaixo.estou verificando há algum tempo.desculpe, sou realmente novo em 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++;

    }
Foi útil?

Solução

O problema está na maneira como você concatenado as variáveis.

Você esqueceu um ponto e uma citação.Mudar .$RegType" <br />; para . $RegType . "<br />";

echo $index . "." . $preNAME . " " . $Name . " " . $RegType  "<br /> ;
                                                            ^  dot  ^ quote

Altere para:

echo $index . "." . $preNAME . " " . $Name . " " . $RegType . "<br />";

Você pode remover o espaço no " " se você quiser.

Outras dicas

primeiro:você pode usar:

$tCompany_SQLselect_Query = mysql_query($tCompany_SQLselect) or die(mysql_error());

isso permitirá que você depure o erro.

segundo:você pode usar:

$row = mysql_fetch_assoc($tCompany_SQLselect_Query)

para encurtar a sintaxe.

O echo linha deve ser:

echo $index.".".$preNAME." ".$Name." ".$RegType." . "<br />";

Você estava perdendo citações por aí <br />, e a . para concatenação antes dele.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top