Jump to content


Php news system


5 replies to this topic

#1 Latinoking

    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:Germany

Posted 04 September 2007 - 10:56 AM

I wanted to make news system for web page. Like this ,echo date and then all news what are written at that date and then it takes next aviable date and echo all news that are in that day..............But I just cant make select statement for that.

#2 Matt L

    Young Padawan

  • Members
  • Pip
  • 272 posts
  • Gender:Male
  • Location:Newcastle

Posted 04 September 2007 - 11:32 AM

mysql_query("SELECT * FROM `table` WHERE date = '$date' ORDER DESC") or die(mysql_error());
Obviously $date would be the date stamp variable.

#3 Latinoking

    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:Germany

Posted 04 September 2007 - 12:39 PM

I made such code it worked , but I would like to hear your opinion about it

conect to db :biggrin:
$gen = mysql_query("SELECT DISTINCT date FROM `news`") or die(mysql_error());
$n=0;
$d = array();
while($row = mysql_fetch_array($gen)){ 
$d[$n]=$row['date'];
$n++;
}
for ($t=0; $t<count($d); $t++){
echo "<div id=\"news\">";
echo "<fieldset>";
echo "<legend>".$d[$t]."</legend>";
$gen2 = mysql_query("SELECT teksts,nosaukums FROM `news` WHERE date='$d[$t]'") or die(mysql_error());
while($row2 = mysql_fetch_array($gen2)){ 
echo $row2['nosaukums']."\n";
echo $row2['teksts']."\n";
}
echo "</fieldset>";
echo "</div>";
}


#4 Edmachine

    Young Padawan

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Latvia

Posted 04 September 2007 - 01:07 PM

1) Heijā Latvieti :)!

2)
1. The first row is already incorrect. Since it is a comment, it should start with //. E.g.

// Connect to database
$gen = ...

About the rest... can't spot anything wrong. But don't mark these words, I don't know much.

P.S. Lai citi saprot, rakstīju visu pārējo angliski :biggrin:. Un žēl ka skola sākas :).

#5 Latinoking

    Young Padawan

  • Members
  • Pip
  • 18 posts
  • Gender:Male
  • Location:Germany

Posted 04 September 2007 - 02:07 PM

View PostEdmachine, on Sep 4 2007, 09:07 PM, said:

1) Heijā Latvieti :)!

2)
1. The first row is already incorrect. Since it is a comment, it should start with //. E.g.

// Connect to database
$gen = ...

About the rest... can't spot anything wrong. But don't mark these words, I don't know much.

P.S. Lai citi saprot, rakstīju visu pārējo angliski :biggrin:. Un žēl ka skola sākas :).


Code is working I just wanted to know maybe it can be done shorter or in some other way.

#6 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 04 September 2007 - 04:33 PM

Not sure whether you save the date as a timestamp or in a different format, because if it's the former, it's only going to group the news items saved on the exact same second, I don't think that's what your aiming for..?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users