Yohanne Posted February 28, 2014 Share Posted February 28, 2014 Hi coders, i have search box, and i want to show the result from db into javascript message alert box with option yes and cancel botton. please any help and idea how it to work? same like below but it's not working. if (isset($_POST['search'])) { $word = mysql_real_escape_string($_POST['search']); $sql = "SELECT code FROM code_number WHERE code like '%" . $word . "%' ORDER BY code LIMIT 2"; $row = mysql_query($sql) or die(mysql_error()); echo '<script type="text/javascript">'; while($result = mysql_fetch_array($row)) { echo 'alert(\'' + $result[code] + '\');'; } echo '</script>'; } thanks Quote Link to comment Share on other sites More sharing options...
WebStyles Posted February 28, 2014 Share Posted February 28, 2014 (edited) Try confirm('...') instead of alert('...') $result[code] //should be $result['code'] Edited February 28, 2014 by WebStyles Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted February 28, 2014 Share Posted February 28, 2014 This coding practice to mix up sql/php/js/html, etc....in same document is bad. If you want to use sql/php and js you should consider of using AJAX! To your question, the following works for me (tested a minute ago) while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "<script type='text/javascript'>"; echo "alert('{$row['names']}')"; echo "</script>"; } 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.