BrentonHale Posted December 29, 2009 Share Posted December 29, 2009 Ever time I play around with the code -- i get an error message and then nothing appears. I've been stuck on this page for three days. At first I was not able to connect to the database, but that HAS BEEN resolved. I just need some help with formatting the results that appear in the browser. Try loading this page in your browser and see what I mean. <?php $page_title = 'View the Current Users'; include ('./header.html'); // Page header. echo '<h1 id="mainhead">Registered Users</h1>'; $username = "username"; $password = "password"; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("sitename",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT user_id, first_name, last_name, registration_date FROM users"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "first_name:".$row{'first_name'}."last_name:" .$row{'last_name'}."registration_date:". $row{'registration_date'}."<br>"; //display the results } //close the connection mysql_close($dbhandle); include ('./footer.html'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186563-need-help-making-query-results-more-appealing-and-readable/ Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 Add these two lines after your opening tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); That should list any and all errors in your code preventing it from being displayed. As for formatting, What do you mean? What are you wanting to do? You're being fairly vague on the problem. Quote Link to comment https://forums.phpfreaks.com/topic/186563-need-help-making-query-results-more-appealing-and-readable/#findComment-985260 Share on other sites More sharing options...
BrentonHale Posted December 29, 2009 Author Share Posted December 29, 2009 Add these two lines after your opening tag: ini_set ("display_errors", "1"); error_reporting(E_ALL); That should list any and all errors in your code preventing it from being displayed. As for formatting, What do you mean? What are you wanting to do? You're being fairly vague on the problem. For example, on the first result from database that displays in the browser: first_name:Larrylast_name:Ullmanregistration_date:2009-12-25 19:12:05 It all runs together, I would like to have spaces between the first name, last name, registration date and time. I've tried added simple html, but when I do the page stops displaying anything in the browser. Maybe it i was not coding properly. It would be nice if I could get the results in some sort of table. I need to have Name and Date Registered printed above the columns. Quote Link to comment https://forums.phpfreaks.com/topic/186563-need-help-making-query-results-more-appealing-and-readable/#findComment-985262 Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 Hm? All it needs is simple spacing in php, for example look at my linebreak version of it: while ($row = mysql_fetch_array($result)) { echo "first_name: ".$row['first_name']."\n<br/>"; echo "last_name: " .$row['last_name']."\n<br/>"; echo "registration_date: ". $row['registration_date']."<br>"; } Or spaces is fine, You just need to add them to the echo! Quote Link to comment https://forums.phpfreaks.com/topic/186563-need-help-making-query-results-more-appealing-and-readable/#findComment-985265 Share on other sites More sharing options...
Buddski Posted December 29, 2009 Share Posted December 29, 2009 <?php echo '<table>'; while ($row = mysql_fetch_array($result)) { echo "<tr> <td>first_name:</td><td>".$row{'first_name'}."</td></tr> <tr> <td>last_name:</td><td>" .$row{'last_name'}."</td></tr> <tr> <td>registration_date:</td><td>".$row{'registration_date'}."</td></tr>"; //display the results } echo '</table>'; ?> or something Quote Link to comment https://forums.phpfreaks.com/topic/186563-need-help-making-query-results-more-appealing-and-readable/#findComment-985266 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.