Calgaryalberta Posted January 25, 2008 Share Posted January 25, 2008 I posted a topic just recently, but I closed it because, turns out I was asking the wrong question. Because my knowledge of php is basic Im wondering if someone can recommend a tutorial or tell me what the script is to do the following: I have data in a database and I want to display it in a list, ie: Title of Event: <Title Here> Registration Start Date: <Start date displays here> Registration End Date: <End date displays here> All the information from the list is coming out of a db. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/ Share on other sites More sharing options...
pocobueno1388 Posted January 25, 2008 Share Posted January 25, 2008 There are good PHP/MySQL tutorials at these sites: www.tizag.com www.w3schools.com All you need to do is select the information from the database, here is an example snippet. <?php $query = mysql_query("SELECT title, start_date, end_date FROM table WHERE {condition}")or die(mysql_error()); $row = mysql_fetch_assoc($query); echo "<b>Title of Event</b>: {$row['title']}<br>"; echo "<b>Registration Start Date</b>: {$row['start_date']}<br>"; echo "<b>Registration End Date</b>: {$row['end_date']}<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449081 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 Ok, this is how I coded it: Tell me what needs to be edited, everything looks right to me but Im unsure, Im getting an error saying, "Unknown column 'jobtitle' in 'field list' " <?php $con = mysql_connect("mysql105.mysite4now.com","aiim","k7YuHeFv") or die('Could not connect: ' . mysql_error()); mysql_select_db("login", $con); $result = mysql_query("SELECT * FROM subscribe"); $query = mysql_query("SELECT jobtitle, jobtype, postedby, opendate, closedate, jobdescription, contact")or die(mysql_error()); $row = mysql_fetch_assoc($query); echo "<b>Job Title</b>: {$row['jobtitle']}<br>"; echo "<b>Job Type</b>: {$row['jobtype']}<br>"; echo "<b>Job Open Date</b>: {$row['opendate']}<br>"; echo "<b>Job Close Date</b>: {$row['closedate']}</br>"; echo "<b>Posted By</b>: {$row['postedby']}<br>"; echo "<b>Job Description</b>: {$row['jobdescription']}<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449108 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 First, NEVER POST USERNAME/PASSWORDS. Make sure you log into your hosting service and change these passwords immediately. Second, here is an update to your code: <?php $con = mysql_connect("#######","######","#####") or die('Could not connect: ' . mysql_error()); mysql_select_db("login", $con); $result = mysql_query("SELECT * FROM subscribe"); while($row = mysql_fetch_assoc($query)){ echo "<b>Job Title</b>: {$row['jobtitle']}<br>"; echo "<b>Job Type</b>: {$row['jobtype']}<br>"; echo "<b>Job Open Date</b>: {$row['opendate']}<br>"; echo "<b>Job Close Date</b>: {$row['closedate']}</br>"; echo "<b>Posted By</b>: {$row['postedby']}<br>"; echo "<b>Job Description</b>: {$row['jobdescription']}<br>"; echo "<hr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449110 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 will do thanks!! Thanks for the update! Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449112 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 Will do, thanks Thanks for the update! Getting an error on line 247, which is: while($row = mysql_fetch_assoc($query)){ Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449113 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 oops: while($row = mysql_fetch_assoc($result)){ Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449116 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 Fantastic, thanks a bunch! Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449118 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 I clicked, 'Topic Solved' because it is, but I wanted to see if I could get you're input on one last thing. Is there anyway I can add some sort of script to the bottom of my script above that automatically, deletes the job posting on whatever the date is the job closes? So say the job close date is listed as: 01/27/2008 The job posting automatically gets deleted off this page on that date.. Is that possible, do you have any code suggestions, or any tutorial that would explain something like that? I know how to delete things, but as far as doing something like this, because my knowledge is basic, this task seems pretty complex to me, so if you have any sample codes or tutorials on how to do something like this, that'd be fantastic Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449121 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 You have 2 options: If you want to delete it right away, you need to look into a Cronjob, which is an OS level scheduled job. But, what I would do, is leave the entries in there, in case you want to refer back to them. And just change your SQL to this: $result = mysql_query("SELECT * FROM subscribe WHERE closedate >= NOW()"); Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449134 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 And what does that do - that would just delete it off the page, but keep it in the db? Or how does that script work? Ill also type it into google and read what I can about it Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449152 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 What does changing that script do ? Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449158 Share on other sites More sharing options...
rhodesa Posted January 25, 2008 Share Posted January 25, 2008 It tells the database to only give you records where closedate is in the future. Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449159 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 thanks again Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449188 Share on other sites More sharing options...
Calgaryalberta Posted January 25, 2008 Author Share Posted January 25, 2008 After adding the above SQL statement, it is not displaying any of my records on the page now Its supposed to not show the ones with dates before the closing date correct? In the database the dates are being displayed like: 01/23/2008 - I dont know if that matters but using the $result = mysql_query("SELECT * FROM job WHERE closedate >= NOW()");while($row = mysql_fetch_assoc($result)){ its not showing any of my records, when its supposed to show the current open date, to the close date and its not supposed to show the records before the closing date. If that makes sense So say the close day was 01/25/2008 the record wouldn't show on the page. But if the close date was 01/26/2008 it would still show on the page until tomorrow <?php $con = mysql_connect("***","***","***") or die('Could not connect: ' . mysql_error()); mysql_select_db("login", $con); $result = mysql_query("SELECT * FROM job WHERE closedate >= NOW()");while($row = mysql_fetch_assoc($result)){ echo "<b>Job Title</b>: {$row['jobtitle']}<br>"; echo "<b>Job Type</b>: {$row['jobtype']}<br>"; echo "<b>Job Open Date</b>: {$row['opendate']}<br>"; echo "<b>Job Close Date</b>: {$row['closedate']}</br>"; echo "<b>Posted By</b>: {$row['postedby']}<br>"; echo "<b>Job Description</b><br>: {$row['jobdescription']}<br>"; echo "<hr>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87797-displaying-data-in-lists/#findComment-449239 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.