0

I am creating a table by echoing results out as the following:

include 'database.php';

$pdo = Database::connect();
$sql = 'SELECT * FROM kayitlar ORDER BY id DESC';

foreach ($pdo->query($sql) as $row) 
{
    echo '<tr>';
    echo '<td>'. $row['model'] . '</td>';
    echo '<td>'. $row['problem'] . '</td>';
    echo '<td>'. $row['work'] . '</td>';
    echo '<td>'. $row['result'] . '</td>';
    echo '<td>'. $row['keywords'] . '</td>';
    echo '<td>'. $row['addedby'] . '</td>';
    echo '<td>'. $row['date_time'] . '</td>';
    echo '<td>'. $row['document'] . '</td>';
}

I allowed users to add documents and the file name is being recorded into documents after string operations. I want to display respective documents as hyperlinks. If I was using mysql_fetch array I would use

<td><a href="uploads/<?php echo $row['file'] ?>" target="_blank"> view </a></td>

but I am not good at PDO and getting synthax error everytime.

here is my erroneous code:

echo '<td>'. <a href="uploads/<?php echo $row['document'] ?>" target="_blank">view file</a>.'</td>';
Henkealg
  • 1,466
  • 1
  • 16
  • 19
Deniz
  • 29
  • 9
  • 1
    PDO has nothing to do with echoing things. It works with database. The way you echo the data is irrelevant to the database driver – Your Common Sense Mar 23 '16 at 09:08
  • 1
    You seem to lack a fundamental understanding of PHP syntax, your "erroneous" code, is full of syntax errors, you don't echo inside another echo, you don't use open / closing tags of php when you are all ready inside a pair of them, you are missing `"` or `'` around your href link – Epodax Mar 23 '16 at 09:14
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Ferrybig Mar 23 '16 at 10:45

3 Answers3

1

Your echo statement mixes inline html with echo. You should use inline html or echo a string, but not both at the same time

echo '<td><a href="uploads/' . $row['document'] . '" target="_blank">view file</a></td>';

or

<td><a href="uploads/<?php echo $row['document'] ?>" target="_blank">view file</a></td>
Philipp
  • 15,377
  • 4
  • 35
  • 52
1

simply try echo '<td><a href="uploads/'.$row['document'].'" target="_blank">view file</a></td>';

St3an
  • 726
  • 1
  • 6
  • 21
0
echo '<td><a href="uploads/'.$row['document'].'" target="_blank">view file</a></td>';
obe
  • 7,378
  • 5
  • 31
  • 40
  • 1
    please add some more details to your answer – Elzo Valugi Mar 23 '16 at 11:08
  • 1
    While this answer is probably correct and useful, it is preferred if you [include some explanation along with it](http://meta.stackexchange.com/q/114762/159034) to explain how it helps to solve the problem. This becomes especially useful in the future, if there is a change (possibly unrelated) that causes it to stop working and users need to understand how it once worked. Thanks! – Hatchet Mar 23 '16 at 12:56
  • Well another answer has already been selected so this is probably moot by now. I agree in general but I think that in this case the code is really quite self-explanatory and IMO, just like it is OK to expect a person who asks a question a minimum level of effort in writing the question, it's also OK to expect that in understanding an answer. IMO even a PHP newbie should be able to compare my suggested code with his original code and understand where he was wrong, and I think that it would even be beneficial for a beginner to go through this process... – obe Mar 23 '16 at 13:21
  • To be accurate - there was no question. The author wrote that he was getting a syntax error and provided the faulty code. I corrected it and sent it back as a resolution and as reference material for him to learn from. I did not intend to critique or request clarification. I was given erroneous code and corrected it in a manner that, in my opinion, is self-explanatory enough for the author to use and learn from. You may disagree but I would say that to each his own. If my answer is not up to par with the site guidelines due to lack of accompanying English text then feel free to remove it... – obe Mar 23 '16 at 17:00