5 Replies - 1073 Views - Last Post: 17 February 2013 - 01:42 AM

#1 Arfa naqvi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-February 13

to write a code in javascript , and access values from mysql database

Posted 15 February 2013 - 01:04 AM

i have to access values from mysql database and place them against the selected value from combo box i created.
table name=location
feilds=DevID , Location

couldn't embed javascript in php ..






<html>
<head>
<title></title>

<link rel="stylesheet" type="text/css" href="css\style.css" />

</head>
<body>
<div id="page">
		
       <div id="header">
       <div id="headerTitle" align='center'>National Transmission & Dispatch Monitoring System</div>
       <div id="headerSubText">Give Subtitle here...</div>
       </div>
       <div id="bar">

       <div class="navLink"><a href="index.html">home</a></div>
       <div class="navLink"><a href="index.html">about us</a></div>
       <div class="navLink"><a href="index.html">products</a></div>
       <div class="navLink"><a href="index.html">services</a></div>
       <div class="navLink"><a href="index.html">portfolio</a></div>
       <div class="navLink"><a href="index.html">our process</a></div>
       <div class="navLink"><a href="index.html">contact</a></div>
       </div>

<div class="contentTitle"><h1>Field title</h1></div>

<div class="contentText">

<?php





         $connect=mysql_connect('127.0.0.1','root','');
         if(!$connect){ die('error connecting :' .mysql_error());}


         $database=mysql_select_db('SERVER',$connect);
         if(!$database){die('couldnt select database :' .mysql_error());}

         echo "<table align='center'>";
         echo"<tr>";
         echo"<td>";
         echo "<h1 align='center'><b>C@RE</b><h1>";
         echo"</td>";
         
         $query=("Select Location from location");
         $result=mysql_query($query);
         if(!$result){die('no entry in table :' .mysql_error());}
        
        
         echo"</tr>";
         echo"<tr>";
         echo"<td>";


         echo "<select name='id' id='devlocation'>\n";
         echo "<option value='nothing' selected='selected' onchange=''>--DeviceID--</option>\n";
         

         echo"<script type='text/javascript'>
         var selectlocation=document.getElementById(devlocation);
         selectlocation.onchange=function()
{
 var chosenoption=this.options
[this.selectedIndex]
 if(chosenoption.value!='nothing'){window.open (chosenoption.value,'','')}
}
</script>";

         while($row=mysql_fetch_array($result))
         echo"<option value='$row[Location]'>$row[Location]</option>\n";
         
        
         echo "</select>\n";
         echo"</td>";
         echo"</tr>";

         echo"<tr>";
         echo"<td>";
         echo "<input type='submit' value='PLOT' />";
            
         echo"</td>";
         echo"</tr>";
         echo"</table>";
?>

</div>
<div id="footer"></div>

</body>
</html>








Is This A Good Question/Topic? 0
  • +

Replies To: to write a code in javascript , and access values from mysql database

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: to write a code in javascript , and access values from mysql database

Posted 15 February 2013 - 01:25 AM

View PostArfa naqvi, on 15 February 2013 - 09:04 AM, said:

couldn't embed javascript in php ..

that’s probably because PHP is a server-side and Java​Script a client-side language.

if you want to pass data from PHP to JS, look into json_encode().
Was This Post Helpful? 0
  • +
  • -

#3 Arfa naqvi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 15-February 13

Re: to write a code in javascript , and access values from mysql database

Posted 15 February 2013 - 02:39 AM

please tell any other link related to json thingy . having examples for sql and js.
have a look to my code aswel .
thanks for your time .
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: to write a code in javascript , and access values from mysql database

Posted 15 February 2013 - 03:49 AM

here you go: http://json.org/
Was This Post Helpful? 0
  • +
  • -

#5 Ghlavac  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 519
  • Joined: 14-January 09

Re: to write a code in javascript , and access values from mysql database

Posted 17 February 2013 - 12:42 AM

This could probably also be done with node.js maybe?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: to write a code in javascript , and access values from mysql database

Posted 17 February 2013 - 01:42 AM

it could also be done with node.js, though the server-client separation stays the same.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1