fabrydesign Posted April 29, 2009 Share Posted April 29, 2009 http://thwhap.fabrydesign.com/ I have the center box refreshing with a random database entry. When someone enters something into the form, I'd like it to select a random database entry LIKE whatever is entered. What I have right now only seems to work in Chrome. <script src="http://code.jquery.com/jquery-latest.js"></script> <script> var onLoad = $(document).ready(function(){ $('#randomdate').load('date.php'); var refreshId = setInterval(function(){ $('#randomdate').fadeOut("slow",function(){$(this).load('date.php?q=' + $('input#search').val(),function(){$(this).fadeIn("slow")})}); }, 7500); }); </script> <?php if(strlen($_GET['q']) > 1 && $_GET['q'] != 'undefined'){ $q = $_GET['q']; $query = "SELECT * FROM thwhap_dates WHERE title LIKE '%" . $q . "%' ORDER BY Rand()"; $result = mysql_query($query); if(mysql_num_rows($result) > 0){ $row = mysql_fetch_array($result); echo '<h2>' . $row['year'] . ' ' . $row['era'] . '</h2>'; echo $row['title']; } else { echo 'Nothing found for ' . $q . '.'; } } else { $query = "SELECT * FROM thwhap_dates ORDER BY Rand()"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<h2>' . $row['year'] . ' ' . $row['era'] . '</h2>'; echo $row['title']; } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 29, 2009 Share Posted April 29, 2009 HTML 101 - never have more than 1 DOM element with the same ID on the same page. Quote Link to comment Share on other sites More sharing options...
fabrydesign Posted April 29, 2009 Author Share Posted April 29, 2009 Thanks. I can't believe I made such a silly mistake. Guess I just needed a fresh set of eyes to spot that. 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.