toney Posted March 13, 2012 Share Posted March 13, 2012 I am trying to have the data from my database display on a webpage the problem I am having is two fold one the 1. picture number is not displaying in order 2. how do I get the birth date to display in D- M - Y on webpage the output displays = 2007-05-11 <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sacredfa_sacred", $con); $query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, birthdate, gender FROM child_info"; $result = mysql_query($query); if(!$result) { echo "There was a problem getting the data"; } else if(!$result) { echo "There were no results"; } else { echo "<b><center>Children to be sponsored</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<table border='1'> <tr> <th>Picture Number</th> <th>First Name</th> <th>Middle Name</th> <th>First Family Name</th> <th>Second Family Name</th> <th>Birthdate</th> <th>Gender</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['picture_number'] . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['middle_name'] . "</td>"; echo "<td>" . $row['first_family_name'] . "</td>"; echo "<td>" . $row['second_family_name'] . "</td>"; echo "<td>" . $row['birthdate'] . "</td>"; echo "<td>" . $row['gender'] . "</td>"; echo "</tr>"; } echo "</table>"; } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/ Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 <?php $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, birthdate, gender FROM child_info"; $result = mysql_query($query); if(!$result) { echo "There was a problem getting the data"; } else if(!$result) { echo "There were no results"; } else { echo "<b><center>Children to be sponsored</center></b><br><br>\n"; while($row = mysql_fetch_assoc($result)) { echo "<table border='1'> <tr> <th>Picture Number</th> <th>First Name</th> <th>Middle Name</th> <th>First Family Name</th> <th>Second Family Name</th> <th>Birthdate</th> <th>Gender</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['picture_number'] . "</td>"; echo "<td>" . $row['first_name'] . "</td>"; echo "<td>" . $row['middle_name'] . "</td>"; echo "<td>" . $row['first_family_name'] . "</td>"; echo "<td>" . $row['second_family_name'] . "</td>"; echo "<td>" . $row['birthdate'] . "</td>"; echo "<td>" . $row['gender'] . "</td>"; echo "</tr>"; } echo "</table>"; } } mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326866 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 Please post formatted code, and surround it with [ php ] tags. ...and change your database password. Right now. Stop reading and go change it. You've posted it in public. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326868 Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 make this change: $query = "SELECT picture_number, first_name, middle_name, first_family_name, second_family_name, DATEFORMAT(birthdate, '%e-%c-%Y') as birthdate, gender FROM child_info ORDER BY picture_number ASC"; Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326872 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 I tried the suggestion and it did not work Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326877 Share on other sites More sharing options...
Pikachu2000 Posted March 13, 2012 Share Posted March 13, 2012 "it did not work" isn't very descriptive. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326882 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 A number of things: 1) You removed your db password from this page, but I bet you didn't change it in your actual database. You have told (according to the counter here), 35 strangers your database password, and it's indexed by google. You must change it, now. 2) Adding the ORDER BY that Muddy_Funster suggested will fix your ordering problem unless your picture number isn't stored properly in your database, but you'll have to define "didn't work" first. 3) Formatting your date output can be done with date() and strtotime(), like so: date('d-m-Y', strtotime($row['birthdate'])); Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326885 Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 ... 3) Formatting your date output can be done with date() and strtotime(), like so: date('d-m-Y', strtotime($row['birthdate'])); but I formated the date for them too, i just forgot the _ in the middle of DATE_FORMAT() was all Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326890 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 ... 3) Formatting your date output can be done with date() and strtotime(), like so: date('d-m-Y', strtotime($row['birthdate'])); but I formated the date for them too, i just forgot the _ in the middle of DATE_FORMAT() was all I didn't even notice that. Yes, everything muddy_funster said will fix all your problems if you put that underscore there. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326895 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 ok putting the _ in DATE_FORMAT worked another problem is for some reason the first record is not showing it starts from number 2 Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326903 Share on other sites More sharing options...
Muddy_Funster Posted March 13, 2012 Share Posted March 13, 2012 yeah, your php is a bit of a mess: you seem to be doing everything twice: you have an elseif checking the same condition as the first if (not sure if you expect things to change from one line to the next, but they won't in this case) and then you nest your while loop for disply inside....well....a while loop for display, which is re-assigning different values to the same variables. I'm curious, cold you post a screen cap of what your actual output page looks like? Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326913 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 http://www.sacredfamilysponsor.org/selectdata.php Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326921 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 Once you change the password to your database, you must put the new password in your code. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326923 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 i forgot to upload it back to the server so i did that the link will work now Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326926 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 while($row = mysql_fetch_assoc($result)) That line appears twice in your code. If you indent your code properly, you'll be better able to notice redundancies like this (and the elseif mentioned earlier). Remove the outer while($row = mysql_fetch_assoc($result)) and your code will stop skipping the first result. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326928 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 I removed the extra while($row = mysql_fetch_assoc($result)) it now shows the first rcord. now how do I but a link at the end of each record that will allow the searching person to view that particular record Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326935 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 Write that page. Put a link to it at the end of every row. I mean, I know you're new to PHP, but "write the page" is about as close as we can get. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326944 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 I have 860 entries in the database I need a better way to display them Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326973 Share on other sites More sharing options...
ManiacDan Posted March 13, 2012 Share Posted March 13, 2012 Write a page to display a single entry based on ID. Use $_GET['id'] Link the page you already have to that page. Add "?id={$row['picture_number']}" to the URL. Come back when you're stuck on either of those steps. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1326982 Share on other sites More sharing options...
toney Posted March 13, 2012 Author Share Posted March 13, 2012 please explain further Write a page to display a single entry based on ID. Use $_GET['id'] Link the page you already have to that page. Add "?id={$row['picture_number']}" to the URL. Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1327015 Share on other sites More sharing options...
ManiacDan Posted March 14, 2012 Share Posted March 14, 2012 please explain further No. if you need more help than this, you need to be taking a class or reading a book, not asking random people on the internet. You've already made a page to display records, where did that come from? Quote Link to comment https://forums.phpfreaks.com/topic/258837-displaying-search-info-on-webpage/#findComment-1327104 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.