1
while($row = mysql_fetch_array($result)) {
    echo "<tr>";
        echo "<td>" . $row['mf_id'] . "</td>";
        echo "<td>" . $row['Manufacturer'] . "</td>";
    echo "</tr>";
}

I want to make the Manufacturer column clickable and return the value of the corresponding mf_id value to another page

1
  • My bad, manufacturer column :) edited Commented Aug 7, 2012 at 19:24

2 Answers 2

2

I think this is what you are looking for.

Try this:

while($row = mysql_fetch_array($result))
{
    echo "<tr>";
    echo "<td>" . htmlspecialchars($row['mf_id']) . "</td>";
    echo "<td><a href=\"yourlink.php?mf_id=" . htmlspecialchars($row['mf_id']) . "\">" . $row['Manufacturer'] . "</a></td>";
    echo "</tr>";
}

So when you click the link you will be brought to the page "yourlink.php". If you want the value that was in $row['mf_id'] do this:

$mf_id = $_GET['mf_id']

$mf_id will now hold the value that was passed to the page.

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

6 Comments

You need to use htmlspecialchars() if you don't want reserved characters erroneously ending up in your HTML.
Can you explain where this would be used? Like this? htmlspecialchars($row['mf_id'])
Yes, exactly. If you know that the ID is just going to be numeric, it isn't a big deal. But, if you have variable data that may contain characters such as " or <, then you need to use htmlspecialchars(). See my answer for an example.
Good thinking. I'll include it now
Thanks, this was indeed what I was looking for. Though how do I make it so that each link returns the corresponding mf_id value to my page? I only know how to do so through forms. Thanks again!
|
2

You can use your variables in any context you want, including anchor tags:

echo '<td><a href="', htmlspecialchars('yourpage.php?mf_id=' . $row['mf_id']), '">',
    htmlspecialchars($row['mf_id']), '</a></td>';

If you want to link the entire row, you will need a JavaScript click handler. Otherwise, simple anchor tags will do what you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.