unknownDude
unknownDude

Reputation: 33

How do I pass the information to the other page?

I have the following code which displays a table with two columns, Title and Year, when the user clicks on a title, they are sent to another page (title.php), which will give more information about that title.

echo "<table border=1>
<tr>
<th>Title</th>
<th>Year</th>
</tr>";

while ($record = mysql_fetch_array($myData)) {
    echo "<tr>";
    echo "<td><a href='title.php'>" . $record['title'] . "</a><br />" . $record['plays'] . "</td>";
    echo "<td>" . $record['year'] . "</td>";
    echo "</tr>";
}
echo "</table>";

my question is: how do i pass the title ($result['title']) from the current page to title.php?

Upvotes: 0

Views: 62

Answers (3)

joy
joy

Reputation: 11

<?php echo "<td><a href='title.php?titel=".$record['title'] . "'>" . $record['title'] . "</a><br />" . ?>

and then on the title page

<?php

echo 'Hello ' . htmlspecialchars($_GET["titel"]) . '!'; ?>

http://php.net/manual/en/reserved.variables.get.php

Upvotes: 1

user399666
user399666

Reputation: 19909

In this case, you'll want to pass information using a GET variable:

echo "<table border=1>
<tr>
<th>Title</th>
<th>Year</th>
</tr>";

while ($record = mysql_fetch_array($myData)) {
    echo "<tr>";
    echo "<td><a href='title.php?title=" . $record['title'] . "'>" . $record['title'] . "</a><br />" . $record['plays'] . "</td>";
    echo "<td>" . $record['year'] . "</td>";
    echo "</tr>";
}
echo "</table>";

Although I'd suggest passing an ID representing your primary key instead of a title so that you can grab the title after a db query on title.php

Also, you don't need mysql_fetch_array. In this case, you only need mysql_fetch_assoc.

Upvotes: 0

Schleis
Schleis

Reputation: 43800

Pass the title via GET:

echo "<td><a href='title.php?title=" . $record['title'] . "'>" . $record['title'] . "</a><br />" .  

Then in title.php check the value of $_GET['title']

Upvotes: 1

Related Questions