Solved

PHP Output

Posted on 2012-04-02
17
201 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 110

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 110

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 110

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 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 110

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 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