Jump to content

Displaying Data In Lists


Calgaryalberta

Recommended Posts

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,

 

 

Link to comment
Share on other sites

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>";

?>

Link to comment
Share on other sites

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>";
?>

Link to comment
Share on other sites

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>";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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()");

 

 

Link to comment
Share on other sites

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>";
}
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.