roldahayes Posted June 23, 2008 Share Posted June 23, 2008 Hi, please can someone help with this problem. I have a table called "movies" and 2 colomns, "quote" and "source" The php code to display these are <?php $database="****"; mysql_connect ("localhost", "****", "****"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT quote,source FROM movies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=200 border=0>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><font face=arial size=2 color=#ffffff/>$field</font></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> When displayed, the quote and source is displayed next to each other. How can i get it to have the quote and then the source on the next line (in a different color) and then a page break? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/ Share on other sites More sharing options...
wildteen88 Posted June 23, 2008 Share Posted June 23, 2008 Something like: <?php $database = "****"; mysql_connect ("localhost", "****", "****"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT quote, source FROM movies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=\"200\" border=\"0\">\n"; // initiate counter $i = 0; // colors array // two colors red and pink // RED PINK $colors = array('#FF0000', '#FF0099'); // loop through results, on each iteration the color of the text will alternate between red and pink while ($get_info = mysql_fetch_row($result)) { // Here we work out which color to use for the text $color = ($i%2 == 0) ? $colors[0] : $colors[1]; // The above line of code uses the modulos operator %. // This operator returns the remainder of a divison. // So the above code goes like this: // IF the remainder of the sum ($i DIVIDE BY 2) is EQUALS TO ZERO // THEN set the text color to RED // ELSE set the text color to PINK print "<tr>\n"; foreach ($get_info as $field) // Try to avioud using <font> tags they are depreciated. Use CSS instead. print "\t<td><span style=\"font-family: Arial; font-size: 14px; color:{$color};\">$field</span></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572484 Share on other sites More sharing options...
.josh Posted June 23, 2008 Share Posted June 23, 2008 I interpreted it as him wanting quote being one color, source being another: <?php $database="****"; mysql_connect ("localhost", "****", "****"); @mysql_select_db($database) or die( "Unable to select database"); $result = mysql_query( "SELECT quote,source FROM movies" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<table width=200 border=0>\n"; $color1 = '#ffffff'; $color2 = '#dddddd'; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; print "\t<td><font face=arial size=2 color=$color1/>{$get_info[0]}</font><br />"; print "<font face=arial size=2 color=$color2/>{$get_info[1]}</font></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572491 Share on other sites More sharing options...
roldahayes Posted June 23, 2008 Author Share Posted June 23, 2008 Excellent help! thanks to you both - The only thing now is how do I get a <br> break in between each set of quotes? Also, I have an image that I want to use as a bullet point for each quote - how do I enter the URL for it? Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572507 Share on other sites More sharing options...
wildteen88 Posted June 23, 2008 Share Posted June 23, 2008 I'm not following you there. Could you explain a little more. I cannot see why you need to use <br /> to separate the quotes. They are contained in individual table cells. If you want to space things out a little apply some cellpadding to the table tag, eg print "<table width=200 border=0 cellpadding=5>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572516 Share on other sites More sharing options...
roldahayes Posted June 23, 2008 Author Share Posted June 23, 2008 Ah right, I never thought of that! Yep, I just want to sperate each set of quotes & sources to make it easyier to read. How would I get the image to show as a bullet point for each quote though? Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572519 Share on other sites More sharing options...
wildteen88 Posted June 23, 2008 Share Posted June 23, 2008 You can either apply the bullet point as a background image for the quotes cell, or use the <img> tag instead. Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572520 Share on other sites More sharing options...
roldahayes Posted June 23, 2008 Author Share Posted June 23, 2008 i can't seem to get it to work. Where should i put the <img> tag? Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-572532 Share on other sites More sharing options...
wildteen88 Posted June 24, 2008 Share Posted June 24, 2008 Assuming you're using Crayon Violent's code, change: print "\t<td><font face=arial size=2 color=$color1/>{$get_info[0]}</font><br />"; To print "\t<td><img src=\"your_image_path_here\"><font face=arial size=2 color=$color1/>{$get_info[0]}</font><br />"; Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-573394 Share on other sites More sharing options...
roldahayes Posted June 24, 2008 Author Share Posted June 24, 2008 Excellent! Thread solved - Many Thanks to you all Quote Link to comment https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/#findComment-573556 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.