usman07 Posted March 16, 2012 Share Posted March 16, 2012 I have php code that searched for results of properties from my MYSQL database, but how can i position it and style it with font and colours etc? any help will be appreciated,thanks. Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/ Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Use HTML. Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328114 Share on other sites More sharing options...
smerny Posted March 16, 2012 Share Posted March 16, 2012 yes. Â PHP outputs HTML CSS styles HTML Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328116 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 thanks, but how do i do it exactly? so im using html to style the output of the php coding, but do i input the html in my php file? Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328120 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 <?php echo '<b>this is some html inside php!</b>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328124 Share on other sites More sharing options...
guinbRo Posted March 16, 2012 Share Posted March 16, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328127 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 Sorry, i don't understand, how would i choose a colour or change the position on what the php outputs? Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328133 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 The same way you would with just HTML. Â <?php echo '<span style="color:red;">some red text</span>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328134 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 But that only make red for the text thats inbetween the brackets 'some red text'. how would i change the colour of what the php code outputs. Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328136 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 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. ?> Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328137 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 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";Â Â Â Â // .. } Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328138 Share on other sites More sharing options...
smerny Posted March 16, 2012 Share Posted March 16, 2012 should really use classes and separate styling from html as much as possible  usman, i think it would be very beneficial for you to find and go through some basic css tutorials and readings Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328142 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 thank for your help..what am i doing wrong here cuz this doesnt seem to work? Â '<span style="face=helvetica; font size=50;">' Â Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328154 Share on other sites More sharing options...
smerny Posted March 16, 2012 Share Posted March 16, 2012 font-family, font-size Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328155 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 thank but font size is not working for me, i must be doing something wrong? Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328157 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 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/ Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328158 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 thanks for that, and yeah i will do. just one more question tho, how can i also position it e.g. left-padding? Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328161 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 <span style="font-family:helvetica; font-size:50px; padding-left:10px;"> Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328163 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328173 Share on other sites More sharing options...
scootstah Posted March 16, 2012 Share Posted March 16, 2012 Try changing "span" to "div". Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328175 Share on other sites More sharing options...
usman07 Posted March 16, 2012 Author Share Posted March 16, 2012 that worked! thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/259066-can-you-style-the-context-that-appears-from-the-php-code-if-so-how/#findComment-1328177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.