Solved

href inside php

Posted on 2011-03-21
14
401 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
 
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now