Jump to content


Photo

PHP inside HTML question


  • Please log in to reply
3 replies to this topic

#1 lyndsey.pearce@ntlworld.com

lyndsey.pearce@ntlworld.com
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 16 April 2006 - 03:46 PM

I am struggling to create a dynamic link because I can't seem to figure out how to suitably nest some php in HTML.

Could anyone help?

This is my script:

<?php

//-----------------------
      //CONNECT TO DB
      //-----------------------

             include ('common_db.php');

                     $link_id = db_connect();


//---------------------------------------------------------------
//THIS QUERY WILL CREATE THE DYNAMIC LINKS IN THE WEB PAGE
//---------------------------------------------------------------

?>


<div id="navRight">
<h2 class="navHeader">The heading</h2>

<?php
     $selectquery = "SELECT * FROM Table";
     $result = mysql_query($selectquery) or die("Invalid query: " . mysql_error());

     while ($row = mysql_fetch_array($result))

                {
                   echo "<a href=\"\">" .$row['FieldName']. "</a>";


                }
?>

</div>

I want to place the link info into this bit:

echo "<a href=\"\">" .$row['FieldName']. "</a>";

What I have to create the link is:
echo "<a href=\"pagename.php?action=Table&id=\"$row['IDNumber']\"\">" .$row['FieldName']. "</a>";

Keep returning this error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in script.php on line 108

Can anyone help?



Cheers!

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 April 2006 - 03:50 PM

This should do it:
echo '<a href="pagename.php?action=Table&id="' . $row['IDNumber'] .'">'  . $row['FieldName'] . '</a>';


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 April 2006 - 03:51 PM

You have too many quotes it the line, try it this way:
<?php
echo '<a href="pagename.php?action=Table&id="' . $row['IDNumber'] . '">' . $row['FieldName'] . '</a>';
?>

GMTA -- Wildteen beat me to it... :-)

Ken

#4 lyndsey.pearce@ntlworld.com

lyndsey.pearce@ntlworld.com
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 18 April 2006 - 05:20 PM

Thank you both kindly!

Will give it a whirl!






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users