elentz Posted March 2, 2017 Share Posted March 2, 2017 I have a php page that gets data from several txt files. I want to take those variables and put them into a table. I don't quite know how to make it work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="refresh" CONTENT="15" /> <title>Lentz Abode</title> </head> <?php //File to read $file = '/sys/bus/w1/devices/28-000004d139da/w1_slave'; //Read the file line by line $lines = file($file); //Get the temp from second line $temp = explode('=', $lines[1]); //Setup some nice formatting (i.e. 21,3) $temp = number_format($temp[1] / 1000, 2, '.', ''); $temp_f = number_format(($temp * 9.0 / 5.0 + 32.0),2,'.',''); $fahrenheit=$temp*9/5+32; $temp1=number_format($fahrenheit,1); print"<h4>The Kitchen Temp is: $temp1</h4>"; //*************BME280 code ******************** //Barometric PressureBME280 $pressure=file_get_contents("/var/www/html/BME280/pressure.txt"); $press=$pressure*0.0002952998751; $p=number_format($press,2); //Humidity BME280 $humidity=file_get_contents("/var/www/html/BME280/humidity.txt"); $hum=number_format($humidity/1000,2); //Temperature BME280 $temp2=file_get_contents("/var/www/html/BME280/temp.txt"); $t=number_format(($temp2 /1000 * 9.0 / 5.0 + 32.0),1,'.',''); print "<h4>The Barometric Pressure is: $p</h4>"; print "<h4>The Humidity is: $hum%</h4>"; print "<h4>The Temperature is: $t</h4>"; ?> <body> <style> table, th, td { border: 1px solid black; } </style> <table width="30%" <tr> <th>Temp</th> <th>Pressure</th> <th>Humidity</th> </tr> <tr> <th>$t</th> <th>$p</th> <th>%hum</th> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/ Share on other sites More sharing options...
kessie Posted March 2, 2017 Share Posted March 2, 2017 (edited) at your table use the php echo function <tr> <th><?php echo $t; ?></th> <th><?php echo $p; ?></th> <th><?php echo $hum; ?></th> </tr> Edited March 2, 2017 by cyberRobot fixed the [code][/code] tags Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543612 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 Hmm, Didn't work I got ?php echo $t; ? in the cell Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543654 Share on other sites More sharing options...
mac_gyver Posted March 3, 2017 Share Posted March 3, 2017 your opening <table ... tag is broken, so either all the markup is being considered as being inside that tag and isn't being rendered when it is sent to the browser or the markup is being rendered, but not as a table. rather than to just tell us something didn't work, tell us what result you are getting and if it's not obvious what is wrong with that result, tell us what result you expected. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543655 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 Here is what I have now. I think I fixed the broken tag. The table renders with 3 cols and 2 rows with borders all around. <body> <style> table, th, td { border: 1px solid black; } </style> <table> <tr> <th>Temp</th> <th>Pressure</th> <th>Humidity</th> </tr> <tr> <th>?php echo $t; ?</th> <th>?php echo $p; ?</th> <th>?php echo $hum; ?</th> </tr> </table> </body> </html> I result I get in the 1st col 2nd row ?php echo $t; ? the next ?php echo $p; ? and the last ?php echo $hum; ? The result I expect are the vaiables that print in the PHP code. I really appreciate the help Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543657 Share on other sites More sharing options...
benanamen Posted March 3, 2017 Share Posted March 3, 2017 It's not going to work without the opening and closing PHP brackets Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543658 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Get a proper editor or IDE with syntax highlighting. Then you don't need us to play human parsers. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543660 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 I didn't include the php in the code i last posted. That is working. Suggestion for a fdee ide? Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543663 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Netbeans or Eclipse. What are you currently using? Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543664 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 Actually nothing. I will try them out Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543673 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Actually nothing. Good old Microsoft Notepad? Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543679 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 Actually nothing. I will try them out. Do either one had the head slap function for bone head entries?? Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543682 Share on other sites More sharing options...
Jacques1 Posted March 3, 2017 Share Posted March 3, 2017 Actually nothing. So the code writes itself. Cool. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543685 Share on other sites More sharing options...
elentz Posted March 3, 2017 Author Share Posted March 3, 2017 got me on that one. I use Winsyntax for text, never trusted Notepad that much Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543686 Share on other sites More sharing options...
ginerjm Posted March 3, 2017 Share Posted March 3, 2017 You are using php in your table elements currently. Not the greatest way but you are. Try writing your code and reading it. YOu are outputting the table column headers twice here. You are moving in and out of php mode without using the proper tags. Get yourself some php reference material (the online php manual is excellent if you haven't discovered it yet) and read up on what a php tag looks like. Ex. //(in php mode already) echo "<tr>"; echo "<td>$t</td>"; echo "<td>$p</td>"; echo "<td>$hum</td>"; echo "</tr>"; This is the easy way but there are other ways too. Thought this would be clearer for your untrained eyes. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543705 Share on other sites More sharing options...
elentz Posted March 4, 2017 Author Share Posted March 4, 2017 I got netbeans and used it to make the page, and (After the light went on)and I realized what benanamen was saying, voila it all came together and works the way I want it to. Thanks everyone for the patience and nudging in the direction I needed to go. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543725 Share on other sites More sharing options...
mbrown Posted March 6, 2017 Share Posted March 6, 2017 Get a proper editor or IDE with syntax highlighting. Then you don't need us to play human parsers. What IDE do you recommend? Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543802 Share on other sites More sharing options...
Jacques1 Posted March 6, 2017 Share Posted March 6, 2017 I use PhpStorm. However, it's fairly expensive if you don't meet the requirements for a discount. A good free IDE is Netbeans. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543804 Share on other sites More sharing options...
ginerjm Posted March 6, 2017 Share Posted March 6, 2017 I use something called HTML-Kit Tools. Great editor - colorizes different things so that you can easily recognize a typo/mistake. Connects to your server to do uploads easily, has browser preview windows as well. Very inexpensive. Has a trial version too I think. Google it. Quote Link to comment https://forums.phpfreaks.com/topic/303329-how-do-i-get-a-php-variable-into-a-table/#findComment-1543805 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.