[HELP]PHP Related question
So i have a Parse Error: Syntax Error: I've already tryed to look up with the editors that sometimes show the error but without result also I already checked : PHP parse/syntax errors on google; and how to solve them but not sure on how to fix it. Have a good day. Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file on line 24
Re: [HELP]PHP Related question
12345
Quote:
Originally Posted by
S37uP!Update
So i have a Parse Error: Syntax Error: I've already tryed to look up with the editors that sometimes show the error but without result also I already checked :
PHP parse/syntax errors on google; and how to solve them but not sure on how to fix it. Have a good day.
Parse error: syntax error, unexpected 'else' (T_ELSE), expecting end of file on line 24
Re: [HELP]PHP Related question
Now i've got this error:
PHP Code:
Fatal error: Uncaught Error: Call to undefined method PDOStatement::fetch_assoc() in X:\Xampp\htdocs\rank.php:22 Stack trace: #0 {main} thrown in X:\Xampp\htdocs\rank.php on line 22
Re: [HELP]PHP Related question
was just as example..
this one should do...
Code:
// output data of each row
if ($result)
{
while ($row = $result->fetch_assoc())
{
echo "<tr><td>".$top."</td><td>".$row[userName]."</td><td>".$row[userLevel]."</td><td>".$row[totalExp]."</td><td>".$row[equipItemLevel]."</td></tr>";
}
}
else
{
echo "No data available";
echo "Prepared Statement Error:\n" + $Connection->error;
}
Re: [HELP]PHP Related question
Well, after reading some articles i finally managed to fix it, thank you anyway for the help provided it leaded me to a better keyword search on google :).
This is the working code, i also included HTML table for positioning.
PHP Code:
<?php
// DATABASE CONNECTION
include 'config.php';
$serverName = "$IPAddress";
$connectionInfo = array( "Database"=>$DATABase, "UID"=>$USERName, "PWD"=>$PASSWORD);
$Connection = sqlsrv_connect($serverName, $connectionInfo);
// PREPARE QUERY
$sql = "SELECT userName, userLevel, totalExp, equipItemLevel FROM Users ORDER BY totalExp DESC";
$stmt = sqlsrv_query( $Connection, $sql );
if( $stmt === false)
{die( print_r( sqlsrv_errors(), true) );}
// RANK NUMBER DEFINITION
$i = 1;
//START HTML TABLE
echo '<table>';
// HTML TOP ROWS
echo '<tr>';
echo '<th>Rank</th>';
echo '<th>Character Name</th>';
echo '<th>Level</th>';
echo '<th>Total Experience</th>';
echo '<th>Equipment Item Level</th>';
echo '</tr>';
// CHECK CONNECTION
if( $Connection )
// PRINT QUERY
{while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
// QUERY RESULT ROWS
{echo '<tr><td>' .$i++, '</td><td>' . $row['userName'] . '</td><td>' . $row['userLevel'] . '</td><td>' . $row['totalExp'] . '</td><td>' . $row['equipItemLevel'] . '</td></tr>';}
// END TABLE
echo '</table>';}
// FAIL CONNECTION
else
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}
// CLOSE CONNECTION
sqlsrv_free_stmt( $stmt);
?>
- - - Updated - - -
So, i'm trying to use the if/elseif for the class name to switch the variables with a predefined text
PHP Code:
if($row["class"] == "0"){$charclass="WA0";}
else if($row["class"] == "1"){$charclass="WA1";}
else if($row["class"] == "2"){$charclass="WA2";}
else if($row["class"] == "3"){$charclass="WA3";}
else if($row["class"] == "4"){$charclass="WA4";}
else if($row["class"] == "5"){$charclass="WA5";}
else if($row["class"] == "6"){$charclass="WA6";}
else if($row["class"] == "7"){$charclass="WA7";}
else if($row["class"] == "8"){$charclass="WA8";}
else if($row["class"] == "9"){$charclass="WA9";}
else if($row["class"] == "10"){$charclass="WA10";}
else if($row["class"] == "11"){$charclass="WA11";}
else if($row["class"] == "12"){$charclass="WA12";}
else if($row["class"] == "13"){$charclass="WA13";}
And it's give's me "Notice: Trying to access array offset on value of type null"
The number 12 - WA12 shows up but with the error from above at every character
Re: [HELP]PHP Related question
Quote:
Originally Posted by
S37uP!Update
Well, after reading some articles i finally managed to fix it, thank you anyway for the help provided it leaded me to a better keyword search on google :).
This is the working code, i also included HTML table for positioning.
PHP Code:
<?php
// DATABASE CONNECTION
include 'config.php';
$serverName = "$IPAddress";
$connectionInfo = array( "Database"=>$DATABase, "UID"=>$USERName, "PWD"=>$PASSWORD);
$Connection = sqlsrv_connect($serverName, $connectionInfo);
// PREPARE QUERY
$sql = "SELECT userName, userLevel, totalExp, equipItemLevel FROM Users ORDER BY totalExp DESC";
$stmt = sqlsrv_query( $Connection, $sql );
if( $stmt === false)
{die( print_r( sqlsrv_errors(), true) );}
// RANK NUMBER DEFINITION
$i = 1;
//START HTML TABLE
echo '<table>';
// HTML TOP ROWS
echo '<tr>';
echo '<th>Rank</th>';
echo '<th>Character Name</th>';
echo '<th>Level</th>';
echo '<th>Total Experience</th>';
echo '<th>Equipment Item Level</th>';
echo '</tr>';
// CHECK CONNECTION
if( $Connection )
// PRINT QUERY
{while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) )
// QUERY RESULT ROWS
{echo '<tr><td>' .$i++, '</td><td>' . $row['userName'] . '</td><td>' . $row['userLevel'] . '</td><td>' . $row['totalExp'] . '</td><td>' . $row['equipItemLevel'] . '</td></tr>';}
// END TABLE
echo '</table>';}
// FAIL CONNECTION
else
{echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));}
// CLOSE CONNECTION
sqlsrv_free_stmt( $stmt);
?>
- - - Updated - - -
So, i'm trying to use the if/elseif for the class name to switch the variables with a predefined text
PHP Code:
if($row["class"] == "0"){$charclass="WA0";}
else if($row["class"] == "1"){$charclass="WA1";}
else if($row["class"] == "2"){$charclass="WA2";}
else if($row["class"] == "3"){$charclass="WA3";}
else if($row["class"] == "4"){$charclass="WA4";}
else if($row["class"] == "5"){$charclass="WA5";}
else if($row["class"] == "6"){$charclass="WA6";}
else if($row["class"] == "7"){$charclass="WA7";}
else if($row["class"] == "8"){$charclass="WA8";}
else if($row["class"] == "9"){$charclass="WA9";}
else if($row["class"] == "10"){$charclass="WA10";}
else if($row["class"] == "11"){$charclass="WA11";}
else if($row["class"] == "12"){$charclass="WA12";}
else if($row["class"] == "13"){$charclass="WA13";}
And it's give's me "Notice: Trying to access array offset on value of type null"
The number 12 - WA12 shows up but with the error from above at every character
why doing such a if/else fields?
You can prepare an array ahead like so
PHP Code:
$class_name = [
'WA1',
'WA2',
'etc...'
];
echo $class_name[intval($row['class'])];
This will access directly your array and output a given string depending on the class number in your row variable.
Now for your error, it says that your $row['class'] is undefined prob, try to var_dump($row); to see what's in there.
Re: [HELP]PHP Related question
var_dump($row); returns as NULL
Re: [HELP]PHP Related question
Quote:
Originally Posted by
S37uP!Update
var_dump($row); returns as NULL
So then it means your SELECT query doesn't return anything. Also you don't have any "class" column in your SELECT, so the $row['class'] will never be filled.
Re: [HELP]PHP Related question
Solved anything about my questions, you can close topic. Thanks guys.