Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/111539-solved-different-color-line-breaks/
Share on other sites

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";
?>

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";  
?>

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

 

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 />";

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.