Jump to content

shutat

Members
  • Posts

    30
  • Joined

  • Last visited

Posts posted by shutat

  1. I'm trying to conditionally add a table to a select query using the join, but I always get an "no such table"  error.  I'm not at all sure if the syntax is correct, so I decided to ask. 

     

    I'm using the sqlite C API interface and my tables and query were constructed using sprintf, so please ignore any %d, %s that may appear

    CREATE TABLE IF NOT EXISTS tbl_master
    (
         id INTEGER PRIMARY KEY AUTOINCREMENT,
         volume TEXT(16) UNIQUE NOT NULL DEFAULT '',
         note   TEXT(%d) NOT NULL DEFAULT '',
         items INTEGER NOT NULL DEFAULT 0
    );
     
    CREATE TABLE IF NOT EXISTS tbl_file
    (
          id INTEGER PRIMARY KEY AUTOINCREMENT,
          volume_key TEXT(16) NOT NULL DEFAULT '',
          name TEXT(%d),
          size TEXT(20),
          type TEXT(4),
          path TEXT(%d),
          file_id INTEGER
    );
     
    CREATE TABLE IF NOT EXISTS tbl_hash
    (
         id INTEGER PRIMARY KEY AUTOINCREMENT,
         hash TEXT(33) NOT NULL DEFAULT '',
         volume_key TEXT(16) NOT NULL DEFAULT '',
         file_key INTEGER NOT NULL DEFAULT 0
    );
     
    CREATE TABLE IF NOT EXISTS tbl_media
    (
           id INTEGER PRIMARY KEY AUTOINCREMENT,
           runtime TEXT(10) NOT NULL DEFAULT '',
           frame TEXT(12) NOT NULL DEFAULT '',
           type_key TEXT(4) NOT NULL DEFAULT '',
           hash_key TEXT(33) NOT NULL DEFAULT '',
           volume_key TEXT(16) NOT NULL DEFAULT '',
           file_key INTEGER NOT NULL DEFAULT 0
    );

    I milled over a few JOIN tutorials, but I'm still unclear on the exact usage of JOIN; I'm trying to add the media table if the file type is a vid, snd, or pix, but I need file information regardless.  I've tried various flavors of the following query, but each time I get the table doesn't exist error.  Selects, deletes, updates, inserts work on all tables, so I'm guessing my syntax is wrong with the JOIN.

    SELECT tbl_file.*, tbl_hash.hash
      FROM tbl_file AS f, tbl_hash AS h
      LEFT OUTER JOIN tbl_media AS m
      ON  ((f.type='VID' OR f.type='SND' OR f.type='PIX')
      AND m.file_key=f.file_id)
      WHERE ((f.volume_key=tbl_master.volume
      AND (h.volume_key=tbl_master.volume AND h.file_key=f.file_id)))
      ORDER BY f.path ASC;
    

    Any ideas on how to pull off what I'm trying to do would be greatly appreciated.  Thank you for your time.

     

     

     

  2. You can use styling properties to alter the appearence of the button.

     

    <input style="background-color: same as default background; color: desired text color; border: 0px" ...>
    

     

    Not sure how you would go about passing input using a hyperlink alone.

     

     

     

  3. If the image needs to change as the user types, then I *think* something like below may work.  onChange is triggered when the textbox loses focus and its value was changed.  "this" contains properties of the target.  For example, you could add another parameter to your function that includes the "name" parameter of the input box by adding onkeypress="isCorrect(this.name, this.value, 'actual_text');" 

     

    <input type='text' name="random_letters" onkeypress="isCorrect(this.value, 'some_actual_value');">
    

     

    HTH

  4. I had the exact same issue, and after a bit of research, I discovered it was a synchronous / asynchronous  problem.  Try modifying your code as

     

    function ajaxPost(params, url){
       
       var XMLHttpRequestObj = false;
          
       if (window.XMLHttpRequest){
          XMLHttpRequestObj = new XMLHttpRequest();
       } else if (window.ActiveXObject){
          XMLHttpRequestObj = new ActiveXObject("Microsoft.XMLHttp");
       }
          
       if (XMLHttpRequestObj){
          XMLHttpRequestObj.open("POST", url, false);
          XMLHttpRequestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          XMLHttpRequestObj.setRequestHeader("Content-length", params.length);
          XMLHttpRequestObj.setRequestHeader("Connection", "close");
          XMLHttpRequestObj.send(params);
         
          var requestResponse = XMLHttpRequestObj.responseText;
          delete XMLHttpRequestObj;
          return (requestResponse);      
       }
    }

     

    HTH

  5. If you want, you can use php to serve the form as well as process it.  You should always check your variables before using them; empty is just a simple check to see whether or not a user filled them in.  You'd want to make sure any input was valid for the field you expect before processing it.

     

    <?php
    
       if(isset($_POST["submit"]) && $_POST["submit"] === "send") {
    
          if(empty($_POST["name"]) || empty($_POST["replymail"]) || empty($_POST["subject"]) || empty($_POST["body"])) {
    
             // one or more post vars had an empty field
    
          } else {
    
             // validate input
             // assign post vars as needed          
             // call mail function
    
             // mail returns a boolean value, true indicates it was sent, but
             // does not indicate whether or not it will actually arrive
          } 
    
       } else {
    ?>
    
    <pre>
    <form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post">
       Name: <input type="text" name="name" size="30">
       From: <input type="text" name="replyemail" size="30">
    Subject: <input type="text" name="subject" size="30">
    
       Body:
             <textarea rows="6" cols="54" name="body"></textarea>
    <input type="submit" name="submit" value="send">
    </pre>
    
    <?php
       }
    ?>
    

     

    HTH

  6. Don't know if it will help, but one thing you *might* try is something like below.  If you need to unhide it again, place the input stuff back as innerHTML. 

    <html>
    <head>
    <script language="javascript">
    
    function fifty() {
       var docs = document.getElementById("opt1");
       docs.innerHTML = " ";   
    }
    </script>
    </head>
    <body>
    <form>
    <div id="opt1">XHTML <input name="answer" value="xhtml" type="radio"><br></div>
    <div id="opt2">CSS <input name="answer" value="css" type="radio"><br></div>
    <div id="opt3">PHP <input name="answer" value="php" type="radio"><br></div>
    <input value="50 / 50" type="button" onclick="fifty();">
    <input value="submit" type="submit">
    </form>
    </body>
    </html>
    

     

    The downside is having to rely on client support being enabled.  If you want straight html, then you could pass along the request in your link and regenerate the page.

     

    HTH

  7. I'm working on a basic login routine where I'd like to replace a "guest" once a member logs in, but ran into a snag with syntax.

     

    Right now, I have something like below just to try things out, but it isn't really what I need.

       $res = mysql_query("update tbl_users set laston='" . $time . "' where ID='" .   $n . "' limit 1;");
                 
       $res = mysql_query("update tbl_guests set laston='0' where ip='" . 
                $_SERVER["REMOTE_ADDR"] . "' limit 1;");
    

     

    I tried various ways at an attempt for just one query, and my last try was something like

       $n = user's ID
       $time = time();
       $res = mysql_query("update tbl_users, tbl_guests, set tbl_users.laston='" .
                $time . "', tbl_users.ip='" . $_SERVER["REMOTE_ADDR"] . "' where
                tbl_users.ID='" . $n . "', set tbl_guests.laston='0' where
                tbl_guests.ip=tbl_users.ip limit 1;");
    

    However, I got nothing but dreaded syntax errors with all attempts.  I haven't done much work at all with joins, but was wondering if it's possible to update two tables in such a way?  If so, what am I not getting right?

     

    TIA

     

  8. if(document.cookie.length > 0 && document.cookie.substr(0, document.cookie.indexOf("=")) == cname) {
       if(document.cookie.substr(document.cookie.indexOf("=") + 1) == "no") {
          location.href = "index.php";
       } else {
          // cookie data was something other than no
       }
    } else {
       location.href = "index.php"; // cookie wasn't set
    }
    

     

    I *think* that would do assuming the cookie format is just cname=no.  Things to lookout for are indexOf is case sensitive, and it returns -1 if the match string isn't found.

     

    HTH

  9. To check if a user exists, you could try something like

     

    ...
    $res = mysql_query("select ID from users where username='$username' limit 1;");
    if(mysql_num_rows($res) == 1) {
       // username already exists
    } else {
       // insert form data
       // delete form data
    }
    ...
    

     

    There's probably better methods, but that's what I usually do.

     

    HTH

  10. Check to see if your host supports the gd library; if it does, you can generate images on the fly including resizing.  The downside is it's somewhat static, so you could use an iframe, and or javascript along with $_GET to "dynamcially" change each image, or try ajax.

     

    Here's a link to gd and here's one to some thumbnails page using php and js.  I don't know if either will meet your need, but thought I'd throw it out there.

     

    HTH.

  11. It would really help if you list the steps you would take and the resulting action you want to occur. But, I think I'm starting to understand. Should only 1 select field have a value and no others? I think adding the keydown event to the body and using a global variable to track the current field will run into problems as well.

     

    I'm working a game actually, where each of the selects will represent commands the player can take.  The first select is static, but the others will be filled once conditions are met.  The first item in each select is just a moniker of sorts to show what each of the commands are, so element 0 wouldn't ever be acted upon. 

     

    Thanks a lot for the great tips; I was looking for a way to compact my version of the switch that you did within your version of the keyB function, and your method is nice and clean.  I think your select handler is going to help out a lot too.

     

    I'm going to go ahead and marked this as solved; I really appreciate your help!  Thank you. 

  12. How about crude methods using javascript and cookies?  You can set up a js handler to read your textarea, split it up into chunks, and then write any data cookies that you may need.  Reload the page and use php to read them back for whatever action you need to make.

     

    You can set a small number of them with each one being up to 4kb in size as I  recall.  Sort of a clumsy approach, but hey, do whatever it takes. :P

  13. for($id = 1; $id <= MAX_PLAYERS; $id++) {
       $res = mysql_query("SELECT * FROM se_player WHERE player_id=$id");
       while($row = mysql_fetch_assoc($res)) {
           // generate the image
       }
    }
    

     

    I *think* that's what you're after.  If you need to format a playing field or something, use the modulus operator against $id... something like

     

       if($id % 3 == 0) { echo "<br>"; }
    

     

     

     

  14. I've read your post a few times now and am still perplexed by what you arereally doing

    lol; you aren't the only one - I'm at a loss myself. :)  Thank you for the response.  I tried to create a page from what I could remember, but I don't have access to the original code at the moment.

     

    I've copied and pasted your code as well and will play around with it once I log off.

     

    <html>
    <head>
    <style type="text/css">
    select { width: 100px }
    </style>
    
    <script language="javascript">
    
    var idx = 1;
    
    function processSel(id) {
    
       var docs = document.getElementById(id);
       var r_id = document.getElementById("res");
    
       switch(docs.id) {
          case "sel_1": switch(docs.options[docs.selectedIndex].value) {
                           case "cmd 1": r_id.innerHTML = "ID: " + docs.id + "   VALUE: " + docs.options[docs.selectedIndex].value;
                                         break;
                           case "cmd 2": r_id.innerHTML = "ID: " + docs.id + "   VALUE: " + docs.options[docs.selectedIndex].value;
                                         break;
                           case "cmd 3": r_id.innerHTML = "ID: " + docs.id + "   VALUE: " + docs.options[docs.selectedIndex].value;
                                         break;
                        } break;
          case "sel_2": //alert(docs.options[docs.selectedIndex].value);
                        break;
          case "sel_3": //alert(docs.options[docs.selectedIndex].value);
                        break;
          case "sel_4": //alert(docs.options[docs.selectedIndex].value);
                        break;
       }   
    }
    
    function keyB(evt) {
    
       try {
    
          switch(evt.keyCode) {
             case 37: switch(idx) {
                         case 1: idx = 4; 
                                 document.getElementById("sel_4").focus();
                                 break;
                         case 2: idx = 1;
                                 document.getElementById("sel_1").focus();
                                 break;
                         case 3: idx = 2;
                                 document.getElementById("sel_2").focus();
                                 break;
                         case 4: idx = 3;
                                 document.getElementById("sel_3").focus();
                                 break;
                      } break; 
    
             case 39: switch(idx) {
                         case 1: idx = 2; 
                                 document.getElementById("sel_2").focus();
                                 break;
                         case 2: idx = 3;
                                 document.getElementById("sel_3").focus();
                                 break;
                         case 3: idx = 4;
                                 document.getElementById("sel_4").focus();
                                 break;
                         case 4: idx = 1;
                                 document.getElementById("sel_1").focus();
                                 break;
                      } break; 
                          
          }
       }
    
       catch(e) { alert("oops"); }
    }
    
    </script>
    </head>
    <body onkeydown="keyB(event)">
    <div id="res">.</div>
    <form name="f">
    <select id="sel_1" size="1" onchange="processSel(this.id);" onblur="this.selectedIndex=0;">
    <option value="-- sel1">-- sel1</option>
    <option value="cmd 1">cmd 1</option>
    <option value="cmd 2">cmd 2</option>
    <option value="cmd 3">cmd 3</option>
    </select>
    
    <select id="sel_2" size="1" onchange="processSel(this.id);" onblur="this.selectedIndex=0;">
    <option value="-- sel2">-- sel2</option>
    <option value="cmd 1">cmd 1</option>
    </select>
    
    <select id="sel_3" size="1" onchange="processSel(this.id);" onblur="this.selectedIndex=0;">
    <option value="-- sel3">-- sel3</option>
    </select>
    
    <select id="sel_4" size="1" onchange="processSel(this.id);" onblur="this.selectedIndex=0;">
    <option value="-- sel4">-- sel4</option>
    </select>
    </form>
    </body>
    </html>
    

     

    The above is similar to what I was doing, but I changed a few things to try and replicate what the problem was.  Select an item, other than index 0 in the first select, and then use the left and right arrow keys alone.

     

    IE6, at least, doesn't seem to be affected, but in Firefox 3 and Opera 9.6, if you use the left and right arrow keys, the value above the select *should* change. 

     

    I want to be able to cycle through any of the four selects, choose an item in any of the selects, yet be able to "cancel" any choice by moving to another select.  A "choice" should be made only if the mouse onclick event is triggered or the enter key is pressed, or at least that's what I'm trying to make it do.

     

    Any ideas?

    TIA

  15. I have four select boxes that I'm switching using the arrow keys (key down event).  I'd like to be able to select an item, then cancel and move onto another select, but whenever I try it, the onchange event is triggered in the select that I blurred.  I have a common handler for all four selects during the onchange event.

     

    The onfocus handler was an attempt to set the selectedIndex property to 0, but it didn't matter whether I tried it within that function or inside of the keyboard handler... neither seemed to help.

     

    <select id="c_cmd" size="1" onfocus="setIdx(this.id);" onchange="doCmd(this.id);">...</select>
    ...
    <select id="c_itm" size="1" onfocus="setIdx(this.id);" onchange="doCmd(this.id);">...</select>
    

     

     

    switch(evt.keyCode) {
       case 37:  switch(activeSel) {
                        case 1: docu...("c_cmd").selectedIndex = 0;
                                docu...("c_itm").focus();
                                activeSel = 4;
                                break;
                        ...
                        case 4: docu...("c_itm").selectedIndex = 0;
                                docu...("c_cmd").focus();
                                activeSel = 1;
                                break;
                    } break;
    
       case 39: ...
    }

     

    I tried the above and thought it was working, but if I had selected an item in the list and then decided to choose another select box, the onchange for the prior select box fires.

     

    Is there a way to ensure that the select boxes that aren't desired won't fire the onchange event?  onblur doesn't seem to work either.

     

    TIA

  16. I'm trying to merge two images on the fly; I have a base image and a smaller image with a "white" border that I'd like to get rid of.  I can merge the images ok, but I can't seem to get rid of the border.  I was wondering if it's my choice of functions, something I'm missing, or perhaps the mask color.

     

    Any hints are greatly appreciated.

     

    
    $base = "imgs/base.png";
    $merg = "imgs/test.png";
    
    list($bw, $bh) = getimagesize($base);
    list($mw, $mh) = getimagesize($merg);
    
    $tmp = imagecreatetruecolor($bw, $bh);
    $src1 = imagecreatefrompng($base);
    $src2 = imagecreatefrompng($merg);
    
    imagecopy($tmp, $src1, 0, 0, 0, 0, $bw, $bh);
    imagecopy($tmp, $src2, 0, 0, 0, 0, $mw, $mh);
    imagelayereffect($tmp, IMG_EFFECT_ALPHABLEND);
    

     

    Does anyone have any ideas on how to achieve the effect?

     

    TIA

     

     

     

     

  17. You can use document.getElementById("main").focus() to set the focus back onto it.

     

    Thanks for the reply - I sure appreciate it. 

     

    I tried that in the init function and as a stand alone function for main's onblur event, but it didn't work - I either got .focus() isn't a function in the js console or it didn't do anything when I used .focus

     

    Where should it go?   

  18. I'm working on a game where I have a script that polls the keyboard in order to simulate movement of a central character.  If the character is at a certain coordinate, I change the src property of an iframe to load a midi file.  That's where my problem arises, I lose focus on the character and cannot figure out programmatically how to get it back.  Is it possible?

     

    Here's a basic idea of what I'm up to.

     

    main.html

    <head>
    <script language="javascript">
    var x, y;
    
    function pollKeyB(e) {
       ...
    
       if(x == m && y == n) { 
          document.getElementById("midi").src = "sndwrap.php?snd=" + snd_file;
    } 
    ...
    </head>
    <body onload="init()" onkeyup="pollKeyB(event)">
    <iframe id="midi" src="sndwrap.php"></iframe>
    <table id="main" ...>
    game ui
    </table>
    </body>
    ...
    

     

    I've tried everything from setting the iframe's onfocus event to main's onblur event, but none of the combinations I've tried works.  :( 

     

    in sndwrap.php I get the sound file via $_GET and then set either an embed or MS's function (forget it's name) to play the midi file.  I even tried setting sndwrap's body onfocus event to blur, but that didn't work either.

     

    It seemingly *works* but in order to move the character again, I have to click  inside of the table "main."  Does anyone have any ideas how I keep focus on the keyboard polling, yet still be able to dynamically change sound via the iframe src?

     

    I'm not that familiar with JS other than a few docs I've read.  As a side question, what is purpose of returning true or false in some functions?

×
×
  • 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.