Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Parse error: syntax error, unexpected T_VARIABLE in line 47.

LEGEND ,
Jun 10, 2011 Jun 10, 2011

Using phpmyadmin I created a simple query and had the program create the php code, which reads like this:

$sql  = 'SELECT *FROM `Personal_data` WHERE 1  ORDER BY `Date & Time` ASC LIMIT 0, 30 ';

I copy/paste that statement into my code, parts of it are:

44. $con = mysql_connect($localhost, $user, $password);
45. $db = mysql_select_db($database) or die( "Unable to select database");
46. $br = "<br />"
47. $sql = 'SELECT *FROM `Personal_data` WHERE 1 ORDER BY `Date & Time` ASC LIMIT 0, 30 ';
48. $result = mysql_query($sql);
49. while($row = mysql_fetch_array($result))
50.   {  echo $row['Ref_ID'] . " " . $row['Date & Time'] . " " . $row['IP_Address'] . " " . $br;  }
51. mysql_free_result($result); 
52. mysql_close($con);
53. ?>

Why do I get this Parse error in this bold line?

TOPICS
Server side applications
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 10, 2011 Jun 10, 2011

Look on line 46

46. $br = "<br />"

You need to add a semi-colon

46. $br = "<br />";

Gary

Translate
Guest
Jun 10, 2011 Jun 10, 2011

Look on line 46

46. $br = "<br />"

You need to add a semi-colon

46. $br = "<br />";

Gary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2011 Jun 10, 2011

Gary,

Duuhh, what a stupid mistake, but you saw it immediately. Thanks a lot.

Next question if I may. I can see my table, but want to add a calculated field to the table and sort on it.

I made this code, with your correction of course:

$con = mysql_connect($localhost, $user, $password);
$db = mysql_select_db($database) or die( "Unable to select database");
$br = "<br />";
$sql = 'SELECT *FROM `Personal_data` WHERE 1 ORDER BY `Date & Time` ASC LIMIT 0, 500 ';
$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Date & Time</th>
<th>Email</th>
<th>Computer ID</th>
<th>Model CPU</th>
<th>Clock speed</th>
<th>RAM installed</th>
<th>Version</th>
<th>Graphics card</th>
<th>Total score</th>
<th>Disk I/O</th>
<th>MPEG2-DVD</th>
<th>H.264-br</th>
<th>MPE On</th>
<th>MPE Off</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Date & Time'] . "</td>";
  echo "<td>" . $row['Email'] . "</td>";
  echo "<td>" . $row['Computer ID'] . "</td>";
  echo "<td>" . $row['Model CPU'] . "</td>";
  echo "<td>" . $row['Clock speed'] . "</td>";
  echo "<td>" . $row['RAM installed'] . "</td>";
  echo "<td>" . $row['Version'] . "</td>";
  echo "<td>" . $row['Graphics card'] . "</td>";
  echo "<td>" . $row['Disk I/O'+'MPEG2-DVD'+'H.264-BR'+'MPE On'+'MPE Off'] . "</td>";
  echo "<td>" . $row['Disk I/O'] . "</td>";
  echo "<td>" . $row['MPEG2-DVD'] . "</td>";
  echo "<td>" . $row['H.264-BR'] . "</td>";
  echo "<td>" . $row['MPE On'] . "</td>";
  echo "<td>" . $row['MPE Off'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_free_result($result); 
mysql_close($con);
?>

This works, apart from the highlighted line, which does not show the calculated results, but the primary key. Actually I want to have something, in Excel terms, like:

Sum (Disk I/O, MPEG2-DVD, H.264-BR, (MIN(MPE On, MPE Off))

I assume this is another duuhh experience for me. During my first exercise with PHP I have learnt that interpunction can be devastating. The slightest type is punished. That will take some getting used to, since I come from an APL background, where more than 10 lines of code was extravagant.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 10, 2011 Jun 10, 2011

I'm not sure, perhaps someone with more experience with sql calculations can help, but it seems to me that this:

echo "<td>" . $row['Disk I/O'+'MPEG2-DVD'+'H.264-BR'+'MPE On'+'MPE Off'] . "</td>";

Should be this

echo "<td>" . $row['Disk I/O']+['MPEG2-DVD']+['H.264-BR']+['MPE On']+['MPE Off'] . "</td>";

or perhpas

$calcu = $row['Disk I/O']+$row['MPEG2-DVD']+$row['H.264-BR']+$row['MPE On']+$row['MPE Off'];

echo "<td>". "$calcu" . "</td>";

Gary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 10, 2011 Jun 10, 2011
LATEST

Gary,

Thanks for the suggestion, but that did not work.

This was the solution:

$con = mysql_connect($localhost, $user, $password);
$db = mysql_select_db($database) or die( "Unable to select database");
$br = "<br />";
$sql = 'SELECT *, (`Disk I/O`+`MPEG2-DVD`+`H.264-BR`+`MPE On`) As Total FROM `Personal_data` WHERE 1 ORDER BY (`Disk I/O`+`MPEG2-DVD`+`H.264-BR`+`MPE On`) ASC LIMIT 0, 500 ';
$result = mysql_query($sql);

echo "<table border='1'>
<tr>
<th>Date & Time</th>
<th>Email</th>
<th>Computer ID</th>
<th>Model CPU</th>
<th>Clock speed</th>
<th>RAM installed</th>
<th>Version</th>
<th>Graphics card</th>
<th>Total score</th>
<th>Disk I/O</th>
<th>MPEG2-DVD</th>
<th>H.264-BR</th>
<th>MPE On</th>
<th>MPE Off</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
 
  echo "<td>" . $row['Date & Time'] . "</td>";
  echo "<td>" . $row['Email'] . "</td>";
  echo "<td>" . $row['Computer ID'] . "</td>";
  echo "<td>" . $row['Model CPU'] . "</td>";
  echo "<td>" . $row['Clock speed'] . "</td>";
  echo "<td>" . $row['RAM installed'] . "</td>";
  echo "<td>" . $row['Version'] . "</td>";
  echo "<td>" . $row['Graphics card'] . "</td>";
  echo "<td>" . $row['Total'] . "</td>";
  echo "<td>" . $row['Disk I/O'] . "</td>";
  echo "<td>" . $row['MPEG2-DVD'] . "</td>";
  echo "<td>" . $row['H.264-BR'] . "</td>";
  echo "<td>" . $row['MPE On'] . "</td>";
  echo "<td>" . $row['MPE Off'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_free_result($result); 
mysql_close($con);
?>

Changing the code to include the bold parts solved it.

Now the next step is to adjust the calculation, again in Excel terms from:

IF(Ax=0,Bx,MIN(Ax,BJx))

In this case, if MPE On = 0, then use MPE Off, else use MPE On.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines