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?
 
rkeith2412Connect With a Mentor Commented:
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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
 
KendorConnect With a Mentor Commented:
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
All Courses

From novice to tech pro — start learning today.