0

This is my page from an online radio station site of mine on localhost, it's a basic PHP/MySQL one for test purposes:

    <?php
mysql_connect('localhost', 'root', 'mypass') or die (mysql_error());
mysql_select_db('radiotest') or die (mysql_error());
$result = mysql_query("SELECT *, TIME_FORMAT(airtime, '%H:%i') `airtime` 
from presenters");
//Table starting tag and header cells
while($row = mysql_fetch_array($result)){
//Display the results in different cells
echo "<dd><dl><img src=' " . $row['image'] . " '>" . $row['airtime'] ." 
" . $row['presenter'] . "</dd></dl>";
echo "<dd><dl>" . $row['showinfo'] . "</dd></dl>";
}
?>

It works properly, displays the data from the table in the required format.

However, I want to try doing it this way:

<dd><dl><img src='<?php echo $row['image'] ?'> <?php echo $row['airtime']?> 
 <?php echo. $row['presenter']?> </dd></dl>

My problem: I admit I've forgotten how to do echo without displaying it in the PHP/MySQL query like above, so how can I ensure it displays the variables using echo without having to declare it in the MySQL connection? I know my original is correctly formatted, but I don't want it to have the echo variables after the while part of the syntax, I wanted to echo them within the dd / dl HTML (definition list).

Basically, I'm just trying to brush up my skills in this area; had a look on Google but am not quite sure

Any help is appreciated!

1
  • Your code already looks formated and im not sure what you re trying to ask here. Commented Aug 25, 2011 at 22:33

2 Answers 2

0

It's really no different, and definitely not better, but I think you are asking to do:

while($row = mysql_fetch_array($result)){
//Display the results in different cells
?>
<dd><dl>
    <img src='<?php echo $row['image']; ?>'>
    <?php echo $row['airtime']; ?> <?php echo $row['presenter']; ?>
</dd></dl>
<dd><dl>'<?php echo $row['showinfo']; ?></dd></dl>
<?php
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this instead:

<dd>
    <dl>
        <img src='<?=$row['image'] ?>'> <?=$row['airtime'] . " - " .$row['presenter']?> 
    </dd>
</dl>

2 Comments

Are short tags really necessary?
what's wrong with short tags? i'm not getting paid by code length :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.