Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Unexpected t_string error

    Hello,

    Gettin back to php once again. I'm starting simple but I can't figure out what the problem with my code is:

    Code:
          echo '<p><b>'.$row['title'].'</b><br />
    	'.$row['sd'].'
      
           '.$row['post'].'<br /><br />
    	
    	 
          <i>Posted by</i> <b>'.$row['author'].'</b>;
                   
    		}
      
          }else {
      
          echo 'Apologies from Sean! At the moment, there are no displaying news publications! 
           Please check back soon!';
     
          }
     
          ?>
    I am getting the "
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'" error near the Apologies line.

    Thanks,

    Sean
    Last edited by Socca; 03-28-2009 at 02:33 PM.

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    28
    Thanks
    3
    Thanked 4 Times in 4 Posts
    There's no quote on the end of your last echo.

  • #3
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Actually it was already there but the [PHP] tags don't show it so I changed it to [CODE] on the forum post. Any other ideas?

  • #4
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    First echo is missing single quote. Replace:

    PHP Code:
    echo '<p><b>'.$row['title'].'</b><br />
        '
    .$row['sd'].'
      
           '
    .$row['post'].'<br /><br />
        
         
          <i>Posted by</i> <b>'
    .$row['author'].</b>; 
    with:

    PHP Code:
    echo '<p>
            <b>'
    .$row['title'].'</b><br />
            '
    .$row['sd'].' '.$row['post'].'<br /><br />
            <i>Posted by</i> <b>'
    .$row['author'].'</b>'

  • Users who have thanked steelaz for this post:

    Socca (03-27-2009)

  • #5
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Ah Stupid mistake! Thanks Steelaz!
    Do you know maybe Why the system doesn't show the else echo?
    This is the full file:
    Code:
       <html>
      
          <head>
    	
             
          </head>
      
          <body>
       
          <?php
      
          include ('_mysql.php');
    
      
          $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC";
      
          $result = @mysql_query($query);
       
           
      
          if ($result) {
      
          while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    
          $news_id = $row['id'];
        
               
    
          echo '<p><b>'.$row['title'].'</b><br />
    	
      
           '.$row['post'].'<br /><br />
    	
    	 
          <i>Posted by</i> <b>'.$row['author'].'</b> on '.$row['sd'].'';
                   
    		}
      
          }else {
      
          echo '<b>Apologies from Sean Lofgren! At the moment, there are no displaying news publications! Please check back soon!<b>';
     
          }
     
          ?>
      
          </body>
      
          </html>
    Any ideas?

  • #6
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    if ($result) - will check if query was successful. Query can be successful but return 0 results. For that you need mysql_num_rows() function. See the code below.


    PHP Code:
    <html>
        <body>

    <?php
        
    include ('_mysql.php');
        
        
    $query "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC";
        
        
    $result = @mysql_query($query);

        if (
    $result
        {
            if (
    mysql_num_rows($result) > 0)
            {
                while (
    $row mysql_fetch_array($resultMYSQL_ASSOC))
                {
                    
    $news_id $row['id'];
                    echo 
    '<p><b>'.$row['title'].'</b><br />
                           '
    .$row['post'].'<br /><br />
                        <i>Posted by</i> <b>'
    .$row['author'].'</b> on '.$row['sd'].'';
                }  
            }
            else
            {
                echo 
    '<b>Apologies from Sean Lofgren! At the moment, there are no displaying news publications! Please check back soon!<b>';
            }
            
        }
        else 
        {
            echo 
    '<b>Database error: 'mysql_error();
        }
    ?>

        </body>
    </html>

  • Users who have thanked steelaz for this post:

    Socca (03-28-2009)

  • #7
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Works now! Thanks alot. Last but not least do I use the Select tool to only display the last 3 or 5 articles or do I need to add some more lines? Is there no

    $query = "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts LATEST 5 DESC"


    ? THanks again!

  • #8
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    PHP Code:
    $query "SELECT id, title, author, post, DATE_FORMAT(date, '%M %d, %Y') as sd FROM news_posts ORDER BY date DESC LIMIT 5"
    assuming you want it ordered by the date field DESC
    John

  • Users who have thanked PappaJohn for this post:

    Socca (03-28-2009)

  • #9
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Ah It was limit. I saw on some work they used latest but i guess that was probably a different function. Thanks once again!

  • #10
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    If I wanted a function whcih allowed me to view news post seperately...like if i did news.php?id=2 it would show me Id#2 news article how would i get around that? If you could simplify your explanation so that I could try first on my own..and if I needed help ill ask again that would be great.

  • #11
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    First you would need to get id parameter from URI string:

    PHP Code:
    // (int) typecasting makes sure that value is integer
    $id = (int)$_GET['id']; 
    Then you can use it in the query:

    PHP Code:
    $query "SELECT * FROM `news_posts` WHERE `id` = '{$id}'"

  • #12
    New Coder
    Join Date
    Nov 2007
    Posts
    34
    Thanks
    10
    Thanked 0 Times in 0 Posts
    OK I tried first adding those two things into the news.php file and that didn't work. I guess it wasn't so easy. Would it be better if I made a new php file to do the above? Or what should i do in news.php to get that result?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •