BrainBoxMad Posted June 12, 2013 Share Posted June 12, 2013 Hi everyone, I am quite new to the world of PHP, and really need some help, as i am getting the following error message over and over again, and cant find a solution: Parse error: syntax error, unexpected 'while' (T_WHILE), expecting ',' or ';' in E:\website\htdocs\test\test.php on line 27 Can anyone please give me some of their time and check through my code to maybe see if they can spot the problem area? Thanks. My Code is the following: <?phpinclude 'config.php';//Choose the database$selected = mysql_select_db("store",$dbhandle) or die("Could not select store"); //execute the SQL query and return results$result = mysql_query("SELECT product_id, product_name, product_type, price, description, stock, weight FROM products");echo "<table border=\"1\" cellpadding=\"3\">\n";echo "<thead>\n";echo "<tr>\n";echo "<th>ID</th>";echo "<th>Name</th>";echo "<th>Product Type</th>";echo "<th>Price</th>";echo "<th>Description</th>";echo "<th>Stock</th>";echo "<th>Weight</th>";echo "</thead>\n";echo "<tbody>\n"//retrieve that data from the database, while loop due to having more than one resultwhile($row = mysql_fetch_array($result)){ echo "ID: ".$row{"product_id"}. "<br>"; echo "Name: ".$row{"product_name"}. "<br>"; echo "Product Type: ".$row{"product_type"}. "<br>"; echo "Price: ".$row{"price"}. "<br>"; echo "Description: ".$row{"description"}. "<br>"; echo "Stock: ".$row{"stock"}. "<br>"; echo "Weight: ".$row{"weight"}. "<br>"; "<br>"; //display the results}?> Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/ Share on other sites More sharing options...
Love2c0de Posted June 12, 2013 Share Posted June 12, 2013 Good evening, You have missed off an ending semi-colon on this line: echo "<tbody>\n" Kind regards, L2c Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435577 Share on other sites More sharing options...
BrainBoxMad Posted June 12, 2013 Author Share Posted June 12, 2013 Yes, thank you L2c, however, i am now getting the data displayed, but not correctly, as you can see below, any ideas why this may be happening? Connected to MySQLID: 1Name: ASUS 15" UltrabookProduct Type: LaptopPrice: 400Description: Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test Gibrish Test GibrishStock: 15Weight: 8 ID Name Product Type Price Description Stock Weight Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435605 Share on other sites More sharing options...
Barand Posted June 12, 2013 Share Posted June 12, 2013 Give us a clue. How do you want it to appear? Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435607 Share on other sites More sharing options...
mac_gyver Posted June 12, 2013 Share Posted June 12, 2013 your actual data output doesn't contain any <tr><td>...</td>...</tr> tags, so it is just output as is. you would probably want to add those tags if you want the data to be displayed in the table. you will also want to close the table after all the output with a </table> tag. Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435608 Share on other sites More sharing options...
BrainBoxMad Posted June 13, 2013 Author Share Posted June 13, 2013 To Mac_gyver, Thanks for the above help, that got me sorted ; ) Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435634 Share on other sites More sharing options...
imen Posted June 13, 2013 Share Posted June 13, 2013 If you want to display in a table, I suggest you this code Quote <php .................................. ?> <html><head></head> <body> <?php while($row = mysql_fetch_array($result)){ ?> <tr><td><?php echo $row{"product_id"} ;?></td> <td><? php echo $row{"product_name"} ?></td></tr>............................................................................................................ ?></body></html> Link to comment https://forums.phpfreaks.com/topic/279082-trying-to-display-data-from-databse-in-a-php-table/#findComment-1435638 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.