Solved

href inside php

Posted on 2011-03-21
14
405 Views
Last Modified: 2012-05-11
hi i am trying to add an id from a query to link to that users page but keep getting a error in my code unexpected T_STRING its because i cant get this bit to work: '<a href="users.php?id=' . $row['id']. '"></a>'
0
Comment
Question by:helpchrisplz
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35182623
here is the full code:

$sqlf = "SELECT friends.UserName,friends.id,friends.UserEmail,images.imgSmall FROM friends JOIN images ON images.memberId = friends.friendID
WHERE friends.activate = '1' AND friends.friendPage = '".$_SESSION['MemberID']."'";
$resultf = mysql_query($sqlf)or die(mysql_error());

while($row = mysql_fetch_array($resultf, MYSQL_ASSOC))
{
      $friendPlayerName = "Player Name: <br>";
$Email = "Players Email: <br>";
$title = "Your Accepted Friends: <br>";

$smallImagef = "{$row['imgSmall']}";
//$friendIDf = "{$row['id']}";
$namef = "{$row['UserName']}";
$UsersEmailf = "{$row['UsersEmail']}";


$show_friends_waitingf .= "<td>$title</td><br><td><img src='$smallImagef'></td><br><td>'<a href="users.php?id=' . $row['id']. '"></a>'</td><td>$friendPlayerName</td><td>$namef</td><br><br><td>$Email</td><td>$UsersEmailf</td>";
}
$show_friends_waitingf .= "</table>";
echo $show_friends_waitingf;
mysql_close($connection);
   
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35182649
Replace it with this:

<a href="users.php?id=" . $row['id']. "">

Open in new window


single quotes to double quotes.
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35182671
You seem to have more faults in your string,
the full line should be like this:

$show_friends_waitingf .= '<td>' . $title . ' </td><br><td><img src=\'' . $smallImagef . '\'></td><br><td>\'<a href="users.php?id=' . $row['id']. '"></a>\'</td><td>' . $friendPlayerName . '</td><td>' . $namef . '</td><br><br><td>' . $Email . '</td><td>' . $UsersEmailf . '</td>';

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Author Comment

by:helpchrisplz
ID: 35182705
ok i get the error still: syntax error, unexpected T_STRING

this is what i have now:
$show_friends_waitingf .= "<td>$title</td><br><td><img src='$smallImagef'></td><br><td><a href="users.php?id=" . $row['id']. ""></td><td>$friendPlayerName</td><td>$namef</td><br><br><td>$Email</td><td>$UsersEmailf</td>";
}
$show_friends_waitingf .= "</table>";
echo $show_friends_waitingf;

 help
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35182717
See my latest reply for the correct version.
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35182719
your quick i am looking at your last post now...... thx
0
 
LVL 2

Expert Comment

by:k_romych
ID: 35182729
try it like this
     
     <a href=\"users.php?id=$row['id']\">
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35182865
try this:

printf('<a href="users.php?id=%s">%s</a>',$row['id'],'The Link Title');
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 35182892
Also... based on your screenshot, it appears the code highlighting is telling you that you have an extra quote far before the line in question.

What are you using? Dreamweaver or npp?
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35182923
help

using:
$show_friends_waitingf .= '<td>' . $title . ' </td><br><td><img src=\'' . $smallImagef . '\'></td><br><td>\'<a href="users.php?id=' . $row['id']. '"></a>\'</td><td>' . $friendPlayerName . '</td><td>' . $namef . '</td><br><br><td>' . $Email . '</td><td>' . $UsersEmailf . '</td>';

Every thing is getting added to the table but where the href id is supposed to be there is '' and no link
the table does have content for id and if i add row id to a variable after the query it is populating the variable so am unsure why its showing as ''
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35183120
Check your code to see if $row['id'] gets populated and debug to see where it goes wrong.
0
 
LVL 1

Author Comment

by:helpchrisplz
ID: 35186420
i just removed the table as it was doing my head in

while

echo '<img src='. $row['imgSmall'].'><br>';
echo '<a href="users.php?id='. $row['ID']. '">' . $row['playername'] . '</a><br>';
echo $row['UserEmail'].'<br><br>';
0
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 35188635
Answer given for initial question.
0
 
LVL 1

Author Closing Comment

by:helpchrisplz
ID: 35191089
ok you helped
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question