Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP Output

Posted on 2012-04-02
17
200 Views
Last Modified: 2012-04-03
I have a line of PHP code:

echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window


but the .$row['RegID'] isn't showing up in the outputted HTML.   If I put it anywhere else, it shows up so I know the variable is correct.   What is wrong with my syntax??
0
Comment
Question by:digitalwise
  • 5
  • 4
  • 4
  • +1
17 Comments
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37796703
Try this: var_dump($row); and post the output here, thanks.
0
 

Author Comment

by:digitalwise
ID: 37796720
array(56) { [0]=> string(1) "5" ["RegID"]=> string(1) "5" [1]=> string(7) "Heather" ["FirstName"]=> string(7) "Heather" [2]=> string(5) "Lukes" ["LastName"]=> string(5) "Lukes" }
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37796732
Visit this page and use view source.  It looks like quote marks are misplaced in the echo statement.  I will try to show you a better way to do this.
http://www.laprbass.com/RAY_temp_digitalwise.php
<?php // RAY_temp_digitalwise.php
error_reporting(E_ALL);


// SET THE VARIABLES
$row['RegID']     = 'Foo';
$row['FirstName'] = 'Ray';
$row['LastName']  = 'Paseur';

// USE THE VARIABLES IN AN ECHO STATEMENT COPIED FROM EE
echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window

Back in a moment with an alternate suggestion...
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 31

Expert Comment

by:Marco Gasi
ID: 37796734
You have a unneeded slash

echo "<A HREF='ems_registration.php?regid='" .$row['RegID'] ."/>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Just delete it and see what happens (it's also preferable to use lowercase for html:

echo "<a href='ems_registration.php?regid='" .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796741
I don't see a problem with what you've shown so far, so the problem is likely outside this piece of code somewhere. Can you show us a little more of the surrounding code (including the place where you ran the var_dump($row))?
0
 

Author Comment

by:digitalwise
ID: 37796754
Had a little bit of garbage everywhere!   Thanks for the Monday morning extra set of eyes.
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37796762
Try it more like this...
<?php // RAY_temp_digitalwise.php
error_reporting(E_ALL);

// SET THE VARIABLES
$row['RegID']     = 'Foo';
$row['FirstName'] = 'Ray';
$row['LastName']  = 'Paseur';

// CREATE A LINK
$lnk
= '<a href="ems_registration.php?regid='
. $row['RegID']
. '">'
. $row['FirstName']
. ' '
. $row['LastName']
. '</a>'
. PHP_EOL
;

echo $lnk;

Open in new window

I find that if I put only one thing on each line, I write code that is easier to read and debug.  One other note - if you use mysql_fetch_assoc() to retrieve the rows from the query results set, you will not get the numerically indexed array positions and it will make your results set 1/2 the size that it is now.  Might improve performance ;-)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796777
Another thing: you should move quote from

echo "<a href='ems_registration.php?regid='" .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

to

echo "<a href='ems_registration.php?regid=" .$row['RegID'] ."'>" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers and thanks for points
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796783
What was the final problem? While that slash wasn't correct HTML, it shouldn't have prevented the number from showing up in the source code...?
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796788
It'sa not so evident with bold: I used here parenthesis and spaces:

From:

echo "<a href='ems_registration.php?regid= (') " .$row['RegID'] .">" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

To:

echo "<a href='ems_registration.php?regid=" .$row['RegID'] ." (') >" .$row['FirstName'] ." " .$row['LastName'] . "</a>";

Cheers
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 37796790
The accepted solution generates an invalid HTML string
<a href='ems_registration.php?regid='Foo>Ray Paseur</a>

Open in new window

I have asked a moderator to reopen the question so a correct solution can be accepted.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796819
@gr8gonzo You're right. Effectively I don't know why my answer has been accepted. Ray has shown the value were shown in the source code. But viewing the ray's sample I saw the quote problem: this problem prevents the link to work. So my think is that our asker has not checked visually the source code but he tried the link and seeing it didn't work has desumed the variable were not shown. But this is only my ideas
0
 
LVL 34

Expert Comment

by:gr8gonzo
ID: 37796820
@marqusG - I understand there were changes to the HTML output, but it sounded like the RegID wasn't showing up. It's possible it was showing up in the source, but the author was judging its existence by whether or not it was there after the link was clicked.
0
 

Author Comment

by:digitalwise
ID: 37796826
OK - the good code was:
echo "<A HREF='ems_registration.php?regid=" .$row['RegID'] ."'>" .$row['FirstName'] ." " .$row['LastName'] . "</A>";

Open in new window

0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 37796830
@Ray: you're right also. In fact I have added a comment to fix the quote problem. But the invalid HTML were in the question yet... :-)
0
 

Author Comment

by:digitalwise
ID: 37796843
Guys - Ray provided me with the path to fix the issue.   When I accepted the solution, I didn't see that others had been offering solutions.   I will fix the accepted solution when the moderator opens this back up again.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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