andy_b_1502 Posted February 5, 2012 Share Posted February 5, 2012 hi everyone, Whats the best way to put my displayed php into my table? I already have gotten to the point where it is displayed, but it looks basic, so i want it to look like the table below it.... i just havent quite figured out how to "space" the data out so it looks better? Is it just a case of printing out what i want where in the table? or is it something more complex? http://www.removalspace.com/indextwo.php Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/ Share on other sites More sharing options...
litebearer Posted February 5, 2012 Share Posted February 5, 2012 Simply design a 'this is how I would like it to look' page using css and html and hand entered test data. when you have a 'look' you like, experiment how you would replace the test data with php generated data. The key is EXPERIMENT Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1314814 Share on other sites More sharing options...
andy_b_1502 Posted February 6, 2012 Author Share Posted February 6, 2012 but thats what i've got in the table below. it's how i want it to look, im just stuck on how to get little individual snippets of the mySQL table to fit it snug where i want it?? do you connect to the database first at the top of the page and then call it below in different places how? my code currently looks like this: <?php $database="my_db"; mysql_connect ("host/server", "user", "password"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=1/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> that works a treat with the "basic" un-styled table without CSS. but where i think i'm getting confused is it's fetching all the data in one go? it needs to fit inside this table markup: <table width="1083" height="313" border="2" cellpadding="1" cellspacing="2" bordercolor="#0066FF"> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> Sooooo i'm guessing it should look something like this: <?php $database="my_db"; mysql_connect ("host/server", "user", "password"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); <tr> <td>while ($get_info = mysql_fetch_row($result)){</td> <td>foreach ($get_info as $field)</td> <td>this is where i'm getting bogged down?</td> <td> </td> <td> </td> <td> </td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1315206 Share on other sites More sharing options...
andy_b_1502 Posted February 6, 2012 Author Share Posted February 6, 2012 Or is this a better way: <?php $database="my_db"; mysql_connect ("host/server", "user", "password"); @mysql_select_db($database) or die( "Unable to select database"); $results = mysql_query($sql); while ($row = mysql_fetch_array($results)) { print '<tr>'; print '<td>' . htmlentities($row['col1'] . '</td>'; print '<td>' . htmlentities($row['col2'] . '</td>'; print '</tr>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1315212 Share on other sites More sharing options...
ttocskcaj Posted February 7, 2012 Share Posted February 7, 2012 echo '<table width="1083" height="313" border="2" cellpadding="1" cellspacing="2" bordercolor="#0066FF">'; $result = mysql_query ("Select whatever data from whatever table"); while ($row = mysql_fetch_array($result)){ echo "<tr>"; // PHP loops through each row from the database and draws an HTML table row for each one. echo "<td>{$row['field1']}</td>"; echo "<td>{$row['field2']}</td>"; echo "<td>{$row['field3']}</td>"; echo "</tr>"; // End of this table row. } echo '</table>'; //We have now looped through each row, so we close the table and we're done. Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1315388 Share on other sites More sharing options...
andy_b_1502 Posted February 8, 2012 Author Share Posted February 8, 2012 thanks ttocskcaj but this doesn't display anything from my DB? Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1315924 Share on other sites More sharing options...
ttocskcaj Posted February 12, 2012 Share Posted February 12, 2012 Did you replace $result = mysql_query ("Select whatever data from whatever table"); with the right query to get the data you want? Quote Link to comment https://forums.phpfreaks.com/topic/256477-tables-and-php/#findComment-1317171 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.