简体   繁体   中英

Create clicable hyperlink in table using php with sql (ASC/DESC)

I'm sorry if this is unclear or difficult to understand, but explaining what I am attempting to do isn't that easy over text. In the HTML code like this entry works:

<th><a href="members.php?id=<?php echo 'name';?>&action=<?php echo $action;?>">Name</a></th>
<td><?php echo $row["name"];?></td>

but in PHP I can not advise:

echo "<th><a href="members.php?id=<?php echo 'name';?>&action=<?php echo $action;?>">Name</a></th>";
echo "<td><?php echo $row["name"];?></td>";

"id" has value /name, lastname, city, district/ 
"action" has value /ASC, DESC/

Complete table for clarity I not want to indicate. Can you help me?

Now I have:

echo "<th><a href=\"members.php?id=<?php echo 'name';?\>&action=<?php echo $action;?\>\">Name</a></th>";
echo "<td><?php echo '".$row['name']."';?\></td>";

expected result in URL is:

.../members.php?id=name&action=ASC

but my is:

.../members.php?id=<?php%20echo%20%27name%27;?\>&action=<?php%20echo%20;?\>

can you anybody help me?

Edit 2

$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo '<th><a href="members.php?id='.$row['name'].'&action=' . $action . '">Name</a></th>';

while($row = $result->fetch_assoc()) {
echo '<td> ' . $row['name'] . '</td>';

Undefined variable: 'row'

can you help me?

Try this. When you echoes that is already between <?php tags.

<?php
echo '<th><a href="members.php?id='.$row['name'].'&action=' . $action . '">Name</a></th>';
echo '<td> ' . $row['name'] . '</td>';
?>

But I suggest you to use it as a template, not from PHP (this is html code)

<th><a href="members.php?id=<?php echo $row['name']; ?>&action=<?php echo $action; ?>">Name</a></th>
<td><?php echo $row['name']; ?></td>;

Try this code 100% working..

echo '<th><a href="members.php?id='$name'&action='$action"'>Name</a></th>';
echo '<td>'$row["name"]'</td>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM