truck7758 Posted February 20, 2008 Share Posted February 20, 2008 Hi All, I currently have a table in mysql called supplier(suppid, name, address, telno, fax, website, accountno, accountmanager, email, accountlogin, accountpwd, otherinfo) Was just wondering if it is possible to do 'select * from supplier' and then show the results in a table. Also, new suppliers are going to be added so the table will need to be able to handle these as they are added as well. Hope this makes sense, Thanks in advance, Mike Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 Check out Example #1: http://us2.php.net/mysql#mysql.examples Quote Link to comment Share on other sites More sharing options...
numan82 Posted February 20, 2008 Share Posted February 20, 2008 hi If you can write the code than it is much better to respond on that instead of confusing statements. Thanks Numan Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 20, 2008 Author Share Posted February 20, 2008 Hi rhodesa, I have copied the example and edited it to suit my particulars and have come up with the following: <?php // Connecting, selecting database $mysqli = new mysqli('localhost','root','newr00t'); $mysqli->select_db('orders'); // Performing SQL query $result = $mysqli->query("SELECT * FROM supplier"); // Printing results in HTML echo "<table>\n"; while($line = $result->fetch_array()) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset mysqli_free_result($result); // Closing connection $result->close(); ?> Now, although this does display the results from my table it is displaying everything twice and it also doesnt look very tidy. was kinda hoping for a table with visible rows and columns if this is possible. Thanks for your support, Mike Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 20, 2008 Author Share Posted February 20, 2008 ok, i have changed fetch_array to fetch_assoc and it now displays only once. would it now be possible to insert visible rows and columns with column headers etc Cheers, Mike Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 Couple things... 1) Never post your passwords with your code. Replace them with stars: ******** 2) Please use the code button when posting blocks of code. It's the one with the # sign on the toolbar Glad you got it working. To use column headings use the following: <table> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>etc</th> </tr> <?php // Connecting, selecting database $mysqli = new mysqli('*****','*******','*****'); $mysqli->select_db('orders'); // Performing SQL query $result = $mysqli->query("SELECT * FROM supplier"); while($line = $result->fetch_array()) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value</td>\n"; } echo "\t</tr>\n"; } // Free resultset mysqli_free_result($result); // Closing connection $result->close(); ?> </table> Quote Link to comment Share on other sites More sharing options...
aschk Posted February 20, 2008 Share Posted February 20, 2008 What you need is some styling attributes for your html table. Thus echo "<table>\n"; becomes echo "<table border=\"1\">\n"; This should help you get some layout to it. Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 20, 2008 Author Share Posted February 20, 2008 Thanks guys a combination of the last 2 posts has left me with exactly what i require although there is still 1 error showing up: Warning: Couldn't fetch mysqli_result in c:\webs\test\createingviewsuppliers2.php on line 27 Line 27 is: $result->close(); Thanks, Mike Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 20, 2008 Share Posted February 20, 2008 That line should probably be: $mysqli->close(); Quote Link to comment Share on other sites More sharing options...
truck7758 Posted February 20, 2008 Author Share Posted February 20, 2008 you my friend are an absolute genius. Thanks for all your help, Mike 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.