wooowooo Posted December 23, 2007 Share Posted December 23, 2007 Hi I found this code to help with my previous question however it doesnt seem to work because im getting the error Parse error: syntax error, unexpected '=', expecting ')' relating to line 35, any idea what the prob could be? <?php /* set the allowed order by columns */ $default_sort = 'CustomerID'; $allowed_order = array ('Name', 'Address','Postcode','Telephone','Email'); /* if order is not set, or it is not in the allowed * list, then set it to a default value. Otherwise, * set it to what was passed in. */ if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) { $order = $default_sort; } else { $order = $_GET['order']; } /* connect to db */ mysql_connect ('localhost','user','pass); mysql_select_db ('database'); /* construct and run our query */ $query = "SELECT * FROM table ORDER BY $order"; $result = mysql_query ($query); /* make sure data was retrieved */ $numrows = mysql_num_rows($result); if ($numrows == 0) { echo "No data to display!"; exit; } /* now grab the first row and start the table */ $row = mysql_fetch_assoc ($result); echo "<TABLE border=1>\n"; echo "<TR>\n"; foreach ($row as $heading=>$column) { /* check if the heading is in our allowed_order * array. If it is, hyperlink it so that we can * order by this column */ echo "<TD><b>"; if (in_array ($heading, $allowed_order)) { echo "<a href=\"{$_SERVER['PHP_SELF']}?order=$heading\">$heading</a>"; } else { echo $heading; } echo "</b></TD>\n"; } echo "</TR>\n"; /* reset the $result set back to the first row and * display the data */ mysql_data_seek ($result, 0); while ($row = mysql_fetch_assoc ($result)) { echo "<TR>\n"; foreach ($row as $column) { echo "<TD>$column</TD>\n"; } echo "</TR>\n"; } echo "</TABLE>\n"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/82942-solved-gt-will-this-work/ Share on other sites More sharing options...
wildteen88 Posted December 23, 2007 Share Posted December 23, 2007 This line: foreach ($row as $heading=>$column) { which I presume is line 35 is supposed to be: foreach ($row as $heading => $column) { Also it looks like for some reason the HTML has been converted to htmlspecialcars you will need to convert any instances of < to < and > to > in order for your html code to work properly when outputted by the PHP code. Also when posting code please use the code tags ( ) Quote Link to comment https://forums.phpfreaks.com/topic/82942-solved-gt-will-this-work/#findComment-421841 Share on other sites More sharing options...
wooowooo Posted December 23, 2007 Author Share Posted December 23, 2007 Sorry about not using code as I was supposed to, I didnt relise I am new to this board. That solved the problem, I have a random ; at the top of the table though, any idea what could be causing it? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/82942-solved-gt-will-this-work/#findComment-421849 Share on other sites More sharing options...
wildteen88 Posted December 24, 2007 Share Posted December 24, 2007 I cannot see why you are your code is outputting a ; at the top of the page. You mostly likely have a random ; somewhere within your HTML when your output the table. Run the code again but this time view the source code (View > Source Code) and have a look to see where the ; is within the outputted HTML. That will give an idea of where it is within your PHP code. Quote Link to comment https://forums.phpfreaks.com/topic/82942-solved-gt-will-this-work/#findComment-422314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.