Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to save this in database as binary

    i have this in my code

    <td onclick="addcolor(1);" id="gimage1" style="border:1px solid #555555; cursorointer; background:url(template/premium/img/guild-back.gif);" width="15" height="15">
    <input type="hidden" name="poscolor[1]" id="poscolor[1]" value="0"></td>

    there are 64 all in all hidden input because this is 8x8 box. how can i save them as binary

  • #2
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    I see what you're trying to do, and I'll go ahead and tell you... don't do it like that.

    Do it like this:
    PHP Code:
    <?php
        $Plot
    ['Width'] = 15;
        
    $Plot['Height'] = 15;
        
    $Plot['Border'] = 1;
        
    $Rows 8;
        
    $Cols 8;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
        <head>
            <title>Example</title>
            <style type="text/css">
                #Field {
                    margin:10px;
                }
                #Field .Row {
                    width:<?php echo $Rows*($Plot['Width'] + $Plot['Border']*2); ?>px;
                }
                #Field .Row div {
                    float:left;
                    width:<?php echo $Plot['Width']; ?>px;
                    height:<?php echo $Plot['Height']; ?>px;
                    border:<?php echo $Plot['Border']; ?>px solid #824a00;
                    margin:0px;
                    padding:0px;
                    background:#00ff00;
                    cursor:pointer;
                    font-size:8px;
                }
            </style>
        </head>
        <body>
            <div id="Field">
    <?php
        
    for ($i 0$i $Rows$i++) {
    ?>
                <div class="Row">
    <?php
            
    for ($j 0$j $Cols$j++) {
    ?>
                    <div id="Plot_<?php echo $i?>_<?php echo $j?>" onClick="alert('This alert would be replaced with an AJAX call storing the true/false switch.  This is row <?php echo $i?> column <?php echo $j?>.');"><?php echo $i?>.<?php echo $j?></div>
    <?php
            
    }
    ?>
                </div>
    <?php
        
    }
    ?>
            </div>
        </body>
    </html>
    If you're confused about what exactly is going on there... google some of the syntax of which you are unsure (i.e., "PHP echo", "CSS float", etc.) and learn from there. If you're still confused, let me know.

    If you test it, you'll see where I've provided an alert that you'll replace with an AJAX call. AJAX will be used to store the status of the "boxes" as they are selected/deselected. As for the AJAX part of it, after you've learned how I've done this, I'll show you the best way to do that. It's fairly straightforward.
    Last edited by tfburges; 09-21-2010 at 08:57 AM.

  • Users who have thanked tfburges for this post:

    jcardy (09-21-2010)

  • #3
    New Coder
    Join Date
    Sep 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    tfburges i send you private message. cause i could not post here my actual code, its too long

  • #4
    Regular Coder
    Join Date
    May 2009
    Posts
    425
    Thanks
    3
    Thanked 62 Times in 61 Posts
    In the javascript function "addcolor", you'll need to add an AJAX call. I see you're using jQuery so it should be fairly easy to do. I personally don't use jQuery as I've created my own javascript library but if you Google "jQuery AJAX PHP example" you should find exactly what you need syntax-wise.

    Oh... and there's no reason to save it as binary. Just store the colors as whatever their respective values are. I'd store them as an array with the ids as the keys. As for how you want to store them, it's up to you. Most people use MySQL as a shortcut but I personally feel using the following functions is a better method:
    http://php.net/manual/en/function.serialize.php
    http://php.net/manual/en/function.file-put-contents.php
    (You may want some encryption/decryption right about here...)
    http://php.net/manual/en/function.file-get-contents.php
    http://php.net/manual/en/function.unserialize.php

    Last but not least, you should really consider tossing tables out the window and converting your code to the div format as I've shown in my previous post... with nested for-loops and CSS. This will make it 1000 times quicker/easier to add/edit/remove anything in the future.
    Last edited by tfburges; 09-21-2010 at 02:07 PM.


  •  

    Posting Permissions

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