Simpson Posted April 19, 2014 Share Posted April 19, 2014 Hey, I wrote this code, to make a dynamic table, but I keep getting Syntax error, and I can't see where that error is, plz help. mysql_connect ("localhost", "USERNAME", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error()); // Select the database mysql_select_db ("DATABASE") or die ("Could not select database"); // Store Settings $gable_max_colo = "9"; $box_max_fresh = "2"; $box_max_frozen = "2"; // Getting data $dep = 'Colonial'; $displayT = 'Gable'; $res = mysql_query("SELECT * FROM Marketing WHERE Year='".$_POST['year']."' and Week='".$_POST['week']."'"); while ($row = mysql_fetch_array($res)){ $dep = $row['Department']; $displayT = $row['DisplayType']; if ($dep == 'Colonial'){ if ($displayT == 'Gable'){ $number = '1'; while ($number > $gable_max_colo){ $result = mysql_query("SELECT * FROM Marketing WHERE Year'".$_POST['year']."' and Number='".$number."' and DisplayType='".$displayT."' and Department='".$dep."' and Week='".$_POST['week']."'"); $html_start = '<h2>Endegavl'.$number.'</h2> <table border="1" cellspacing="4" cellpadding="4"> <tr> <th>Brand</th> <th align="right">Product</th> <th align="left">Type</th> <th>Price</th> </tr>'; while ($row = mysql_fetch_array($result)){ $Product = $row['Product']; $Brand = $row['Brand']; $Price = $row['Price']; $ProductT = $row['ProductType']; $Count = $row['Count']; $Goods = $row['Goodsnr']; $html_inside .= ' <tr> <td>'.$Brand.'</td> <td>'.$Product.'</td> <td>'.$Type.'</td> <td>'.$Price.'</td> </tr>'; } $html_end = '</table>'; $number = $number + 1; } } } echo $html_start; echo $html_inside; echo $html_end; Quote Link to comment Share on other sites More sharing options...
boompa Posted April 19, 2014 Share Posted April 19, 2014 You appear to be missing a }. Next time, please copy and paste the exact error. Quote Link to comment Share on other sites More sharing options...
bsmither Posted April 19, 2014 Share Posted April 19, 2014 (edited) I do not like the mysql_connect and mysql_select_db statements. If you found that in a book, please review the language being used. Let us know how this statemnent is supposed to work. PHP should report the line number on which the error occured. May I ask what environment you are programming in where PHP does not indicate the line number where an error occured? mysql_connect should return with a connection handle, true, or false. We need to test for that and deal with the failure: if (($db = mysql_connect ("localhost", "USERNAME", "PASSWORD")) === false) { die ('I cannot connect to the database because: ' . mysql_error()); } I also see: while ($number > $gable_max_colo){ does not have a closing brace after: $number = $number + 1; Edited April 19, 2014 by bsmither Quote Link to comment Share on other sites More sharing options...
boompa Posted April 19, 2014 Share Posted April 19, 2014 Fact is at this point he or she shouldn't be using the mysql_ functions at all as they're deprecated, instead opting for PDO or mysqli. Also, not sure exactly what the goal is, but nested queries are never a good sign. Quote Link to comment Share on other sites More sharing options...
Simpson Posted April 20, 2014 Author Share Posted April 20, 2014 Thx, I knew i had missed something, just could't see it Quote Link to comment 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.