Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: PHP Change Table BG Color

  1. #1
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default PHP Change Table BG Color

    How can I change the background color of a table without having to reload the page? Thanks in advanced!

    PS: I'm placing the change BG color after a sleep(); function.
    Last edited by M2com; 08-03-2011 at 12:30 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Be more specific.

  3. #3
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    Well all I need is a way to change the background of a table without having to constantly reload the page. I don't know how to be any more specific.

    Please be more specific on what you need to me to be more specific on.

    Thanks for your time!

  4. #4
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Do you mean that the background of the table would be changed dynamically? This could be accomplished in JavaScript.

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    For example, you would click a button and it would change the background of the table. If that's what you're getting at, it can be accomplished. Also, do you have any code?

  6. #6
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    Hmm, I was hoping not to use Javascript but if that's the best then we could use it. Here is a portion of my code:

    Code:
    sleep(10);
    $myFile = "../$id2/status.txt";
    $timestamp = date("l, F d, Y h:i" ,time());
    $fh = fopen($myFile, 'w') or die("
    								 Data: 133484354354236253690528");
    $stringData = "Hacked";
    fwrite($fh, $stringData);
    fclose($fh);//Here is where you will set your path for entry
    $myFile = "../$id2/status2.txt";
    $timestamp = date("l, F d, Y h:i" ,time());
    $fh = fopen($myFile, 'w') or die("
    								 Data: 133484354354236253690528");
    
    $stringData = "Hacked";
    fwrite($fh, $stringData);
    fclose($fh);//Here is where you will set your path for entry
    			$fp=fopen("credits.txt","r");		//Opens the Pass.txt file
    $data=fgets($fp);				//Reads the File entirely
    fclose($fp);					//Closes the file since we already got our info
    
    $filename= "credits.txt" ;
    $fd = fopen ($filename , "r") or die ("Can't open $filename") ;
    $fstring = fread ($fd , filesize ($filename)) ;
    fclose($fd) ;
    
    $fd = fopen ($filename , "w") or die ("Can't open $filename") ;
    $fcounted = $fstring + 50 ;
    $fout= fwrite ($fd , $fcounted ) ;
    fclose($fd) ;
    
    // This is where I would place the background color change.

    It would change this table:



    Code:
    <table width='400' border='1' bgcolor='$bg2'>
      <tr>
        <th scope='col'>ID #1: $id1</th>
      </tr>
    </table>

  7. #7
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    PHP is server-side, so changing the table's background color dynamically is not possible once the page is loaded.

    It is possible to change it client-side using JavaScript, but it sounds like you want a more robust solution to that.

    Also, in your PHP code, nothing is being printed out -- it's only files being read/modified/closed. Where exactly is your table being created?

  8. #8
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    My tables are being created above the .TXT reading and editing script.

  9. #9
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    The PHP compiler compiles code in descending order (so code created in the beginning cannot be manipulated at the end).

    Here is a jQuery solution that will dynamically change the background color of a table whose ID is named "table_id".

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
       $("#table_id").css("background-color", "<?php echo $bg2; ?>");
    });
    </script>
    ... and your table should look something like:
    Code:
    <table width='400' border='1' id='table_id'>
      <tr>
        <th scope='col'>ID #1: $id1</th>
      </tr>
    </table>
    Remember to include the jQuery library in your code. If you don't want to use jQuery, I could give you another solution, but it would be much longer, complex and convoluted.

  10. The Following User Says Thank You to JShor For This Useful Post:

    LeeForbes (08-01-2011)

  11. #10
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    Thanks so much for your help! But for some reason the script you gave me isn't working. Should I show you my current code?

    Thanks so much again!

    EDIT: I think I fixed it now! Thanks so much for your help! Though only one thing is that it changes the color of the tables after it's done with the whole process not during it (real time). If there is a way of fixing that, that would be nice, otherwise it's fine.
    Last edited by M2com; 07-31-2011 at 02:02 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •