php sql help

Discussion in 'PHP' started by izlik, Sep 15, 2009.

  1. #1
    can anyone tell me why the code bellow wont work? it's some problem down when i try to echo out html :/

    $sql = "SELECT * FROM flash ORDER BY date DESC LIMIT 10";
    
    $result = mysql_query($sql);
    
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    
    	 while ($row = mysql_fetch_assoc($result)) {
    
    		echo "<table border="1" width="100%">";
    			echo "<tr>";
    				echo "<td>" $row["name"]; "</td>";
    				echo "<td>" $row["size"]; "</td>";
    				echo "<td>" $row["date"]; "</td>";
    				echo "<td>&nbsp;</td>";
    				echo "<td>&nbsp;</td>";
    			echo "</tr>";
    		echo "</table>";
    		echo "<p>";
    		}
    
    		<?
    		mysql_free_result($result);
    
    ?>
    PHP:

     
    izlik, Sep 15, 2009 IP
  2. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you get an error or a notice?
     
    LogicFlux, Sep 15, 2009 IP
  3. Webmaster Perks

    Webmaster Perks Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The error is in three echo statements for your table data. They should be corrected to be:

    
      echo "<td>" . $row["name"] . "</td>";
      echo "<td>" . $row["size"] . "</td>";
      echo "<td>" . $row["date"] . "</td>";
    
    Code (markup):
     
    Webmaster Perks, Sep 15, 2009 IP
  4. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Thank you, but i still get a parse error :/

    Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';' in /index.php on line 23

    i cant se that i missed any ;
     
    izlik, Sep 15, 2009 IP
  5. Brandon_R

    Brandon_R Peon

    Messages:
    330
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try pasting line 23 here so we can take a look at it.
     
    Brandon_R, Sep 15, 2009 IP
  6. dicecities

    dicecities Well-Known Member

    Messages:
    944
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #6
    make sure you end with ?> your first sample was:
    }
    <?

    mysql_free_result($result);

    ?>

    no close php before the next open php tag --
     
    dicecities, Sep 15, 2009 IP
  7. LogicFlux

    LogicFlux Peon

    Messages:
    2,925
    Likes Received:
    102
    Best Answers:
    0
    Trophy Points:
    0
    #7
    He's not escape quotes on this line:

    echo "<table border="1" width="100%">";

    try :

    echo "<table border=\"1\" width=\"100%\">";

    or

    echo '<table border="1" width="100%">';
     
    LogicFlux, Sep 15, 2009 IP
  8. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #8

    echo "<table border=\"1\" width=\"100%\">";

    that worked, that you very very much! =)
     
    izlik, Sep 15, 2009 IP