PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #16  
Old June 11th, 2002, 06:26 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: more issues

Just a guess here, but remember that PHP's 'date' function is looking for a UNIX timestamp, not the date values that is typically returned from a MySQL query. So, if your DB date is "20020610162214", you need to covert that to UNIX timestamp -- easiest to do that in the SELECT statement: "select unix_timestamp(date) as date, email, name, news ...".

Reply With Quote
  #17  
Old June 11th, 2002, 11:27 AM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: more issues

Simply format it when you pull it from the database, i would usually do something like :

php Code:
Original - php Code
  1.  
  2. <?
  3.   $qry = "SELECT * FROM news LIMIT 5 ORDER BY dateadded"
  4.   $result = mysql_query($qry);
  5.  
  6.   while ($row = mysql_fetch_assoc()) {
  7.     // format date
  8.     print(date("F j, g:i a", strtotime($row["dateadded"])));
  9.   }
  10. ?>


strtotime works like a charm, and date() needs the number of seconds since whenever long ago..

Hope this helps

Reply With Quote
  #18  
Old June 11th, 2002, 07:53 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: more issues

thanks for all your help guys, I tried them out, and None of them seems to be working, so Now I'm thinking if there is a way of doing it like in matts newsscript, by sending it when the news is submitted, maybe not into a timestamp row but maybe just a text row?

Reply With Quote
  #19  
Old June 11th, 2002, 10:23 PM
notepad notepad is offline
Codewalkers Loyal (3000 - 3499 posts)
 
Join Date: Apr 2007
Location: Central, IL USA
Posts: 3,214 notepad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via AIM to notepad
RE: more issues

hm.. i'm lost.

Reply With Quote
  #20  
Old June 12th, 2002, 08:26 AM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: more issues

Oh geez, you using TIMESTAMP type.... use datetime type and manually insert the time using now()

ie. insert query : "INSERT INTO news (dateadded) VALUES (now())"

kindof thing, then the strtotime will work.. either that or manually dissect and format the timestamp first..

Reply With Quote
  #21  
Old June 12th, 2002, 08:20 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: more issues

okay now I get this error
Warning: Wrong parameter count for mysql_fetch_assoc() in /home/gmflp/public_html/news.php on line 80


here is my code

php Code:
Original - php Code
  1.  
  2. <?php
  3. $db = @mysql_connect("localhost", "****", "****");
  4. if (!$db) {
  5.   echo( "<p>Unable to connect to the " .
  6.         "database server at this time.</p>" );
  7.   exit();
  8. }
  9. mysql_select_db("*****", $db);
  10. if (! @mysql_select_db("*****") ) {
  11.   echo( "<p>Unable to locate the news " .
  12.         "database at this time.</p>" );
  13.   exit();
  14. }
  15. $qry = "SELECT * FROM news LIMIT 5 ORDER BY id";
  16.   $result = mysql_query($qry);
  17.  
  18.   while ($myrow = mysql_fetch_assoc()) {
  19.     // format date
  20.     print(date("F j, g:i a", strtotime($row["date"])));
  21. }
  22. {
  23. echo( "<b>".$myrow['title']."</b> - posted by <a href=mailto:".$myrow['email'] . " class=link>".$myrow['name']. "</a> " . $myrow['date']);
  24. echo( "<br>".$myrow['news'] );
  25. echo( "<br><b><font class=rm><a href=vnews.php?id=" .$myrow[id]. " class=rm>Comments: (0)</a></b></font>" );
  26. echo( "<p>" );
  27. }
  28.  
  29. ?>


Also I have no clue about the insert into news bit, but we can get to that bit later, cheers for your help

Reply With Quote
  #22  
Old June 12th, 2002, 08:32 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: more issues

php Code:
Original - php Code
  1. while ($myrow = mysql_fetch_assoc()) {


should be

php Code:
Original - php Code
  1. while ($myrow = mysql_fetch_assoc($result)) {


Reply With Quote
  #23  
Old June 12th, 2002, 09:02 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: more issues

I'm still getting the same error :/

Reply With Quote
  #24  
Old June 12th, 2002, 10:35 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: more issues

Sorry, bout that.. yeah, it's supposed to be mysql_fetch_assoc($result).. try printing $result, if you don't get something like "Resource id #xx" then print(mysql_error()) and see what that gives you..

Reply With Quote
  #25  
Old June 13th, 2002, 12:05 AM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: more issues

okay, Now I think I done this right 'cause now I'm getting error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/gmflp/public_html/news.php on line 79
- posted by

Reply With Quote
  #26  
Old June 13th, 2002, 01:57 AM
Matt Matt is offline
Moderator
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: more issues

That's an invalid query, try this:

$qry = "SELECT * FROM news ORDER BY id LIMIT 5";

Reply With Quote
  #27  
Old June 13th, 2002, 07:56 AM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: more issues

Sorry, i wasn't concentrating on the SQL statement, coz i thought u were gonna replace it.. ;)

Reply With Quote
  #28  
Old June 13th, 2002, 07:54 PM
russ russ is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: London, UK
Posts: 129 russ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to russ Send a message via Yahoo to russ
RE: more issues

okay, good news, the date is showing, WEHEY, thanks guiys, bad news, it looks abit "funny", http://gmflp.l33t.ca/news.php this will show you what I mean

here is my code at the mo

php Code: