Solved

PHP Output

Posted on 2012-04-02
17
196 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 108

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 108

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
 
LVL 30

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 108

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 30

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

 
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 30

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 108

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 30

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 30

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 dynamically set the form action using jQuery.

762 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

19 Experts available now in Live!

Get 1:1 Help Now