Jump to content

Php variable in Hyperlink


ananaz

Recommended Posts

Hello im wondering how i can make a hyperlinks adress be a set after a variable.

this is my php:

 

$result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;");
$result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;");

<html>
<a href="???"> <p class="note-general"> The first link </p>
<a href="???"> <p class="note-general"> The the second link </p>
</html>

 

The important thing is that the url from $result1 will link under "the first link" and url from $result2 link under "the second link".

Link to comment
https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/
Share on other sites

<a href=<?php $row1 = mysql_fetch_row($result1);echo $row1[2];?> > <p class="note-general"> The first link </p>

<a href=<?php $row2 = mysql_fetch_row($result2);echo $row2[2];?> > <p class="note-general"> The second link </p>

 

I'd do it like this

$result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;")

$link1 = $result1;

 

$result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;");

$link2 = $result2;

 

<html>

<a href="<echo ''.$link1.'';?>"> <p class="note-general"> The first link </p></a>

<a href="<echo ''.$link2.'';?>"> <p class="note-general"> The the second link </p></a>

</html>

(should the href be inside of the p tag?)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.