tags:

views:

32

answers:

2

I juz wana make the 'url' row data as hyperlink. Someone help plz. I already tried but the data is not displaying in the table neither the hyperlink.

while ($rows = mysql_fetch_assoc($run))
{
echo "<tr>";
echo "<td>". $rows['file_ref'] ."</td>";
echo "<td>". $rows['file_name'] ."</td>";
echo "<td>". $rows['owner'] ."</td>";
echo "<td><a href=" . $rows['url'] . "></a></td>";
echo "<td><a href=add_borrower.php?id=" . $rows['id'] . ">Borrow</a></td>";
echo "</tr>";
}
echo "</table>";
}
Thankz.

+1  A: 

You need to put some content in the a tag (note the NAME OF YOUR LINK I added). And also you haven't added quotes around the href attribute (note the \" I added).

while ($rows = mysql_fetch_assoc($run)) {
    echo "<tr>";
    echo "<td>". $rows['file_ref'] ."</td>";
    echo "<td>". $rows['file_name'] ."</td>";
    echo "<td>". $rows['owner'] ."</td>";
    echo "<td><a href=\"" . $rows['url'] . "\">NAME OF YOUR LINK</a></td>";
    echo "<td><a href=\"add_borrower.php?id=" . $rows['id'] . "\">Borrow</a></td>";
    echo "</tr>";
}

Also your coding conventions are rather inconsistent, (your mixing both kinds of quotes. You should use one or the other. See the following examples of how to quote consistently.

while ($rows = mysql_fetch_assoc($run)) {
    echo "<tr>";
    echo "<td>{$rows['file_ref']}</td>";
    echo "<td>{$rows['file_name']}</td>";
    echo "<td>{$rows['owner']}</td>";
    echo "<td><a href=\"{$rows['url']}\">NAME OF YOUR LINK</a></td>";
    echo "<td><a href=\"add_borrower.php?id={$rows['id']}\">Borrow</a></td>";
    echo "</tr>";
}

Or:

while ($rows = mysql_fetch_assoc($run)) {
    echo '<tr>';
    echo '<td>'.$rows['file_ref'].'</td>';
    echo '<td>'.$rows['file_name'].'</td>';
    echo '<td>'.$rows['owner'].'</td>';
    echo '<td><a href="'.$rows['url'].'">NAME OF YOUR LINK</a></td>';
    echo '<td><a href="add_borrower.php?id='.$rows['id'].'">Borrow</a></td>';
    echo '</tr>';
}

Or:

while ($rows = mysql_fetch_assoc($run)) {
echo <<<HTML
    <tr>
        <td>{$rows['file_ref']}</td>
        <td>{$rows['file_name']}</td>
        <td>{$rows['owner']}</td>
        <td><a href="{$rows['url']}">NAME OF YOUR LINK</a></td>
        <td><a href="add_borrower.php?id={$rows['id']}">Borrow</a></td>
    </tr>
HTML;
}
Petah
Thank u. Solved.
yash
A: 

You should edit you line to make it look like :

echo "<td><a href=" . $rows['url'] . ">" . $rows['url'] . "</a></td>";

you need content between your

<a>...</a>

And one more thing, if you want to speed up the rendering process, for string where you don't use variable, it would be better if you used single quotes ('). This would also allow you to put the values of your HTML tag attribute inside double quotes (") (required by the w3c xhtml and html5 standards)

Jeff
The comment about speed is hardly relevant. You would only save about 0.0000001 of a second
Petah
Thank u. Solved.
yash
@Petah: On the long run double quotes run slower than single quotes. In small web app it wont change a lot but in bigger ones, processing time will be cut by approximately 4%.
Jeff
Define bigger in terms of amount of quoted code. Also when a website get big enough that a 4% slow down is significant there would be more important aspects to consider, such as caching.
Petah
ok guys.. thank you very much =)
yash