PHP - Setting Variable Dates In Php Script
Attempting to set a variable = NOW() + INTERVAL 90 DAY;
I can run SELECT DATE_ADD(NOW(), INTERVAL 90 DAY using MYSQL, but don't know how to move result to a variable. Similar Tutorialsi wonder if anyone can help with this problem. I have a form where the dates are set (and have to be passed) in the format: &checkin_monthday=1&checkin_year_month=2012-3&checkout_monthday=2&checkout_year_month=2012-3 so my form is like this:<select id="b_checkin_month" name="checkin_year_month" onchange="checkDateOrder('b_availFrm2', 'b_checkin_day', 'b_checkin_month', 'b_checkout_day', 'b_checkout_month');"> <option value="2012-2">February '12</option> <option value="2012-3">March '12</option> <option value="2012-4">April '12</option> <option value="2012-5">May '12</option> <option value="2012-6">June '12</option> <option value="2012-7">July '12</option> <option value="2012-8">August '12</option> <option value="2012-9">September '12</option> <option value="2012-10">October '12</option> <option value="2012-11">November '12</option> <option value="2012-12">December '12</option> <option value="2013-1">January '13</option> </select> and then every month i have to manually delete the top month and add a new month at the end. is there anyway to automate this with php rather than the javascript route which means users with scripting disabled cant use the form. I saw something that suggested you can do a check for current month/year with php and then set code based on the result but understandng what to do was beyond me im afraid. Thanks in advance. v=$("#txtusername"); $.post('../actions/check.php',{user:v.val().toLowerCase()},function(d){ if(d=='available'){ $("#usernamemessage").html("<span style='color:green;'>Username is available</span>"); }else if(d=='not-available'){ $( "#txtusername" ).effect( "shake" ); $('#txtusername').css('border', 'solid 2px blue'); var iserror = '1' alert(iserror); } }); alert(iserror);The first alert displays '1', however, the second displays 'undefined'. Why is this? Thanks I have a form where users enter name, username, password etc. The values are posted to a MySQL table where I also have a field called 'ID' that auto increments. I want to store that ID in a SESSION variable that I can carry over to other pages. Need help in doing this please. Hello, I found this great free php calandar script here "" by Xu and Alessandro, and I'm trying to modify the code to mark several dates(birthdays YYYY-mm-dd) from a date column in a sql database. I've played around with the _showDay() method but I can't seem to get it working.. I've also tried to create a _showBirthday() method to modify the css as well but with no luck. What I'm trying to do is loop through the database to mark the respective dates on the calendar, and have a href to display a new page with the person's name when I click the specific date. Can anyone help with this. Thanks in advance! Hi girls and boys I am trying to set a variable if a session OR a cookie has been set, but am unsure on how to write the statement... if (isset($_SESSION['name'])||isset($_COOKIE['name'])) {$variable = $_SESSION['name']||$_COOKIE['name'];} Obviously not working there, but just need a pointer here. any help is appreciated... Hi I'm having a problem getting a query to work. I have a simple form with user input for start and end date with format: 2009-03-19 (todays date): $Startdate = $_POST['date']; This works well when something is entered into the form, and afterwards using my query: SELECT COUNT(*) as total FROM mydb WHERE Date BETWEEN '$Startdate' AND '$EndDate' ........ Problem is if user submits the form without entering anything in the date input fields, which makes sense. I want to check if inputs has been made, and if not set af default date, but can't make it work: if (isset($_POST['date']) && $_POST['date'] !='') { $Startdate = $_POST['date'];} else { $Startdate = '1980-01-01';} How can I set $Startdate to something that can be used in the query as below doesn't work? i'm creating a page counter which updates a value in a database each time the page is loaded. I'm trying to make it so that it checks to see if a session has been set, if not, it updates the database, and then sets the session. This way it wont update every time someone refreshes the page. $id=$_GET['id']; if(!isset($_SESSION[$id])){ $_SESSION[$id]= $id; $views = $row['views'] + 1; $update_views=mysql_query("UPDATE topic SET views='".$views."' WHERE topic_id='".$id."'") i want to set the session variable as that of the page id ($id) The problem is that it keeps updating the database everytime the page is reloaded. I'm not sure if i'm setting the session variable correctly. Any ideas would be great Thanks Is it posible?! I'm sure it can be done. Description of the problem's frame: A server , multiple nic's with IPa , IPb, IPc. The problem : More than one PHP scripts running in the same time ,but ... I use scriptA I want it to use NICa with IPa to connect somewhere. Then I also want scriptB to connect to the same place but from another IP. I don't want to use proxies or other stuff. Just want to use a specific network card. In C it is posible to choose one. Thank you for your time. When I run 'select 1700-price as blah from goldclose as t2 order by dayid desc limit 1' by itself in mysql I get a numerical result: one row, one column. In my php script, the 1700 is actually a variable. so here it is $changequery = sprintf("select $goldprice-price as change from goldclose order by dayid desc limit 1"); $change = mysql_query(changequery); while ($row = mysql_fetch_array($change)) { printf("$row[0]"); } mysql_free_result($changeresult); I get the following error, Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 99 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in <b>/root/fuzzy/htmlmain4.php on line 103 Not sure why? All i want is to get the result of that select statement into a variable such as $change Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. I have a script that adds points together based upon the placing. This is the actual script: Code: [Select] <? $points = 0; if($place === '1st') {$points = $points + 50;} elseif($place === '2nd') {$points = $points + 45;} elseif($place === '3rd') {$points = $points + 40;} elseif($place === '4th') {$points = $points + 35;} elseif($place === '5th') {$points = $points + 30;} elseif($place === '6th') {$points = $points + 25;} elseif($place === '7th') {$points = $points + 20;} elseif($place === '8th') {$points = $points + 10;} elseif($place === '9th') {$points = $points + 10;} elseif($place === '10th') {$points = $points + 10;} elseif($place === 'CH') {$points = $points + 50;} elseif($place === 'RCH') {$points = $points + 40;} elseif($place === 'TT') {$points = $points + 30;} elseif($place === 'T5') {$points = $points + 30;} elseif($place === 'Champion') {$points = $points + 50;} elseif($place === 'Reserve Champion') {$points = $points + 40;} echo "Total HF Points: $points"; ?>What it *should* do (my friend's script works the same way and it works) it starts at points = 0, than if there is a first place, it adds 50, and so forth until it reaches the end. It is included into a file, in this area: Code: [Select] <div class="tabbertab"> <h2>Records</h2> <? $query92 = "SELECT * FROM THISTABLE WHERE VARIABLE='$id' OR VARIABLE = '$name' ORDER BY ABS(VARIABLE), VARIABLE"; $result92 = mysql_query($query92) or die (mysql_error()); echo "<table class='record'> <tr><th>Show</th> <th>Class</th> <th>Place</th></tr> "; while($row92 = mysql_fetch_array($result92)) { $class = $row92['class']; $place = $row92['place']; $entries = $row92['entries']; $race = $row92['show']; $purse = number_format($row92['purse'],2); echo "<tr><td>$race</td> <td>$class</td> <td>$place</td></tr>"; } ?> <tr><td colspan='3'><div align='right'><? include('includes/points.php'); ?></div></td></tr> </table> </div> This is the code that is relevant. When ended here, it echoes the last place that appears in the results (such as a 5th place echoing 30 points). When I move it to be included in the while loop, it shows Total Points: 50 Total Points: 25 Total Points: 10 (depending on the results displayed on that page). What am I doing wrong? Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. Thanks I have this script and i want to take this in one variable & print where i want is this possible Code: [Select] if ($nro > 0) { echo "<table id='gridview' align='center'> <tr> <td bgcolor='#99CC00'>E.T.D.</td> <td bgcolor='#99CC00'>E.T.A.</td> <td bgcolor='#99CC00'>Quantity</td> </tr>"; $totqty=0; while ($row=mysql_fetch_array($result)) { $etd = $row['etd']; $etd = GetDateUserFormat($etd); $eta = $row['eta']; $eta = GetDateUserFormat($eta); $qty = $row['shptqty']; echo "<tr>"; echo "<td>" . $etd . "</td>"; echo "<td>" . $eta . "</td>"; echo "<td>" . $qty . "</td>"; echo "</tr>"; $totqty = $totqty + $qty; } $remqty = $styleqty - $totqty; echo "<br>"; echo "<tr>"; echo "<td bgcolor='#99CC00' colspan='2'> Total Entered Quantity</td>"; echo "<td>" . $totqty . " Kg.</td>"; echo "<td bgcolor='#99CC00'> Remaining Quantity</td>"; echo "<td>" . $remqty . " Kg.</td>"; echo "</tr>"; echo "</table>"; } Hi, I have this script, it all works fine apart from when I pass the variable on, it only passes the first word and not the whole variable The form that actions to the samples page passes the $siteName as My Test Site, if I type echo $siteName in the sameples page, it will print My Test Site, however when I use this Code: [Select] createSample&siteName=$siteName to pass the variable to the next page, it just echos 'My' instead of My Test Site. Even when I scroll over the link above it just shows My in the url. Code: [Select] case "samples": // Get submitted data and assign to variables $siteName = $_POST['siteName']; $adminEmail = $_POST['adminEmail']; $sendmailLoc = $_POST['sendmailLoc']; $imgdir = $_POST['imgdir']; $imgdirbase = $_POST['imgdirbase']; // Write variable data to text file $FileName = "data/server.txt"; $FileHandle = fopen($FileName, 'w') or die("can't open file"); $data = "<?php\n\$siteName = '$siteName';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$adminEmail = '$adminEmail';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$sendmailLoc = '$sendmailLoc';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$imgdir = '$imgdir';\n?>"; fwrite($FileHandle, $data); $data = "<?php\n\$imgdirbase = '$imgdirbase';\n?>"; fwrite($FileHandle, $data); fclose($FileHandle); // Displays the create sample pages page ECHO <<<SAMPLES <table border=0 align=center bgcolor=#00CCFF> <tr> <td><span class=style1><b><center>Create Sample Pages</center></b></span></td> </tr> <tr> <td>Would you like Member Site Maker to create sample pages for: <ul> <li>index.html</li> <li>login.html</li> <li>search.html</li> <li>register.html</li> </ul> </td> </tr> <tr> <td><a href=installation.php?cmd=createSample&siteName=$siteName>Yes</a> </td> <td><a href=installation.php?cmd=mysql>No</a> </td> </tr> </table> SAMPLES; break; Can anybody tell me where I am going wrong please? Thanks basically if you read this, then you can see they have a "passing-var.php" and a "catching-var.php" How can i make this happen without the passing-var.php and make the catching-var.php actually GET a variable Hey, I am currently trying to get a variable created inside a require_once script to be echoed inside the main page that called the require. The script below is a basic idea of what i want to do. I just want to be able to create a basic variable none of this session stuff as its makes life harder at the moment. Thank guys, hope the snippet below gives you a better idea. Main Code: Code: [Select] <body> <?php require_once("makesVariable.php"); <div> // Variable I want to be echo "NOT WORKING" echo $var; </div> ?> </body> External PHP Code: Code: [Select] <?php //Function gets called by previous code to create the needed variable function createTheVariable(){ $var = "I am the variable to be called"; return $var; } ?> How can i put an variable for example
$variable = 'something';
and then how do i put this into this js script
<script>$(document).ready(function() {$('#open$variable').dataTable();});</script> note: Im trying to put this '$variable' inside ' ' right after #open.
Hi
I am trying to create a google chart from data in query.php and using the google api to load it. Everything works until I want to change the MetalSourceID from a drop select box.
PHP CODE FOR DROP DOWN BOX:
<form> <select name="users" onchange="showUser(this.value);drawChart();"> <option value=""> Select a Metal: </option> <?php $query = "SELECT TOP(31) tblMetalPrice.MetalSourceID, tblMetalSource.MetalSourceName from tblMetalPrice INNER JOIN tblMetalSource ON tblMetalPrice.MetalSourceID=tblMetalSource.MetalSourceID ORDER BY tblMetalPrice.DateCreated DESC "; $result = sqlsrv_query( $conn, $query); while( $row = sqlsrv_fetch_object ($result)) { echo "<option value='".$row->MetalSourceID ."'>". $row->MetalSourceName ."</option>"; } sqlsrv_close( $conn); ?> </select> </form>This works fine and generates all the correct values. One part of this changes contents of a table which works fine. But I also echo the MetalSourceID into the javascript for the google api, JS script below: <script type="text/javascript"> google.load('visualization', '1', {'packages':['corechart']}); google.setOnLoadCallback(drawChart); function drawChart() { var jsonData = $.ajax({ url: "query.php", dataType:"json", async: false, data: { 'MetalSourceID' : <?php $q = intval($_GET['q']); echo $q; ?> } }).responseText; var data = new google.visualization.DataTable(jsonData); var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data); } </script>This then runs the query.php script and returns the google line chart, a copy of the query.php script is below: hello everybody! This is just basic script, where i try to modify for the needs. I try to play with it. i want to parse some data. The whole script has three parts: 1. Fetching 2. parsing 3. storing i want to put all into one script: Two are allready put together - there all seems to be clear... So this thread is one that asks for the combining two parts of a script - how to invoke a variable between them What has happened untill now: 1st i need to have a connection to database lets say MySQL. I will suggest to use mysqli instead of mysql. Well - okay i safe this db.php $host="localhost"; //database hostname $username="******"; //database username $password="******"; //database password $database="******"; //database name ?> Now i am going to take a new script and save this config.php <?php require_once('db.php'); //call db.php $connect=mysqli_connect($host,$username,$password); //connect to mysql through mysqli if(!$connect){ die("Cannot connect to host, please try later."); //throw error if any problem } else { $select_db=mysqli_select_db($database); //select database if(!$select_db){ die("Site Database is down at the moment, Please check later. We will be back shortly."); // error if cannot connect to database or db does not exist } } ?> Now i have to take care for the script, that takes the files (note this is very basic - it is only a proof of concept. In the real situation i will take cURL since cURL is much much nicer and more elegant and faster etc. <?php require_once('config.php'); // call config.php for db connection $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); var_dump($content); $pattern = '/<td>(.*?)<\/td>/si'; preg_match_all($pattern,$content,$matches); foreach ($matches[1] as $match) { $match = strip_tags($match); $match = trim($match); var_dump($match); $sql = mysqli_query("insert into tablename(contents) values ('$match')"); } ?> Note: This is just basic script, where you can modify it for your taste and can play with it. Question: If i have stored the URLs that i want to parse in a local file - how do i "call" them in the script. How do i do the call to file where the URLs (there are more than 2500 URLs that have to be parsed) at the following position: $content = file_get_contents("<-here the path to the file goes in-> Position XY! an URL is here "); The folder with the URLs is stored in the same folder as the scripts reside! Many thanks for all hints and for a starting point! if i have to write more - or if you need more infos - or if i have to be more concrete, just let me know! i love to hear from you! db1 |