tinkertron Posted December 31, 2009 Share Posted December 31, 2009 As mention before, i'm new to the whole PHP programming, but can some tell me how to display my db from MySQL to the web? I know you need to call the db up from MySQL, but how is it display to the web page as a table like excel? I have about 17 colms and there is going to be at least 600+ rows. Someone start me off so I can start learning. Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/ Share on other sites More sharing options...
RussellReal Posted December 31, 2009 Share Posted December 31, 2009 $q = mysql_query("SELECT * FROM tableName"); while ($row = mysql_fetch_assoc($q)) { print_r($row); } work with that Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/#findComment-986296 Share on other sites More sharing options...
tinkertron Posted December 31, 2009 Author Share Posted December 31, 2009 Thanks Russell! I just found how to add entries into my MySQL db using a basic html form. I feel so great that I will pick up on this piece by piece! I can't believe I have already created my first online db! Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/#findComment-986303 Share on other sites More sharing options...
The Little Guy Posted December 31, 2009 Share Posted December 31, 2009 Try this: <?php include '../incl/incl.php'; // Link to your database connection $sql = mysql_query("SELECT * FROM `questions`"); echo '<table>'; echo '<tr>'; while($field = mysql_fetch_field($sql)){ echo '<th>'.ucfirst($field->name).'</th>'; } echo '</tr>'; while($row = mysql_fetch_assoc($sql)){ echo '<tr>'; foreach($row as $item){ echo '<td style="padding-right:50px;border:solid 1px #000;">'.htmlentities(substr($item, 0, 30)).'</td>'; } echo '</tr>'; } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/#findComment-986344 Share on other sites More sharing options...
tinkertron Posted January 1, 2010 Author Share Posted January 1, 2010 I tried Russell code first and this is what I got: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\display.php on line 9 here's the code: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } $q = mysql_query("SELECT * FROM test"); while ($row = mysql_fetch_assoc($q)) { print_r($row); } mysql_close($con); ?> Would this be because it does know what database or table to pull from? Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/#findComment-986603 Share on other sites More sharing options...
RussellReal Posted January 1, 2010 Share Posted January 1, 2010 it means teh query failed and returned false. Quote Link to comment https://forums.phpfreaks.com/topic/186767-display-table-of-my-entries-from-mysql/#findComment-986616 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.