How to display row id into href tag using php and mysql

So, I am attempting to append an ID from a table to an href tag so the result is this:

<a href="cmslist.php?pageid=1">My Link</a>

I am attempting to use code as shown below -- but the result is this:

<a 1="" href="cmslist.php?pageid=">My Link</a>

Clearly i am doing something wrong. What could it be?

Thanks in advance for your assistance.
Jason


<?php
$sql4 = "SELECT pageid FROM pages WHERE pageid='".$siteid."' LIMIT 1";
$result4 = mysql_query($sql4) or die(mysql_error());
if($row=mysql_fetch_assoc($result4)){
 echo "<a href='cmslist.php?pageid='".$row['pageid'].">My Link</a>";
}
?>

Open in new window

jsvb1977Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gamebitsCommented:
try

if($row=mysql_fetch_assoc($result4)){
 echo "<a href="cmslist.php?pageid=\"".$row['pageid']."\">My Link</a>";
}

0
gamebitsCommented:
sorry


if($row=mysql_fetch_assoc($result4)){
 echo "<a href=\"cmslist.php?pageid=".$row['pageid']."\">My Link</a>";
}

0
rkeith2412Commented:
you are putting the pagid outside of the single quotes around the URL try this.
<?php
$sql4 = "SELECT pageid FROM pages WHERE pageid='".$siteid."' LIMIT 1";
$result4 = mysql_query($sql4) or die(mysql_error());
if($row=mysql_fetch_assoc($result4)){
 echo "<a href='cmslist.php?pageid=".$row['pageid']."'>My Link</a>";
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

KendorCommented:
its a missing single quote in your output.

remember that you can also use the retrieved name values for the link name...

<?php
$sql4 = "SELECT pageid,pagename FROM pages WHERE pageid='".$siteid."' LIMIT 1";
$result4 = mysql_query($sql4) or die(mysql_error());
if($row=mysql_fetch_assoc($result4)){
 echo "<a href='cmslist.php?pageid='".$row['pageid']."'>".$row['pageid']."</a>";
}
?>

Open in new window

0
KendorCommented:
of which above is wrong... did the quote mistake myself :)


echo "<a href='cmslist.php?pageid=".$row['pageid']."'>".$row['pagename']."</a>";

Open in new window

0
jsvb1977Author Commented:
I am sure all posts were correct -- but these are the two I am using on my end. nice catch on the missing single quote. I was staring at this for too long and could not see what was right in front of my eyes.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.