We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
PHP/MySQL array problem
Topic Started: Jun 21 2005, 06:29 PM (324 Views)
blakeo_x
Member Avatar
I cant believe its not PHP!
[ *  *  * ]
For some reason, my PHP page isnt working. It keeps returning the error "Parse error: parse error, unexpected T_WHILE on line 16".

PHP code
 
<?php
$conn = mysql_connect("localhost", "user", "password")
or die('Database connection unavailable: ' . mysql_error());
mysql_select_db("blakeab_betalog", $conn) or die('select_db error: ' . mysql_error());

$get_logs = "select log_id, log_owner, log_type, date_format(log_date, '%b %e %Y at %r') as fmt_log_date, log_text from SBPC_logs order by log_id desc";
$get_logs_res = mysql_query($get_logs,$conn) or die('mySQL query error: ' . mysql_error());
if (mysql_num_rows($get_logs_res) < 1)
{
$display_block = "<tr><td><em>No reports exist.</em></td></tr>";
}
else
{
$display_block = ""

while ($log_info = mysql_fetch_array($get_logs_res, MYSQL_BOTH))
{
 $log_id = $log_info['log_id'];
 $log_owner = stripslashes($log_info['log_owner']);
 $log_type = stripslashes($log_info['log_type']);
 $log_date = $log_info['fmt_log_date'];
 $log_text = stripslashes($log_info['log_text']);
 
 $get_num_logs = "select count(log_id) from SBPC_logs where log_id = $log_id";
 $get_num_logs_res = mysql_query($get_num_logs,$conn) or die('mySQL error: ' . mysql_error());
 $num_logs = mysql_result($get_num_logs_res,0,'count(log_id)');
 
 $display_block .= "<tr>
  <td><center>$log_id</center></td>
  <td>$log_owner</td>
  <td>$log_type</td>
  <td>$log_date</td>
  <td>$log_text</td>
  </tr>";
}
}
?>

<html>
<head>
<title>Log Manager for SBPC</title>
</head>
<body>
<h1>Log Manager</h1>
<P>
<table>
<?php echo $display_block; ?>
</table>
</body>
</html>


Any ideas on how to fix this?
Offline Profile Quote Post Goto Top
 
solinent
Member Avatar
Member
[ *  *  * ]
blakeo_x
June 21, 2005 05:29 PM
For some reason, my PHP page isnt working. It keeps returning the error "Parse error: parse error, unexpected T_WHILE on line 16".

PHP code
 
<?php
$conn = mysql_connect("localhost", "user", "password")
or die('Database connection unavailable: ' . mysql_error());
mysql_select_db("blakeab_betalog", $conn) or die('select_db error: ' . mysql_error());

$get_logs = "select log_id, log_owner, log_type, date_format(log_date, '%b %e %Y at %r') as fmt_log_date, log_text from SBPC_logs order by log_id desc";
$get_logs_res = mysql_query($get_logs,$conn) or die('mySQL query error: ' . mysql_error());
if (mysql_num_rows($get_logs_res) < 1)
{
$display_block = "<tr><td><em>No reports exist.</em></td></tr>";
}
else
{
$display_block = ""

while ($log_info = mysql_fetch_array($get_logs_res, MYSQL_BOTH))
{
  $log_id = $log_info['log_id'];
  $log_owner = stripslashes($log_info['log_owner']);
  $log_type = stripslashes($log_info['log_type']);
  $log_date = $log_info['fmt_log_date'];
  $log_text = stripslashes($log_info['log_text']);
 
  $get_num_logs = "select count(log_id) from SBPC_logs where log_id = $log_id";
  $get_num_logs_res = mysql_query($get_num_logs,$conn) or die('mySQL error: ' . mysql_error());
  $num_logs = mysql_result($get_num_logs_res,0,'count(log_id)');
 
  $display_block .= "<tr>
  <td><center>$log_id</center></td>
  <td>$log_owner</td>
  <td>$log_type</td>
  <td>$log_date</td>
  <td>$log_text</td>
  </tr>";
}
}
?>

<html>
<head>
<title>Log Manager for SBPC</title>
</head>
<body>
<h1>Log Manager</h1>
<P>
<table>
<?php echo $display_block; ?>
</table>
</body>
</html>


Any ideas on how to fix this?

Code:
 
if (mysql_num_rows($get_logs_res) < 1)
{
$display_block = "<tr><td><em>No reports exist.</em></td></tr>";
}
else
{
$display_block = ""

while ($log_info = mysql_fetch_array($get_logs_res, MYSQL_BOTH))

Change to:
CODE
 

if (mysql_num_rows($get_logs_res) < 1)
{
$display_block = "<tr><td><em>No reports exist.</em></td></tr>";
}
else
{
$display_block = "";

while ($log_info = mysql_fetch_array($get_logs_res, MYSQL_BOTH))
Offline Profile Quote Post Goto Top
 
blakeo_x
Member Avatar
I cant believe its not PHP!
[ *  *  * ]
D'Oh! >_<

Its amazing how much one semicolon can affect PHP.
Offline Profile Quote Post Goto Top
 
solinent
Member Avatar
Member
[ *  *  * ]
Yeah lol gotta hate 'em

If it's a parse error, generally it's something to do with syntax, and usually semi-colans :huh:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply