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

Link to comment
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 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.

Link to comment
Share on other sites

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>';	

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.