Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

PHP MYSQL <?php echo $row[$variable]; ?>

I have the following code that does what I want it to do, but the ones with the backslashes <?php echo $row['t_id']; ?>, the <?php echo $row['t_type']; ?> and the <?php echo ucfirst$row['t_fn']).'&nbsp;'.ucfirst($row['t_ln']); ?> do not output their respective variable.

Instead, their output is literal like

view_t_profile.php?tutor_id=<?php echo $row['t_id']; ?>&t_type=<?php echo $row['t_type']; ?>

The <?php echo ucfirst$row['t_fn']).'&nbsp;'.ucfirst($row['t_ln']); ?> doesn't show up on the web page like the previous code, but its in the code italicized and in red text. I'm not a programmer/coder, so if someone can correct my code, I sure would appreciate it. Usually, I can figure it out, but on this one, I cannot.

<?php

if($row['t_type'] == 1)

{

echo '<center><strong><font color="#3BB9FF"><a href="view_t_profile.php?t_id=<?php echo $row['t_id']; ?>&t_type=<?php echo $row['t_type']; ?>" class="cls" target="_blank"><br />View Profile</a></font></strong></center>';
echo '<center><strong>Main Contact</strong></center>';
echo '<center><strong><font color="#3BB9FF"><?php echo ucfirst$row['t_fn']).'&nbsp;'.ucfirst($row['t_ln']); ?></font></strong></center>';

}

if($row['t_type'] == 0)

{

echo '<center><strong><font color="#3BB9FF"><a href="view_t_profile.php?t_id=<?php echo $row['t_id']; ?>&t_type=<?php echo $row['t_type']; ?>" class="cls" target="_blank"><br />View Profile</a></font></strong></center>';
echo '<center><strong>Main Sponsor</strong></center>';
echo '<center><strong><font color="#3BB9FF"><?php echo ucfirst$row['t_fn']).'&nbsp;'.ucfirst($row['t_ln']); ?></font></strong></center>';

}

?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't use <?php echo ... ?> when you're already in PHP mode and echoing something. Just concatenate the variable.

echo '<center><strong><font color="#3BB9FF">' . ucfirst($row['t_fn']) . '&nbsp;' . ucfirst($row['t_ln']) . '</font></strong></center>';

<?php echo ... ?> is used when you're just outputting HTML directly, and you want to insert a bit of PHP. For instance, like this:

if($row['t_type'] == 1)
{ ?>
<center><strong><font color="#3BB9FF"><a href="view_t_profile.php?t_id=<?php echo $row['t_id']; ?>&t_type=<?php echo $row['t_type']; ?>" class="cls" target="_blank"><br />View Profile</a></font></strong></center>
<center><strong>Main Contact</strong></center>
<center><strong><font color="#3BB9FF"><?php echo ucfirst$row['t_fn']).'&nbsp;'.ucfirst($row['t_ln']); ?></font></strong></center>
<?php
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...