ravi1988 Posted February 17, 2015 Share Posted February 17, 2015 I am creating a word scramble game in PHP .But I am having difficulty in doing it. What Iam planning to do is to get the jumbled words from the database and display it as tile format or individual buttons . The words are scrambled and I have to do dragging it so that it matched the word from mysql. First how to get individual letters from mysql and that too scrambled. Individual letters , I know it is str_split($words) so that the letter is split into letters. Please help me on this. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted February 17, 2015 Share Posted February 17, 2015 It's hard to help without seeing your code attempts. That's how it works here. Oh - and if your reference to 'mysql' means that you are using the MySQL extension to access your database, stop now and go read up on the mysqlI or PDO extensions and use one of them for your database accessing. See the manual for why this is if you don't know. Quote Link to comment Share on other sites More sharing options...
ignace Posted February 18, 2015 Share Posted February 18, 2015 <?php function get_random_word(PDO $pdo) { $sql = 'SELECT word FROM words WHRE id = (SELECT FLOOR(MIN(id) + RAND() * (MAX(id) - MIN(id))) FROM words)'; $stmt = $pdo->query($sql); if (0 === $stmt->rowCount()) { return ''; } return $stmt->fetchColumn(); } $pdo = new PDO('dsn', 'user', 'pass'); $letters = str_split(get_random_word($pdo)); ?> <html> <head><title>Word Game</title></head> <body> <div class="letters"> <span class="letter"><?php implode('</span><span class="letter">', $letters); ?></span> </div> <script src="//code.jquery.com/jquery-2.1.3.min.js"></script> <script> $(function() { var $dragging = null; $(document.body).on('mousemove', function(e) { if ($dragging) { $dragging.offset({ top: e.pageY, left: e.pageX }); } }).on('mousedown', 'span.letter', function(e) { $dragging = $(e.target); }).on('mouseup', function(e) { $dragging = null; }); }); </script> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.