Jump to content

How to style the php code?


usman07

Recommended Posts

I basically would like to style the third and fourth echo, could i give it a ID then style it in css, how would i do this? any help is appreciated.

 

my php code:


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

Link to comment
https://forums.phpfreaks.com/topic/260922-how-to-style-the-php-code/
Share on other sites

You can do this a couple of ways:

echo "<span style=\"color:red;\">Location: ". $row['Location'] . "</span><br>";

 

or make a CSS section and do this:

 

echo "<span id=\"location\">Location: ". $row['Location'] . "</span><br>";

 

The \n is not needed in your code.

You can do this a couple of ways:

echo "<span style=\"color:red;\">Location: ". $row['Location'] . "</span><br>";

 

or make a CSS section and do this:

 

echo "<span id=\"location\">Location: ". $row['Location'] . "</span><br>";

 

The \n is not needed in your code.

You wouldn't use an id as id's need to be unique to the page, and thus would only be valid for one loop.  Use a css class instead.

Well I am surprised you got it looking like you did without defining the placement of image and text.  This is a css issue really, but I would probably use floating div's inside a container div.  This is a basic (untested) example of what I'm talking about where image is in one div and text is in another, with a break(clear:both) for each record, inside a wrapper div.  I added a padding-top of 10px to the text box.  I added an undefined class for each div that you can "style" in your css instead of using inline styling.    Again this is just a sample so adjust as needed.

echo '<div class="container" style="float:left;">';
  while($row = mysql_fetch_array($result)) {     // Loop through results
        $i++;
echo '<div class="imageholder" style="float:left;">';
        echo '<img class="image1" src="'. $row['images'] .'" />';   //image
echo '</div>';		
echo '<div class="textholder" style="float:left; padding-top:10px;">';
        echo "<span style=\"color:green;\"><b>Displaying record $i<br>\n</b><br></span>";
        echo "<b>" . $row['id'] . "</b><br>\n";      // Where 'id' is the column/field title in the database
        echo "Location: ". $row['Location'] . "<br>\n";            // Where 'location' is the column/field title in the database
        echo "Property Type: ". $row['Property_type'] . "<br>\n";       // as above
        echo "Bedrooms: ". $row['Number_of_bedrooms'] . "<br>\n";  // ..
        echo "Purchase Type: ". $row['Purchase_type'] . "<br>\n";       // ..
        echo "Price: ". $row['Price_range'] . "<br>\n";         // ..
echo '</div>';
echo '<div style="clear:both"></div>';				
    }
echo '</div>';	

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.