Jump to content

show record into message alert box?


Yohanne

Recommended Posts

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

Link to comment
Share on other sites

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>";
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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