Jump to content

Help with news scripts


roondog

Recommended Posts

I'm working through the php tutorials and am making a news script. In my table I have the articles numbered they also have a headline a timestamp and the story. What I want to do is only select stories from a certain month and then put them in order starting with the latest. I know i can use ORDER BY but how would only select those from a certain month.Another question, if i want each story in a new <div> so I can style them how to i do that? Do have to do a query for each story?

Link to comment
Share on other sites

Maybe you can use something like this:

$d = date('M'); // In example it says "Apr" in the database, and the month now is Apr and then it shows those newsSELECT * FROM table WHERE date = '$d' ORDER BY id DESC

The div thing, you want a different on each news or just make them valid? You can use class="" instead of id=""#something { } /* This is for id's */.something { } /* This is for classes */Hope this helps you a little :)

Link to comment
Share on other sites

i should have explained the div thing a bit more clearly.I have this code.

while($row = mysql_fetch_array($result))  {  echo "#".$row['storynum'] . "<br /> " . $row['headline']."<br />".$row['published']."<br />".$row['story'];  echo "<br />";  }

i tried to do something like this

while($row = mysql_fetch_array($result))  {  echo <div id="news">"#".$row['storynum'] . "<br /> " . $row['headline']."<br />".$row['published']."<br />".$row['story']</div>;  echo "<br />";  }

but it wouldn't work. what should i do instead.I've solved this part now looked back over the tutorial and used the table example.

Link to comment
Share on other sites

right i've got another question now. Every story has a number how do i get it to show just a certain amount of stories. Bearing in mind the top number is going to change so i cant just say between this number and this number.

Link to comment
Share on other sites

i tried to do something like this
while($row = mysql_fetch_array($result))  {  echo <div id="news">"#".$row['storynum'] . "<br /> " . $row['headline']."<br />".$row['published']."<br />".$row['story']</div>;  echo "<br />";  }

but it wouldn't work. what should i do instead.

you forgot to escape the double quote on the first echo it should look like this:
while($row = mysql_fetch_array($result)){echo "<div id=\"news\">#".$row['storynum'] . "<br /> " . $row['headline']."<br />".$row['published']."<br />".$row['story'] . "</div>";echo "<br />";}

and <div> tags need to be in between double quote too

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...