0

Im trying to pass a variable in the URL and to post the variable on the page. I currently have a table and a variable named $record['Filename']. The value is not displaying correctly.

Right now I have the following

while($record = mysql_fetch_array($mydata)){ 
    echo "<tr>"; 
    echo "<td>" ."<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>". " </td>";
    echo "<td>" . $record['Description'] . "</td>";

    echo "</tr>"; 
}
2
  • and what is your question ? Commented Aug 6, 2015 at 18:39
  • you cannot embed php-in-php, and using quoted array keys in a "-quoted string is bad php, unless you use the {} extended syntax. Commented Aug 6, 2015 at 18:40

3 Answers 3

2

PHP strings 101:

echo "<td>" ."<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>". " </td>";
             ^--start string                                             end string --^

Since you never "exit" your "-quoted strings, your . are just plaintext periods, not concatenation operators.

You probably want this:

    echo <<<EOL
<td><a href="Info.html?page={$record['Filename']}">{$record['Filename']}</a></td>
EOL;

Notice how using a heredoc removes the need to hop in/out of string mode, and you can use proper quoting in the HTML. Also note the {}-extended string syntax around the variables.

Sign up to request clarification or add additional context in comments.

Comments

0

try to change,

<a href='Info.html?page='.$record['Filename'].> $record['Filename'] </a>

to

<a href="Info.html?page=<?php echo $record['Filename'];?>"> <?php echo $record['Filename'];?> </a>

Comments

0

Use single quotes instead of double quotes. It's faster and more efficient.

while($record = mysql_fetch_array($mydata)){ 
    echo '<tr>'; 
    echo '<td><a href="Info.html?page='.$record['Filename'].'">'.$record['Filename'].'</a></td>';
    echo '<td>'. $record['Description'].'</td>';
    echo '</tr>'; 
}

2 Comments

the processing time difference between " and ' strings is essentially zero, unless you're running a facebook-sized operation.
That's why I mentioned that ;) Essentially zero here, essentially zero there and overall we're having significant time to save.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.