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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question parse error and html table filled from mysql db

    hey folks, I am getting a "Parse error: syntax error, unexpected T_SL" on line 97 of this code. It is a php file where I am trying to get a table (in html) to grow and fill according to the information in my DB. This is for a beer-rating site, the table will show details about each beer and the name can also be linkedAm I doing this firght with the for-loop? Any suggestions and fixes would be greatly appreciated.

    Code:
    <?php
    // Set connection details.
     $db_hostname = // Host 
     $db_username = // Username 
     $db_pass = // Password
     $db_name = // Database Name 
    
    
    // This initializes the connection to the database.
      $con = mysql_connect($db_hostname, $db_username, $db_pass) or die('Could not connect to mysql server.');
    
    // Connect to the specific database.
       mysql_select_db($db_name, $con) or die('Could not select database.');
    
    // Select variable, with LIMIT 1, just in case.
         $sql = "SELECT * FROM beers WHERE `id`='$id'";
    
    // Query variable, with error handling.
         $result = mysql_query($sql) or die('The error was: ' . mysql_error() . '<br />The query was: ' . $sql);
    
    // Begin the while loop, also executing the query variable.
           while($row = mysql_fetch_assoc($result)) {
    
    // Set Variables...
            $beername = $row['beername'];
            $date = $row['date'];
            $style = $row['style'];
            $brewer = $row['brewer'];
    		$abv = $row['abv'];
    		$brewer_url = $row['brewer_url'];
    		$cost = $row['cost'];
    		$avg_score = $row['avg_score'];
    		$id = $row['id'];
    		   }
    //echo HTML Header and navigation
    	echo <<<HTML
    <html>
    <head>
    <title>Beer Club NJ</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body background="homebg.jpg" bgproperties="fixed" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <center>
    <table bgcolor="#ffffff">
    <tr>
    <td>
    <script src="sorttable.js">
    <a href="index.html"><img src="Banner.jpg" border="0"></a>
    <center>
    <table width="720">
    <tr>
    <th align="left"> <a href="beers.html"><IMG style="filter: alpha(Opacity=100, FinishOpacity=0, Style=2)" src="beers.gif" width="150" height="37.5" border="0"></a></th>
    <th align="left"> <a href="learn.html"><img src="learn.gif" width="150" height="37.5" border="0"></th>
    <th align="left"> <a href="http://beerclubnj.proboards.com/index.cgi?board=general"><img src="talk.gif" width="150" height="37.5" border="0"></a></th>
    </tr>
    <tr>
    <th align="right"> <a href="idiots.html"><img src="idiots.gif" width="150" height="37.5" border="0"></a></th>
    <th align="right"> <a href="articles.html"><img src="articles.gif" width="150" height="37.5" border="0"></a></th>
    <th align="right"> <a href="contacts.html"><img src="contacts.gif" width="150" height="37.5" border="0"></a></th>
    </tr>
    </table>
    <img src="beerstext.gif" border="0">
    <br>
    Click on a catagory to re-order the list. Scores are an average score between <br>all raters so make sure to look at the beer's review for more information. <br>The type of beer is also a broad span which is narrowed down on each individual beer's review. <br>So check them out, find out what you like, and then hit the liquor store!
    </center>
    <center>
    <table bgcolor="#ffffff" class="sortable" cellpadding="5">
    <tr>
    <th>
    Beer Name
    </th>
    <th>
    Brewer
    </th>
    <th>
    Style
    </th>
    <th>
    Average Score
    </th>
    <th>
    Date Reviewed
    </th>
    </tr>
    HTML;
    
    //create a table displaying info in table including link to each beer profile
    //loop so that there are only as many rows in table as in db
    
    if (mysql_count_rows($query) > 0)
    {
        while ($row = mysql_fetch_assoc($result))
        {
            for ($i = 0; $i < count($row); $i++)
            {
    			
    echo <<<TABLE     
    <tr><td><a href="beers.php?id=$id">$beername</a></td>
    <td>$brewer</td>
    <td>$style</td>
    <td>$avg_score</td>
    <td>$date</td>
    </tr>
    TABLE;
    
            }
        }
    
    }
    
    //echo HTML footer and mailing list form
    
    	echo <<<FOOT
    </table>
    </center>
    </td>
    </tr>
    <tr>
    <td>
    <center>
    //mailing list form will go here
    Materials Copywrite of BeerClubNJ and Bread 'n' Buttah Design LLC. 2009
    <br>
    <a href="sponsors.html">Sponsors and Special Thanks</a>
    </center>
    </td>
    </tr>
    </table>
    </center>
    </body>
    </html> 
    FOOT;
    
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Yeah, this one is a tough one to see. Took me a few minutes to find this:
    PHP Code:
    echo <<<TABLE     // <-- REMOVE ALL WHITE SPACE HERE
    <tr><td><a href="beers.php?id=$id">$beername</a></td>
    <
    td>$brewer</td>
    <
    td>$style</td>
    <
    td>$avg_score</td>
    <
    td>$date</td>
    </
    tr>
    TABLE
    Heredoc syntax requires the heredoc operator (>>>) followed by the identifier (TABLE) followed immediately by the linefeed.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    me....dumb.

    ACK! Thanks Fou Lu! Had no clue that white space could matter! You're a lifesaver! How about the loop for the table? does that seem right?? thanks again!

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You don't need the for loop. The while loop will take care of it. As it is now your table code will print out the size of the number of rows of your result times the number of rows of your result. That isn't what you want.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    The loops are incorrect. You're first run:
    PHP Code:
    // Begin the while loop, also executing the query variable.
           
    while($row mysql_fetch_assoc($result)) {

    // Set Variables...
            
    $beername $row['beername'];
            
    $date $row['date'];
            
    $style $row['style'];
            
    $brewer $row['brewer'];
            
    $abv $row['abv'];
            
    $brewer_url $row['brewer_url'];
            
    $cost $row['cost'];
            
    $avg_score $row['avg_score'];
            
    $id $row['id'];
               } 
    will populate you're variables with only the last result, and the second one:
    PHP Code:
    if (mysql_count_rows($query) > 0)
    {
        while (
    $row mysql_fetch_assoc($result))
        {
            for (
    $i 0$i count($row); $i++)
            {
                
    echo <<<TABLE
    <tr><td><a href="beers.php?id=$id">$beername</a></td>
    <td>$brewer</td>
    <td>$style</td>
    <td>$avg_score</td>
    <td>$date</td>
    </tr>
    TABLE;

            }
        }


    will fail for two reasons. The first is that $query isn't defined anywhere, and the second is that mysql_count_rows doesn't exist.
    So, from the looks of it, remove this:
    PHP Code:
    // Begin the while loop, also executing the query variable.
           
    while($row mysql_fetch_assoc($result)) {

    // Set Variables...
            
    $beername $row['beername'];
            
    $date $row['date'];
            
    $style $row['style'];
            
    $brewer $row['brewer'];
            
    $abv $row['abv'];
            
    $brewer_url $row['brewer_url'];
            
    $cost $row['cost'];
            
    $avg_score $row['avg_score'];
            
    $id $row['id'];
               } 
    And change this:
    PHP Code:
    if (mysql_count_rows($query) > 0)
    {
        while (
    $row mysql_fetch_assoc($result))
        {
            for (
    $i 0$i count($row); $i++)
            {
                
    echo <<<
    TABLE     
    <tr><td><a href="beers.php?id=$id">$beername</a></td>
    <
    td>$brewer</td>
    <
    td>$style</td>
    <
    td>$avg_score</td>
    <
    td>$date</td>
    </
    tr>
    TABLE;

            }
        }


    to this:
    PHP Code:
        while ($row mysql_fetch_assoc($result))
        {
            
    $beername $row['beername'];
            
    $date $row['date'];
            
    $style $row['style'];
            
    $brewer $row['brewer'];
            
    $abv $row['abv'];
            
    $brewer_url $row['brewer_url'];
            
    $cost $row['cost'];
            
    $avg_score $row['avg_score'];
            
    $id $row['id'];

    echo <<<
    TABLE     
    <tr><td><a href="beers.php?id=$id">$beername</a></td>
    <
    td>$brewer</td>
    <
    td>$style</td>
    <
    td>$avg_score</td>
    <
    td>$date</td>
    </
    tr>
    TABLE;

    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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