How to use php inside html? please help

[hr]This is my php code… works nice, but i want to style tat a bit using html, CSS… just to echo the results inside the div[hr]

[php]

<?php session_start(); ?> <?php if (isset($_GET["id"])){ // Connect to database server mysql_connect("localhost", "root", "") or die (mysql_error ()); // Select database mysql_select_db("lms") or die(mysql_error()); // (Line 17) Get data from the database depending on the value of the id in the URL $strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"]; $rs = mysql_query($strSQL); // (Line 21) Loop the recordset $rs while($row = mysql_fetch_array($rs)) { // Write the data of the person echo $row["firstname"] ; echo $row["username"] ; echo $row["rollno"] ; } } else{ echo "No ID supplied"; } ?>[/php]

[hr]how to bring the retrieved data inside html (The variables wil hav to vary according to the id i supply)[hr]

[s] Franklin [/s]
[s] gdcfrank [/s]
[s] 123456 [/s]

[hr]Thank you in advance :slight_smile:

[php]
echo ‘

’.$row[“firstname”] .’
’;
echo ‘
’.$row[“username”] .’
’ ;
echo ‘
’.$row[“rollno”] .’
’ ;
[/php]

Dear Fastsol,
[hr]
This is my actual code…

[code]

[php]<?php
session_start();
?>

<?php if (isset($_GET["id"])){ // Connect to database server mysql_connect("localhost", "root", "") or die (mysql_error ()); // Select database mysql_select_db("lms") or die(mysql_error()); // (Line 17) Get data from the database depending on the value of the id in the URL $strSQL = "SELECT * FROM login WHERE id=" . $_GET["id"]; $rs = mysql_query($strSQL); // (Line 21) Loop the recordset $rs while($row = mysql_fetch_array($rs)) { // Write the data of the person echo $row["firstname"] ; echo $row["username"] ; echo $row["rollno"] ; } } else{ echo "No ID supplied"; } ?>[/php]
detail
fname [s]Franklin[/s]
idno 2009113043
date06/11/2013
phone9865049988
email[email protected]
[/code]

[hr]
Now tell me how to go about it??
[hr]

Replace this
[php]// (Line 21) Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {

    // Write the data of the person
    echo $row["firstname"] ;
    echo $row["username"] ;
    echo $row["rollno"] ;
}[/php]

With this
[php]while($row = mysql_fetch_array($rs)) {

    // Write the data of the person
    echo '<div id="fullname">'.$row["firstname"] .'</div>';

echo ‘

’.$row[“username”] .’
’ ;
echo ‘
’.$row[“rollno”] .’
’ ;
}[/php]
But really you need to use classes instead of id since there will be more than one of them.
[php]while($row = mysql_fetch_array($rs)) {
    // Write the data of the person
    echo '<div class="fullname">'.$row["firstname"] .'</div>';

echo ‘

’.$row[“username”] .’
’ ;
echo ‘
’.$row[“rollno”] .’
’ ;
}[/php]

Seriously now… Was there any benefit in posting duplicates when the first post received a sufficient answer :o
and i’m sure if you would of asked there, you would of got the same help ???

Sponsor our Newsletter | Privacy Policy | Terms of Service