php - mysql select js variable -


hey wanna know if possible?

$result = mysql_query("select * posted_events month_ = ".echo"months";."  ); 

obviously syntax wrong (because doesn't work), want select data database equal variable happen js variable in js file. know can't assign js variable php, unless use ajax, when use ajax, returns empty string first, runs php , gives me value of variable, php script ran. wondering if echo variable.

i'm not using submit or hidden post method because isn't necessary in i'm trying create. need find way php recognize variable , make query. please me. thank lot.

my js:

   var date = new date();  var month = date.getmonth();  var day = date.getday();  var monthdate = date.getdate();  var monthnow= date.getmonth();   var monthnow2;  var current = 1;  var first_date = new date(date.getfullyear(), date.getmonth(), 1);       var start_day = first_date.getday();  var start_day2;  var first_date2;  var weekday;  var day_selected;  var day_selectedtxt;  var monthnowtxt;  var daynum;   var out;  var months;   var calendermonths = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september',                          'october', 'november', 'december'];    var calenderdays = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ];   var daysinmonths = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];     function currentdate(){         var first_day = first_date.getday() +1;         document.getelementbyid("monthelement").innerhtml = calendermonths[month];          for( var days = 1; days <= daysinmonths[month]; days++) {               document.getelementbyid("day"+ first_day).innerhtml = days;             first_day++;          }             //current date              if( month === monthnow) {         monthdatenow = start_day +monthdate;             var today = document.getelementbyid("day"+ monthdatenow);              today.setattribute('class', today.getattribute('class') + ' current');               }             start_day2 = start_day;              monthnow2 = monthnow;                  months = calendermonths[monthnow];                 $.get('load2.php', {month:months} );                                 //where made ajax  } 

my php:

<?php  header("content-type: application/x-javascript"); error_reporting(e_error | e_warning | e_parse);            $months = $_get['month'];        // connect mysql          if ( !( $database = mysql_connect( "localhost",             "root", "" ) ) )                                   die( "could not connect database </body></html>" );      // open events database          if ( !mysql_select_db( "events", $database ) )             die( "could not open events database </body></html>" );               $result = mysql_query("select * posted_events month_ = .'months'.")                      or die ('error updating database because: '.mysql_error());;               $daysarray = array();             while ($row = mysql_fetch_array($result, mysql_assoc)) {                 $daysarray[] =  $row['daynum']; }             $length = count($daysarray);              echo "function test() { ";                  for($i=0; $i < $length; $i++) {              echo "var active = document.getelementbyid('day'+".$daysarray[$i].");              active.setattribute('class', active.getattribute('class') + ' event');  "; }                    echo "}";    ?> 

and in html have <body onload="currentdate(); test(); " class ="home"> , other code ofc, posted cause rest wasn't necessary.

try below code,

<?php  $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) {     die('could not connect: ' . mysql_error()); } echo 'connected successfully';  $months = $_get['month'];  $result = mysql_query("select * posted_events month_ = '$months'");   while ($row = mysql_fetch_array($result, mysql_assoc))  {     $daysarray[] =  $row['daynum'];  }  $length = count($daysarray);  for($i=0; $i < $length; $i++)  {      echo $daysarray[$i]; }         ?> 

mysql not suggested recommend move mysqli or pdo


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -