Jump to content

sneamia

Members
  • Posts

    62
  • Joined

  • Last visited

    Never

Posts posted by sneamia

  1. I'm using objects as associative arrays in Javascript.

     

    var Cake = new Object();
    Cake['ice cream'] = 'yummy';
    Cake['chocolate'] = 'mmm';
    Cake['none'] = 'aww...';
    

     

    Do objects have a method or property that would tell me how many elements the pseudo-associative array Cake has?

     

    Please don't tell me the only way is to loop through each element and count them.

     

    Thanks.  :)

  2. <?
    $img = imagecreatefromgif('resources/sig_bg.gif');
    
    $background = imagecolorallocate($img, 0, 0, 0);
    $white = imagecolorallocate($img, 255, 255, 255);
    
    $bbox = imagettfbbox(16, 0, 'resources/CALIBRIB.TTF', 'wrong');
    imagettftext($img, 16, 0, 455 - $bbox[2], 70, $white, 'resources/CALIBRIB.TTF', 'wrong');
    
    header('Content-type: image/png');
    imagepng($img);
    imagedestroy($img);
    ?>

     

    As you can see, I open an image stored locally on my server.  It then uses imagettftext to write white text on the image.  However, this is where it screws up.  The text it writes is black, not white.  I'm not entirely sure what I am doing wrong.  Any ideas?

     

    I tried $img = imagecreate(500, 100); and it writes the text correctly, with the correct color.  It seems like there is something incompatible when I use imagecreatefromgif and imagettftext.

  3. if (!empty($_POST['query'])) {
    	$dict = file_get_contents('sowpods.txt');  // Get contents of dictionary in $dict.
    	if (strpos($dict, "\n" . strtoupper(htmlentities($_POST['query'])) . "\n") === false) {
    		echo '<div id="no"><p>No</p></div>';
    	} else {
    		echo '<div id="yes"><p>Yes</p></div>';
    	}
    }
    

     

    The SOWPODS dictionary is arranged like:

    AARDVARK
    AARDVARKS
    AARDWOLF
    AARDWOLVES
    

     

    A \n before each word, and a \n after.

     

    How would you optimize this code snippet?

  4. <?php
    error_reporting(E_ALL);
    switch ($_GET['purpose']) {
    case 'news':
    	$result = mysql_query('SELECT `fulltext` FROM `news` WHERE `newsID` = ' . htmlentities($_GET['argument'] . ' AND `deleted` = 0', ENT_QUOTES));
    	$fulltext = mysql_fetch_array($result);  /* Line 8. */
    	echo 'document.getElementById("text_' . htmlentities($_GET['argument']) . '").innerHTML = "' . str_replace(array("\n", "\r", "\r\n"), '', $fulltext[0]['fulltext']) . '";';
    	break;
    default:
    }
    ?>

     

    That's ajax.php.

     

    When I call .../assets/ajax/?purpose=news&argument=2, it gives me a:

     

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in .../assets/ajax/index.php5 on line 8

  5. INSERT INTO `news` (origID, title, summary, fulltext, timestamp, timestamp2, author, ip) VALUES (3, 'title of it', 'summary of it', 'full text of it', 1194919992, 1194919992, 'loladmin', '68.193.xx.xx')

     

    Fatal Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fulltext, timestamp, timestamp2, author, ip) VALUES (3, 'title of it', 'summary ' at line 1

     

    newsID - smallint(6) - auto_increment, primary key

    origID - smallint(6)

    title - varchar(50)

    summary - text

    fulltext - mediumtext

    timestamp - int(10)

    timestamp2 - int(10)

    author - varchar(20)

    ip - varchar(16)

     

    What am I doing wrong?  I hate these cryptic MySQL errors.

  6. Try changing:

     

    print "<track><location>".$flv."</location></track>";

     

    to

     

    echo '<track><location>' . str_replace("\n", '', $flv) . '</location></track>';

     

    Also, in your second xml output, there is no open trackList.  Is this intentional?

  7. Thanks.

     

    This works:

    <?php
    class mysql {
    protected $mysqlconn;
    function __construct($db_hostname = '******', $db_username = '******', $db_password = '******', $db_name = '*****') {
    	$this -> mysqlconn = @mysql_connect($db_hostname, $db_username, $db_password) or die('Could not connect: ' . mysql_error());
    	mysql_select_db($db_name, $this -> mysqlconn);
    }
    
    function query($querystr) {
    
    }
    
    function __destruct() {
    	@mysql_close($this -> mysqlconn);
    }
    }
    ?>
    

     

     

    edit by redbullmarky: be careful with leaving the login info in your code :)

  8. This sounds like the work of AJAX.

     

    Basically, when you click the next button, you want javascript to create an external javascript include in the body of the page.  This reference includes a .php file, to which you can pass various parameters through get variables.  This .php file gets something from your database, and then outputs javascript that can remove the text of the previous joke and add the text of the next joke.

     

    If you want more specifics, just ask me.

  9. I'm just starting off with OOP, and to be honest, no tutorials provide some applicable examples, so I decided to learn through trial and error.

     

    I'm writing a basic MySQL class, and I'm running into this error.

    Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/tmp/mysqld.sock' (2) in /homepages/.../classes/mysql.php5 on line 10
    

     

    index.php5:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <?php
    error_reporting(E_ALL);
    
    require_once('classes/mysql.php5');
    $result = new mysql();
    
    unset($result);
    ?>
    </body>
    </html>
    

     

    mysql.php5:

    <?php
    class mysql {
    protected $hostname = 'xxxxxx.perfora.net';
    protected $username = 'dboxxxxxxxx';
    protected $password = 'xxxxxxxxx';
    protected $dbname = 'dbxxxxxxx';
    protected $mysqlconn;
    protected $querystr;
    function __construct($hostname = NULL, $username = NULL, $password = NULL, $dbname = NULL) {
    	$mysqlconn = mysql_connect($hostname, $username, $password) or die('Could not connect: ' . mysql_error());
    	mysql_select_db($dbname, $mysqlconn);
    }
    
    function query($querystr) {
    
    }
    
    function __destruct() {
    	mysql_close($mysqlconn);
    }
    }
    ?>
    

     

    Any thoughts?

  10. you dont need to pass in event to the function

     

    in the onload function, change it to = storeLetters;

     

    The function takes the event that is passed into it and then gets the keycode from that.  Is there any way to modify the JS to make it work?

  11. It seems I cannot access 'event' from the head.

     

    event is not defined... Line 25
    

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script language="javascript" type="text/javascript">
    function storeLetters(ev) {
    if (window.event) {
    	keynum = ev.keyCode;
    } else if (ev.which) {
    	keynum = ev.which;
    }
    keychar = String.fromCharCode(keynum);
    if (sofar == undefined) {
    	sofar = keychar;
    } else {
    	sofar += keychar;
    }
    if (sofar.length > 10) {
    	alert(sofar);
    }
    }
    var sofar;
    onload = function(){
    document.getElementById('iframeID').onkeydown = storeLetters(event); ****Line 25****
    }
    </script>
    </head>
    
    <body>
    <iframe src="test.php5" id="iframeID"></iframe>
    <textarea></textarea>
    </body>
    </html>
    

  12. Awesome!  Thank you, sneamia.  It worked.  Now one more question for you.  Instead of popping up an alert to say "file deleted."  Can I have it just pop text on the page that the file was deleted using ajax like how gmail or facebook works.

    Thanks

    Mike

     

    Yes you could, though it would be a bitch to code without the source to your site.

  13. HTML File:

    <html>
    <head>
    <script type="text/javascript">
    function deleteFileAjax(filename) {
    scriptitem = document.createElement('script');
    scriptitem.type = 'text/javascript';
    scriptitem.src = 'ajax.php?filename=' + filename;
    scriptitem.id = 'ajax';
    document.body.appendChild(scriptitem);
    setTimeout('document.body.removeChild(document.getElementById("ajax"))', 500);
    }
    </script>
    </head>
    
    <body>
    <a href="javascript:deleteFileAjax('log.txt');">Delete</a>
    </body>
    </html>
    

     

    Ajax.php

    <?php
    if (isset($_GET['filename'])) {
      if (unlink(htmlentities($_GET['filename']))) {
        echo "alert('Great success!');";
      }
    }
    ?>
    

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