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:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old June 8th, 2002, 04:39 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
more issues

okay, I was reading php / mysql tutorial, and I thought, lets try a news script, but I get this error

Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/gmflp/public_html/test.php on line 19


here is my code

php Code:
Original - php Code
  1.  
  2. <HTML>
  3. <body>
  4. <?php
  5. $db = @mysql_connect("localhost", "*****", "*****");
  6. if (!$db) {
  7.   echo( "<p>Unable to connect to the " .
  8.         "database server at this time.</p>" );
  9.   exit();
  10. }
  11. mysql_select_db("******", $db);
  12. if (! @mysql_select_db("*****") ) {
  13.   echo( "<p>Unable to locate the learn " .
  14.         "database at this time.</p>" );
  15.   exit();
  16. }
  17. $result = mysql_query("SELECT * FROM newsdb",$db);
  18.  
  19. while($myrow = mysql_fetch_array($result))
  20. echo( "$myrow["<b>title<b>"] - posted by <a href=mailto:$myrow["email"] class="gmflp">$myrow["name"]</a> $myrow["date"]" );
  21. echo( "<br>$myrow["news"]" );
  22.  
  23.  
  24. ?>
  25. </body>
  26. </HTML>

Reply With Quote
  #2  
Old June 8th, 2002, 06:00 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

Try changing the following:
while($myrow = mysql_fetch_array($result))
{
echo( "<b>".$myrow['title']."<b>- posted by <a href=mailto:".$myrow['email']."class="gmflp">".$myrow['name']."</a>".$myrow['date'] );
echo( "<br>".$myrow['news'] );
}

Reply With Quote
  #3  
Old June 8th, 2002, 08:07 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 that man, it works now, is there anyways of reversing the data?? and how to show a selected No. eg, show the last 5?

Reply With Quote
  #4  
Old June 9th, 2002, 04:44 AM
EvilivE EvilivE is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Milwaukee, WI USA
Posts: 291 EvilivE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to EvilivE
RE: more issues

You can use "ORDER BY" to get your results in ascending or descending order.

ex: ORDER BY _fieldName_ desc

You can use "LIMIT" to only get a certain amount returned in your result.

ex: LIMIT _number_

So in order to get what you asked for the last 5, you would use something like this:

SELECT * FROM newsdb ORDER BY _fieldName_ LIMIT 5

Hope that helps.

Reply With Quote
  #5  
Old June 10th, 2002, 08:39 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

ah, thank you, works like a charm. Now does anyone know how I could add a comments section on my news program??

Reply With Quote
  #6  
Old June 10th, 2002, 09:25 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

also, I have timestamp on the date at the moment, I was wondering how I can change the date into Monday, June 10th 8:25pm

Reply With Quote
  #7  
Old June 10th, 2002, 09:59 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


Reply With Quote
  #8  
Old June 10th, 2002, 10:34 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, so I want to format the date like this date("F j, g:i a"); would I have to format it before it goes to the database or when its displayed?

Reply With Quote
  #9  
Old June 10th, 2002, 10:42 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

say.. $timestamp = 1002990103083;

then..

print(date("F j, g:i a", $timestamp));

Reply With Quote
  #10  
Old June 10th, 2002, 10:51 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 get unexpected T_VARIABLE when I put that in

Reply With Quote
  #11  
Old June 10th, 2002, 11:03 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

uhh sorry it needs to be formated properly.. um. try

echo date("F j, g:i a", $timestamp);

or (' single quotes ')

print(date('F j, g:i a', $timestamp);

ya know..

Reply With Quote
  #12  
Old June 10th, 2002, 11: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

sorry to bug u again mate, appreciate the help, but where ever I put
echo date("F j, g:i a", $timestamp);
I just get
December 31, 7:00 pm and still the same 20020610162214 printed too

Reply With Quote
  #13  
Old June 10th, 2002, 11:58 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

HMM.. not sure how ur doing it but try this.

$timestamp = "20020610162214";
$display = date("F j, g:i a", $timestamp);

print("$display");

it should work i don't see any reason why it wouldn't work :-/

Reply With Quote
  #14  
Old June 11th, 2002, 12:04 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

hey man, its might be best for me to show you 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. $result = mysql_query("SELECT * FROM newsdb ORDER BY id desc LIMIT 5",$db);
  16. while($myrow = mysql_fetch_array($result))
  17. {
  18. echo( "<b>".$myrow[