#1
  1. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    I can't seem to get a background color in the tables that are created from output by mySQL using PhP3... sample output table...:

    printf("<tr><td>%s</td><td>%s</td><td>%s</tr>n", $myrow["Name"], $myrow["Location"], $myrow["Cost"]);


    I am brand new at this, it is part of my first script...

    thank you
  2. #2
  3. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    I don't see any background definitions in your HTML. How are you trying to do it? That's an HTML function, has nothing to do with PHP.
  4. #3
  5. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    I have tried to input the bgcolor everywhere... example...:

    printf("<tr><td bgcolor="ff0000">%s</td><td>%s</td><td>%s</tr>n", $myrow["Name"], $myrow["Location"], $myrow["Cost"]);

    How would you do this...? All I get is a parse error... anywhere I put "bgcolor="ff0000"... I always get a parse error...

    Help...

  6. #4
  7. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Look over your line carefully.. How does PHP know when your string begins and ends with all those " in there?

    You need to escape the " you want passed as part of the string, or use ' instead.

    Examples:

    "<tr><td bgcolor="#ff0000">...."
    or
    "<tr><td bgcolor='#ff0000'> ... "

    [This message has been edited by rod k (edited 12-10-99).]
  8. #5
  9. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    That worked wonderfully... thank you so much...

    Does anybody know how to rotate colors in the tables created from php3 every other line...?

    example:

    1st output from mySQL
    "<tr><td bgcolor='#ff0000'>%s</td><td bgcolor='#0000ff'>%s</td> ... "

    2nd output
    "<tr><td bgcolor='#0000ff'>%s</td><td bgcolor='#ff0000'>%s</td> ... "

    and have it keep alternating... my script looks like:

    mysql_select_db("kidz4dayz_com",$db);

    $result = mysql_query("SELECT * FROM $state WHERE City = '$cities'",$db);

    if ($myrow = mysql_fetch_array($result)) {

    echo "<table border=0 cellpadding=5>n";

    echo "<tr>
    <td><b>Name</b></td><td><b>Location</b></td><td><b>Cost</b></td>< /tr>n";

    echo "<tr></tr>n";
    echo "<tr></tr>n";
    echo "<tr></tr>n";
    do {

    printf("<tr><td bgcolor='#c8c8ff'>%s</td><td bgcolor='#7d7dff'>%s</td><td bgcolor='#c8c8ff'>%s</tr>n", $myrow["Name"], $myrow["Location"], $myrow["Cost"]);

    } while ($myrow = mysql_fetch_array($result));

    echo "n";

    } else {

    echo "Sorry, no records were found!";
    }

    ?>

    </body>

    </html>


    Thank you...

  10. #6
  11. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    You just need a counter in your do..while.

    Like this:

    $i=1;
    do {
    if (is_int($i/2))
    {$color=$evenrowcolor;}
    else{$color=$oddrowcolor;}

    print "<tr><td bgcolor='$color'>whatever</td></tr>";

    $i++;
    } while ($myrow = mysql_fetch_array($result));

    [This message has been edited by rod k (edited 12-11-99).]
  12. #7
  13. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks so much rod... I couldn't get your script to work for some reason but I modified it to look like this:

    $i=1;
    do {
    if (is_int($i/2))

    printf("<tr><td bgcolor='#c8c8ff'><a href = 'daycare.php3'>%s</a></td><td bgcolor='#9797ff'>%s</td><td bgcolor='#c8c8ff'>%s</tr>n", $myrow["Name"], $myrow["Location"], $myrow["Cost"]);

    else printf("<tr><td bgcolor='#9797ff'><a href = 'daycare.php3'>%s</a></td><td bgcolor='#c8c8ff'>%s</td><td bgcolor='#9797ff'>%s</tr>n", $myrow["Name"], $myrow["Location"], $myrow["Cost"]);



    $i++;
    } while ($myrow = mysql_fetch_array($result));


    And it works great... It gives my results a "checkerboard look"... I am not sure I will use this but I saw it in Bank Ones website and thought it might be fun...

    Thanks again...

    Also... I am using a javascript for a "back" button...

    echo "<a href=javascript:history.go(-1)>Please take me back.</a>";

    Is there an easy way I can do this without the java but just with "php3"...

    thanks again...

  14. #8
  15. No Profile Picture
    Pointman
    Guest
    Devshed Newbie (0 - 499 posts)
    Move your bgcolor into your TR tag instead and you'll get solid colors per line instead of per cell.

    That would give you an effect that makes the table easier to read instead of the more difficult checker-board.

    Just my $0.02
  16. #9
  17. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    Thank you Pointman, I have tried it both ways and I am not sure wich one I will use yet...

    Have a great Christmas...

    Also... I am using a javascript (javascript:history.go(-1)) for a back button, is there a way to do this with php3 instead of java...?

    Thanks again...

    [This message has been edited by tucats (edited 12-22-99).]
  18. #10
  19. No Profile Picture
    Randy
    Guest
    Devshed Newbie (0 - 499 posts)
    I believe you're looking for the $HTTP_REFERER variable. Something like:

    <A href=<?echo $HTTP_REFERER?>>Go Back</a>

    You might want to put a little more logic in it to make sure that $HTTP_REFERER is set, and that the page they are going back to is on your site.
  20. #11
  21. No Profile Picture
    Randy
    Guest
    Devshed Newbie (0 - 499 posts)
    Following up on the last message.. .

    Never use JavaScript when you CAN do something server-side. It'll save you a ton of headaches in the long run.

    Also, one of the most helpful functions in PHP is the phpinfo() function. Try it! Also try linking from another page to a page with phpinfo() to make sure you get the HTTP_REFERER set.

  22. #12
  23. No Profile Picture
    tucats
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks Randy... I will give it a shot... looks like it will work...

    Happy NEW YEAR...
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Location
    London
    Posts
    110
    Rep Power
    0
    I know this is late in the day but..... here is a simple way to alternate colours across and down the page ..

    echo "<tr><td valign="top" bgcolor="";
    if($trcount=="0")
    {
    $bgcolor="#fef7d9";
    $trcount++;
    }
    else
    {
    $bgcolor="#ffffff";
    $trcount--;
    }
    echo "$bgcolor" width="40"><font face="helvetica" color="#0063a2" size="1"><b>$time</b></font></td>
    <td align="top" bgcolor="#ffffff" width="5"></td>
    <td valign="top" bgcolor="$bgcolor" width="260"><font face="helvetica" color="#0063a2" size="1"><b>$name</b></font></td>
    <td align="top" bgcolor="#ffffff" width="5"></td>
    <td valign="top" bgcolor="$bgcolor" width="296"><font face="helvetica" color="#0063a2" size="1">$desc<br><br></td></font></tr>";
    }

    [This message has been edited by timbo (edited January 07, 2000).]

Similar Threads

  1. How do I find out what tables are on the database?
    By Swell in forum Oracle Development
    Replies: 7
    Last Post: February 18th, 2004, 08:18 AM
  2. Large tables or many small tables?
    By Tassadar356 in forum MySQL Help
    Replies: 4
    Last Post: February 8th, 2004, 01:07 PM
  3. How to know which tables are on a database?
    By c.caraccioli in forum PostgreSQL Help
    Replies: 5
    Last Post: January 22nd, 2004, 01:06 PM
  4. How Do I Output Image From Database
    By Volitics in forum PHP Development
    Replies: 5
    Last Post: January 16th, 2004, 05:24 PM
  5. Count all tables in a database
    By Joput in forum PHP Development
    Replies: 1
    Last Post: January 14th, 2004, 08:31 AM

IMN logo majestic logo threadwatch logo seochat tools logo