Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Output

Posted on 2012-04-02
17
Medium Priority
?
205 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
[X]
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
  • 5
  • 4
  • 4
  • +1
17 Comments
 
LVL 111

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 111

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 35

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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 35

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 111

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 35

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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.
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 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