View Full Version : How to save this in database as binary

09-21-2010, 03:35 AM
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

09-21-2010, 07:41 AM
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:

$Plot['Width'] = 15;
$Plot['Height'] = 15;
$Plot['Border'] = 1;
$Rows = 8;
$Cols = 8;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<style type="text/css">
#Field {
#Field .Row {
width:<?php echo $Rows*($Plot['Width'] + $Plot['Border']*2); ?>px;
#Field .Row div {
width:<?php echo $Plot['Width']; ?>px;
height:<?php echo $Plot['Height']; ?>px;
border:<?php echo $Plot['Border']; ?>px solid #824a00;
<div id="Field">
for ($i = 0; $i < $Rows; $i++) {
<div class="Row">
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>

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.

09-21-2010, 10:58 AM
tfburges i send you private message. cause i could not post here my actual code, its too long :)

09-21-2010, 01:57 PM
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:
(You may want some encryption/decryption right about here...)

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.