OsirisElKeleni Posted September 28, 2014 Share Posted September 28, 2014 Hello everyone, i'm Osiris and i'm stuck with this PHP/HTML code, i'm fairly new at this so this might be a dumb question. i have a database, but i want to output all data into a table from the database using HTML codes. i had it so far that i could outpust the info in just plain text but it doesn't output in the HTML table. Can anyone see what i did wrong? This is my PHP code its in the body section <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'password'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`'; mysql_select_db('mtgstock'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo '<table class=mytable>'; echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>"; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr><td>"; echo $row['Name'] echo "</td><td>"; echo $row['Color']; echo "</td><td>"; echo $row['Type']; echo "</td><td>"; echo $row['Subtype']; echo "</td><td>"; echo $row['Power']; echo "</td><td>"; echo $row['Toughness']; echo "</td><td>"; echo $row['Manacost']; echo "</td><td>"; echo $row['Rarity']; echo "</td><td>"; echo $row['Expansion']; echo "</td><td>"; echo $row['Foil']; echo "</td><td>"; echo $row['Stock']; echo "</td></tr>"; } echo "</table>"; mysql_close($conn); ?> Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 28, 2014 Share Posted September 28, 2014 Your (html) code being output by your PHP code looks ok to me. The data returned by your query should be displayed in the HTML table. What are you seeing instead? Note you should stop using the mysql_ functions. These functions are deprecated meaning they are no longer supported and could be removed from future versions of PHP. You should be using MySQLi or PDO Quote Link to comment Share on other sites More sharing options...
maxxd Posted September 28, 2014 Share Posted September 28, 2014 The code does look like it should be working - do you have error reporting turned on, and if so, is it displaying an error? And to reinforce Ch0cu3r's point, move away from the mysql_ functions. Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted September 28, 2014 Author Share Posted September 28, 2014 Getting no error as far as i can see, it prints the code instead of using it. http://imgur.com/S5wlflW this is the result of that code Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 28, 2014 Share Posted September 28, 2014 Umm... Are you sure your server is configured with PHP? Are you running code in a file ending with .php extension? Can you tell use how this code is being called? Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted September 28, 2014 Author Share Posted September 28, 2014 (edited) Ow yea i did not change the html file to php. :@ But now i'm gettin this error: Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in D:\xampp\htdocs\mtgstock\index.php on line 66 this is the full file <!DOCTYPE html> <html> <head> <title>MTG Card List</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <style type="text/css" media="screen"> @import "filtergrid.css"; body{ margin:15px; padding:15px; border:1px solid #666; font-family:Arial, Helvetica, sans-serif; font-size:88%; } h2{ margin-top: 50px; } caption{ margin:10px 0 0 5px; padding:10px; text-align:left; } pre{ font-size:13px; margin:5px; padding:5px; background-color:#f4f4f4; border:1px solid #ccc; } .mytable{ width:100%; font-size:12px; border:1px solid #ccc; } th{ background-color:#003366; color:#FFF; padding:2px; border:1px solid #ccc; } td{ padding:2px; border-bottom:1px solid #ccc; border-right:1px solid #ccc; } body p { font-size: 50%; color: #000; } a:link { color: #000; } a:visited { color: #000; } </style> <script language="javascript" type="text/javascript" src="actb.js"></script> <script language="javascript" type="text/javascript" src="tablefilter.js"></script> </head> <body> <form action="password.php" method="POST"> <b>Username:</b> <input type="text" name="username"> <b>Password:</b> <input type="text" name="password"> <input type="submit"> </form> <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT `Name`, `Color`, `Type`, `Subtype`, `Power`, `Toughness`, `Manacost`, `Rarity`, `Expansion`, `Foil`, `Stock` FROM `mtgtabel`'; mysql_select_db('mtgstock'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } echo '<table class=mytable>'; echo "<tr><th >Name</th><th >Color</th><th >Type</th><th >Sub Type</th><th >Power</th><th >Toughness</th><th >Converted mana cost</th><th >Rarity</th><th >Expansion</th><th >Foil</th><th >Stock</th></tr>"; while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr><td>"; echo $row['Name'] echo "</td><td>"; echo $row['Color']; echo "</td><td>"; echo $row['Type']; echo "</td><td>"; echo $row['Subtype']; echo "</td><td>"; echo $row['Power']; echo "</td><td>"; echo $row['Toughness']; echo "</td><td>"; echo $row['Manacost']; echo "</td><td>"; echo $row['Rarity']; echo "</td><td>"; echo $row['Expansion']; echo "</td><td>"; echo $row['Foil']; echo "</td><td>"; echo $row['Stock']; echo "</td></tr>"; } echo "</table>"; mysql_close($conn); ?> <script language="javascript" type="text/javascript"> var recapFilters = { sort_select: true, loader: true, col_1: "select", col_2: "select", col_3: "select", col_7: "select", col_8: "select", col_9: "select", col_10: "false", on_change: true, display_all_text: "Show all", rows_counter: true, btn_reset: true, alternate_rows: true, btn_reset_text: "Clear", col_width: ["150px","150px",null,null] } setFilterGrid("recap",recapFilters); </script> <script language="javascript" type="text/javascript"> var table_Props = { paging: true, paging_length: 3, rows_counter: true, btn_reset: true, loader: true, loader_text: "Filtering data..." }; setFilterGrid( "table",table_Props ); </script> </body> </html> >Thanks for responding and helping me out so quickly btw! Edited September 28, 2014 by OsirisElKeleni Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 28, 2014 Share Posted September 28, 2014 That error is caused due to leaving off the semi-colon at the end of line 65. Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted September 28, 2014 Author Share Posted September 28, 2014 Oh thanks alot man! it works fine now really i appriciate it (((: AWESOME FORUM! Quote Link to comment Share on other sites More sharing options...
OsirisElKeleni Posted September 28, 2014 Author Share Posted September 28, 2014 (edited) Oh i do have one more question, i have like filtering stuff at the top of the table but when i use it it just stays loading is this cuz this is a localhost? http://imgur.com/V3wIe4d Edited September 28, 2014 by OsirisElKeleni Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 28, 2014 Share Posted September 28, 2014 This new problem you have has nothing to do with your PHP code or whether you are running the code locally The filtering is handled by the third party javascript code you are using. Maybe you have not handled it correctly? if not check for javascript errors in your browsers console (F12 > Console Tab). If there are javascript errors then start a new thread in the Javascript Forum. 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.