Jump to content

Can you style the context that appears from the php code, if so how?


usman07

Recommended Posts

You can also keep the two separated, which is ideal if you have a lot of code.  Here would be a very primal example: 

 

<?php   

   $output = "Hello world, I'm a simple html document!";
   include_once("template.php");

?>

 

<html>
<head>
  <title>Example</title>
</head>
<body>
  <?php echo $output ?>
</body>

Link to comment
Share on other sites

This is my PHP code


<?php

$server = "";      // Enter your MYSQL server name/address between quotes
$username = "";    // Your MYSQL username between quotes
$password = "";    // Your MYSQL password between quotes
$database = "";    // Your MYSQL database between quotes

$con = mysql_connect($server, $username, $password);       // Connect to the database
if(!$con) { die('Could not connect: ' . mysql_error()); }  // If connection failed, stop and display error
mysql_select_db($database, $con);  // Select database to use
// Query database
$result = mysql_query("SELECT * FROM Properties");

if (!$result)
{
    echo "Error running query:<br>";
    trigger_error(mysql_error());
}
elseif(!mysql_num_rows($result))
{
    // no records found by query.
    echo "No records found";
}
else
{
    $i = 0;
    while($row = mysql_fetch_array($result)) {     // Loop through results
        $i++;
        echo "Displaying record $i<br>\n";
        echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
        echo $row['Location'] . "<br>\n";            // Where 'location' is the column/field title in the database
        echo $row['Property_type'] . "<br>\n";       // as above
        echo $row['Number_of_bedrooms'] . "<br>\n";  // ..
        echo $row['Purchase_type'] . "<br>\n";       // ..
        echo $row['Price_range'] . "<br>\n";         // ..
    }
}

mysql_close($con);  // Close the connection to the database after results, not before.
?>

Link to comment
Share on other sites

So you can either style everything in the while loop, like this

echo '<span style="color:red;">';
while($row = mysql_fetch_array($result)) {     // Loop through results
$i++;
echo "Displaying record $i<br>\n";
echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
echo $row['Location'] . "<br>\n";            // Where 'location' is the column/field title in the database
echo $row['Property_type'] . "<br>\n";       // as above
echo $row['Number_of_bedrooms'] . "<br>\n";  // ..
echo $row['Purchase_type'] . "<br>\n";       // ..
echo $row['Price_range'] . "<br>\n";         // ..
}
echo '</span>';

 

Or color everything in the while loop for each loop

while($row = mysql_fetch_array($result)) {     // Loop through results
$i++;
echo '<span style="color:red;">';
echo "Displaying record $i<br>\n";
echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
echo $row['Location'] . "<br>\n";            // Where 'location' is the column/field title in the database
echo $row['Property_type'] . "<br>\n";       // as above
echo $row['Number_of_bedrooms'] . "<br>\n";  // ..
echo $row['Purchase_type'] . "<br>\n";       // ..
echo $row['Price_range'] . "<br>\n";         // ..
echo '</span>';
}

 

Or color things in the while loop individually

while($row = mysql_fetch_array($result)) {     // Loop through results
$i++;
echo "<span style=\"color:red;\">Displaying record $i</span><br>\n";
echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
echo "<span style=\"color:green;\">" . $row['Location'] . "</span><br>\n";            // Where 'location' is the column/field title in the database
echo $row['Property_type'] . "<br>\n";       // as above
echo "<span style=\"color:blue;\">" . $row['Number_of_bedrooms'] . "</span><br>\n";  // ..
echo $row['Purchase_type'] . "<br>\n";       // ..
echo $row['Price_range'] . "<br>\n";         // ..
}

Link to comment
Share on other sites

thank for your help..what am i doing wrong here cuz this doesnt seem to work?

 

'<span style="face=helvetica; font size=50;">'

 

 

<span style="font-family:helvetica; font-size:50px;">

 

You should take a look at some CSS tutorials.

 

http://www.tizag.com/cssT/

http://www.html.net/tutorials/css/

http://www.csstutorial.net/

Link to comment
Share on other sites

Thanks for that but that only seems to move the top line 'displaying record' not everything?


echo '<span style="font-family:helvetica; font-size:15px; padding-left:20px;">';
    while($row = mysql_fetch_array($result)) {     // Loop through results
        $i++;
        echo "Displaying record $i<br>\n";
        echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
        echo $row['Location'] . "<br>\n";            // Where 'location' is the column/field title in the database
        echo $row['Property_type'] . "<br>\n";       // as above
        echo $row['Number_of_bedrooms'] . "<br>\n";  // ..
        echo $row['Purchase_type'] . "<br>\n";       // ..
        echo $row['Price_range'] . "<br>\n";         // ..
    }
echo '</span>';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.