I am trying to link the result of a list with href so I can pass this data to a variable $value, I am new to PHP any help will be greatly appreciated it.
here is the code;

<?php
print "<table width=61% border=1 align=center cellpadding=4>";

    $data = 10;

    for ($i=1; $i<=$data; $i++)
    {
           print "<tr><td><a href="$value=$i">Data: $i</a></td></tr>";
           print $value;
    }

print "</table>";
?>

Thank you

What do you want the variable $value to be because right now its nothing, all you would get would be

<a href="=1">Data: 1</a> ...

Thank you for your reply,
I want $value to have $i value
in other words when they click the link I wanted to pass $i to $value
I hope this make sense and thanks again for looking into this.

Gonzo, it's not making much sense at all. Here's why:

You must be aware that $i is an integer, defined an declared by your for loop. And I dont think you mean to set your href to those integers.

Perhaps you meant to get the href data from an array, using the integer as an index?

If that's the case:

print "<tr><td><a href="{$arr[$i]}">Data: $i</a></td></tr>";

But I'm not even sure if that's what you want.

Are you trying to show which item in the loop was clicked? If so, try this:

<table width="61%" border="1" align="center" cellpadding="4">
<?php
if (isset($_GET['value'])) {
    print "<tr><td><big>You clicked: $value</big></td></tr>";
}
$data = 10;
for ($i=1; $i<=$data; $i++) {
    print "<tr><td><a href=\"?value=$i\">Data: $i</a></td></tr>";
}
?>
</table>

mETAFACE THANK YOU SO MUCH YOU GOT THIS TO WORK WHEN i WAS TRYING FOR DAYS I REALLY APPRECIATE IT; I ADDED IT A SECOND LINE AFTER THE ISSET SYNTAX $value=$_GET ; and works great thanks again

<table width="61%" border="1" align="center" cellpadding="4">
<?php
if (isset($_GET['value'])) 
{
	$value = $_GET['value'];
    print "<tr><td><big>You clicked: $value</big></td></tr>";
}
$data = 10;
for ($i=1; $i<=$data; $i++) {
    print "<tr><td><a href=\"?value=$i\">Data: $i</a></td></tr>";
}
?>
</table>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.