Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
798 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 Answer

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...