Solved

href inside php

Posted on 2011-03-21
14
406 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

821 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