PHP - How To Rotate Order Based On Season
Maybe somebody knows a good way to do this... I have a simple query that seasonal categories - plus one special events header. then for each header I pull all the classes in that category. Right now it just pulls and orders by id. So, regardless of year, they come out in the same order: spring, winter, fall, special events. I'm trying to see if there's a way to make them show in order of relevance to the current time. right now, the "cat" table just has two fields: cat_id, cat_name.
In other words, in autumn, I want them to order: Autumn, winter, summer, spring - then special events. In summer, I want them to order: Summer, spring, autumn, winter - then special events. any thoughts on how to do this? step one, order by relevence to current date. step two, special events is always last. Code: [Select] $query1 = "select * from tbl_cat ORDER by cat_id"; $result_cats = mysql_query($query1) or die(mysql_error()); while ($row = mysql_fetch_array($result_cats)) { $query_selectall = "select *,workshop_date AS tester from tbl_workshops WHERE category={$row['cat_id']} and active_inactive = '1' ORDER by workshop_date"; $result_all = mysql_query($query_selectall) or die(mysql_error()); $catid = $row['cat_id']; $catname = $row['cat_name']; echo "<font face='georgia' size=5><b>".$catname." </b></font><br><div style='color:#fff;'>"; while ($c_row = mysql_fetch_array($result_all)){ // rest of code pulls items that match that specific category id. } Similar TutorialsWhat I'm trying to do here is generate a table based on a form in which the user selects two options. The first option tells the script which database entries to put in the table, the second option tells it how to arrange them. The first works perfectly, the second not at all - it doesn't produce an error, it just doesn't do anything. I've found a number of tutorials that seem to suggest that the problem is somewhere in my punctuation around ORDER BY '$POST[sort]' but I've been unable to find a solution that actually works. Any help would be much appreciated, my code is below. Thank you! mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM main WHERE state='$_POST[state]' ORDER BY '$POST[sort]'"); if(mysql_num_rows($result)==0){ echo "<p align='left'>View Pantries by State</p><div id='stateform'> <form action='../admin/viewstate.php' method='post'> <select name='state' /> <option value='AL'>Alabama</option> <option value='AK'>Alaska</option> <option value='AZ'>Arizona</option> </select> <select name='sort' /> <option value='name'>Name</option> <option value='id'>Id</option> <option value='city'>City</option> <option value='zip'>Zip</option> <option value='timestamp'>Timestamp</option> </select> <input type='submit' value='Go'></input></form> </div>"; } else{ echo "<p align='left'>View Pantries by State</p> <div id='stateform'> <form action='../admin/viewstate.php' method='post'> <select name='state' /> <option value='AL'>Alabama</option> <option value='AK'>Alaska</option> <option value='AZ'>Arizona</option> </select> <select name='sort' /> <option value='name'>Name</option> <option value='id'>Id</option> <option value='city'>City</option> <option value='zip'>Zip</option> <option value='timestamp'>Timestamp</option> </select> <input type='submit' value='Go'></input></form> </div>"; echo "<div id='fptext'><span class='h1'>Food Pantries for " . $_POST['state'] . "</span><br><br></div>"; } echo "<table border='1' align='center' cellpadding='3' width='900px'> <tr> <th>ID</th> <th>Name</th> <th>Type</th> <th>Address</th> <th>State</th> <th>Phone</th> <th>E-mail</th> <th>Website</th> <th>Hours</th> <th>Requirements</th> <th>Additional Information</th> <th>Lat</th> <th>Lng</th> <th>Update</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['type'] . "</td>"; echo "<td>" . $row['address'] . "</td>"; echo "<td>" . $row['state'] . "</td>"; echo "<td>" . $row['phone'] . "</td>"; echo "<td>"; echo "<a href=mailto:".$row['email'].">".$row['email']."</a>"; echo "</td>"; echo "<td>"; echo "<a href=".$row['website']."\>".$row['website']."</a>"; echo "</td>"; echo "<td>" . $row['hours'] . "</td>"; echo "<td>" . $row['requirements'] . "</td>"; echo "<td>" . $row['additional'] . "</td>"; echo "<td>" . $row['lat'] . "</td>"; echo "<td>" . $row['lng'] . "</td>"; echo "<td><a href='../public/updatepage.php?id=".$row['id']."'>Update Pantry</a></td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I have a an array of dates, an array of normal weekly rates, and an array of seasonal rates. Items in the seasons array consist of: start, end, ongoing, and weekly rates. If the ongoing value is "Y" the season should apply to every year. If the value is "N" then the season should only last for the specified range. The below code is doing what i want except I just don't know how to incorporate the ongoing-ness of the seasonal rates. The last date in the dates array should affected by the second seasonal rates. Can't think of how to go about figuring this out. Code: [Select] <?php $dates[] = "1/26/2010"; $dates[] = "4/13/2011"; $dates[] = "4/19/2034"; $normal_rates = array( 'monday' => 0.99, 'tuesday' => 0.99, 'wednesday' => 0.99, 'thursday' => 0.99, 'friday' => 0.99, 'saturday' => 1.50, 'sunday' => 1.50, ); $seasons[] = array( 'start' => "3/15/2011", 'end' => "4/25/2011", 'ongoing' => "Y", 'monday' => 4.99, 'tuesday' => 4.99, 'wednesday' => 4.99, 'thursday' => 4.99, 'friday' => 4.99, 'saturday' => 10.99, 'sunday' => 10.99, ); $seasons[] = array( 'start' => "3/15/2011", 'end' => "4/25/2011", 'ongoing' => "N", 'monday' => 1.99, 'tuesday' => 1.99, 'wednesday' => 1.99, 'thursday' => 1.99, 'friday' => 1.99, 'saturday' => 19.99, 'sunday' => 19.99, ); foreach($dates as $date) { $x_timestamp = strtotime($date); $day_of_the_week = strtolower(date("l", strtotime($date))); $date_rates[$date] = $normal_rates[$day_of_the_week]; foreach($seasons as $key => $value) { $s_timestamp = strtotime($seasons[$key]['start']); $e_timestamp = strtotime($seasons[$key]['end']); if($x_timestamp >= $s_timestamp && $x_timestamp <= $e_timestamp) //should have an or(||) in it for ongoing { $date_rates[$date] = $seasons[$key][$day_of_the_week]; } } }
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. How to do that when you turn 360 degrees no longer come back? Only in this way was? Hey guy's i have a script i did a few months ago and now noticed that it is doing its job but keeps the old file ..so i got the image a few times but on a different angle...
how can i optimize this code to delete the old image when doing the rotation?
<?php session_start(); include_once 'dbconnect.php'; if (!isset($_SESSION['userSession'])) { header("Location: index.php"); } $degrees = -270; $path = $_GET['Folder']; $file =$_GET['Pic']; $fileid =$_GET['id']; $image = $path.'/'.$file; $imageN = $path.'/New_'.$file; //load the image $source = imagecreatefromjpeg($image); //rotate the image $rotate = imagerotate($source, $degrees, 0); $NewImg='New_'.$file ; //set the Content type //header('Content-type: image/jpeg'); //display the rotated image on the browser //imagejpeg($rotate); imagejpeg($rotate,$imageN,100); //free the memory imagedestroy($source); imagedestroy($rotate); $sql = "UPDATE Coupon_list SET product_image_thumb = '$NewImg' WHERE id = '$fileid'"; if (mysqli_query($DBcon, $sql)) { echo "Rotation ok"; echo('<script language="Javascript">opener.window.location.reload(false); window.close();</script>'); } else { echo "Error Rotating: " . mysqli_error($DBcon); } mysqli_close($DBcon); ?> <img src="gears.gif" alt="" />
Hi, There are 10 images in a folder called "Images". All images are named like 1.jpg, 2.jpg, 3.gif, 4.png, and so on... I am using these images on my website with this link: MyDomain.com/Images/1.jpg Now what i want to do is change the image every minute. from 1... to ...10 all images one by one, every minute... Link should remain same, but it should give different image every time. and if someone copies my link of image, it still gets changed every minute. i hope to get some help, better with some example code... Thanks! I have the following code, works rotates the image. But it seems to lose its transparency and add color when rotated to say 45. How can I avoid this? // File and rotation $filename = 'placeholder.png'; $degrees = 45; // Content type header('Content-type: image/png'); // Load $source = imagecreatefrompng($filename); // Rotate $rotate = imagerotate($source, $degrees, 0); // Output imagepng($rotate); ?> Hi, I want to create a function that reads the exif orientation data of an image and rotates it as required - needs to run before before the resize function here, I'm using GD library if that is relevant: function resize_gd($sourceFileName, $folder, $destinationFileName, $newWidth, $newHeight, $keepProportion) { $newWidth = (int)$newWidth; $newHeight = (int)$newHeight; if (!$this->gdInfo >= 1 || !$this->checkGdFileType($sourceFileName)) { return false; } $img = &$this->getImg($sourceFileName); if ($this->hasError()) { return false; } $srcWidth = ImageSX($img); $srcHeight = ImageSY($img); if ( $keepProportion && ($newWidth != 0 && $srcWidth<$newWidth) && ($newHeight!=0 && $srcHeight<$newHeight) ) { if ($sourceFileName != $folder . $destinationFileName) { @copy($sourceFileName, $folder . $destinationFileName); } return true; } if ($keepProportion == true) { if ($newWidth != 0 && $newHeight != 0) { $ratioWidth = $srcWidth/$newWidth; $ratioHeight = $srcHeight/$newHeight; if ($ratioWidth < $ratioHeight) { $destWidth = $srcWidth/$ratioHeight; $destHeight = $newHeight; } else { $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } } else { if ($newWidth != 0) { $ratioWidth = $srcWidth/$newWidth; $destWidth = $newWidth; $destHeight = $srcHeight/$ratioWidth; } else if ($newHeight != 0) { $ratioHeight = $srcHeight/$newHeight; $destHeight = $newHeight; $destWidth = $srcWidth/$ratioHeight; } else { $destWidth = $srcWidth; $destHeight = $srcHeight; } } } else { $destWidth = $newWidth; $destHeight = $newHeight; } $destWidth = round($destWidth); $destHeight = round($destHeight); if ($destWidth < 1) $destWidth = 1; if ($destHeight < 1) $destHeight = 1; $destImage = &$this->getImageCreate($destWidth, $destHeight);Edited June 7, 2019 by mcfc4heatons So whether I am uploading an image through my iphone or sending that image to my computer and uploading it from the computer, it has the same effect. If I upload that image, it'll orient the image in landscape mode. Having said that, I found a function that can fix the orient issue. The problem is I don't know the proper way to integrate it into the image upload script. I have tried several different ways but they all give me errors. Can you show me where exactly I should use this function? // IMAGE ORIENTATION function getOrientedImage($imagePath) { $image = imagecreatefromstring(file_get_contents($imagePath)); $exif = exif_read_data($imagePath); if(!empty($exif['Orientation'])) { switch($exif['Orientation']) { case 8: $image = imagerotate($image,90,0); swapHW(); break; case 3: $image = imagerotate($image,180,0); break; case 6: $image = imagerotate($image,-90,0); swapHW(); break; } } return $image; } // IMAGE UPLOAD SCRIPT if(isset($_FILES['fileToUpload']) AND !empty($_FILES['fileToUpload']["name"])) { if(is_uploaded_file($_FILES['fileToUpload']["tmp_name"])) { $target_dir = '../members/images/'.$global_user_id.'/projects/'.$url_project_id.'/'; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); $source_file = $_FILES["fileToUpload"]["tmp_name"]; $random_name = generateRandomString(10); $new_image = $random_name . '.' . $imageFileType; $resized_image = compressImage($source_file, $new_image, 50); $new_file_path = $target_dir . $resized_image; if(!is_dir($target_dir)){ mkdir($target_dir, 0775, true); } $uploadOk = 1; // Check if image file is a actual image or fake image $check = getimagesize($source_file); if($check !== false) { // echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { $errors[] = 'File is not an image!'; $uploadOk = 0; } // Check if file already exists if (file_exists($target_file)) { $errors[] = 'Sorry, file already exists!'; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 5000000) { $errors[] = 'Sorry, your file size is bigger than 5mb!'; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG" && $imageFileType != "GIF") { $errors[] = 'Sorry, only JPG, JPEG, PNG & GIF files are allowed!'; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if($uploadOk == 0) { $errors[] = 'Sorry, your file was not uploaded!'; // if everything is ok, try to upload file } else { if(rename($new_image, $new_file_path)) { echo 'success'; } else { $errors[] = 'Sorry, there was an error uploading your file!'; } } } else { $errors[] = 'You must upload an image!'; } } Edited December 23, 2019 by imgrooot Is there a way to use php to incorporate a folder of pictures as a clickable slideshow. For instance.... using a pic as a button... to go to the next pic.... except in quantities of 100... without having to manually write the code for each page...? In HTML: Code: [Select] <a href="index3.html"><img src="2.jpg" /></a> <a href="index4.html"><img src="3.jpg" /></a> <a href="index5.html"><img src="4.jpg" /></a> <a href="index6.html"><img src="5.jpg" /></a> <a href="index7.html"><img src="6.jpg" /></a> <a href="index8.html"><img src="7.jpg" /></a> <a href="index9.html"><img src="8.jpg" /></a> Something like using a basic rotating script activated on mouse click? How do i convert this into a button without making 100 pages? Code: [Select] <img src="/path/to/images/ rotate.php?img=my_static_image.jpg" /> I have come up with the rotate.php file as following: Code: [Select] <?php $folder = '/oprah/is/sofuckingfat.com/images/'; $extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['jpeg'] = 'image/jpeg'; $extList['png'] = 'image/png'; /* I believe that most of the following can be omitted once it hits the timer / countdown script */ $img = null; if (substr($folder,-1) != '/') { $folder = $folder.'/'; } if (isset($_GET['img'])) { $imageInfo = pathinfo($_GET['img']); if ( isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) && file_exists( $folder.$imageInfo['basename'] ) ) { $img = $folder.$imageInfo['basename']; } } else { $fileList = array(); $handle = opendir($folder); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if ( isset( $extList[ strtolower( $file_info['extension'] ) ] ) ) { $fileList[] = $file; } } closedir($handle); if (count($fileList) > 0) { $imageNumber = time() % count($fileList); $img = $folder.$fileList[$imageNumber]; } } if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } else { if ( function_exists('imagecreate') ) { header ("Content-type: image/png"); $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 0,0,0); imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } } ?> Would be more or less converting the rotate.php script into the base for the link structure. I assume the timing element in this script would be omitted with a replacement or nothing. I can't figure out what will be the quickest way to go about making the href follow the folder contents. I just want a basic click on the pic to go to the next one until it ends. Thoughts anyone? I've got. Hello, I have classes in a database with no set UNIX date, just the day like Wednesday and in two other columns the start and end dates. I want to be able to order by the day first and then by end_time but php orders the day column by spelling and not the day it holds in chronological order. Is there anyway to change the query to order the day column as a date? See the query below? Code: [Select] $query = "SELECT * FROM zumba_timetable WHERE end_time>'$current_time' ORDER BY day, end_time ASC LIMIT 0,1"; Hi there, just registered and in need of help, this looks a good place to start! I'm a php beginner so please bear with me I have a mysql database which holds 3 pieces of info id: match: 1: I'm trying to sort the results using ORDER BY match ASC but for some reason it's just not for having it... Can't work out if it's an error with my php code or my table. I can order by "ID" no problem but I when I try ordering alphabetically by "match" it won't. my code is: Code: [Select] mysql_connect("***.***.***") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $query = "SELECT * FROM employees WHERE flag = 'tv' ORDER BY match ASC"; $result = mysql_query($query) or die ("Query failed"); $numrows = (mysql_num_rows ($result)); // loop to create rows if($numrows >0){ echo "<table width = 100% border = '0' cellspacing = '2' cellpadding = '0' >"; // loop to create columns $position = 1; while ($row = mysql_fetch_array($result)){ if($position == 1){echo "<tr>";} echo " <td align = 'center'><a href=\"http://www.website.eu/sport-stream/1/{$row['id']}.html\" target=_blank>{$row['match']} <br> <img src=\"{$row['8']}\" width=\"100\" height=\"70\" /> </a> </td> "; if($position == 4){echo "</tr> "; $position = 1;}else{ $position++;} }//while $end = ""; if($position != 1){ for($z=(4-$position); $z>0 ; $z--){ $end .= "<td></td>"; } $end .= "</tr>"; } echo $end."</table> "; }//if And here's a cap of my database: any help for a php n00b would be greatly appreciated! I need to make 0, which displays as POA appear at the ned of the list not at the begining, I currently just use order by price asc and 0 is at the beginning, i need to make 0 at the end I got this code from a previous thread: Code: [Select] mysql_query("SET @rows = 0;"); $res = mysql_query("SELECT @rows:=@rows+1 AS view_rank,COUNT(id) AS views, credit_members_id FROM vtp_tracking GROUP BY credit_members_id ORDER BY views DESC"); $n = array(1 => 'st', 2 => 'nd', 3 => 'rd'); while($row = mysql_fetch_row($res)) { if ( $row[2] != $members_id ) continue; if ( substr($row[0], -1) < 4 ) { $row[0] .= $n[$row[0]]; } else { $row[0] .= 'th'; } echo ' You are in ' . $row[0] . ' place with ' . number_format($row[1]) . ' views.'; break; } Everything seems ok except it orders by the "credit_members_id" and not "views" as entered. Can someone explain why, and how to fix this? Currently i have a query which at the end has this Code: [Select] order by (value/counter) desc"); which works fine, however i was wondering, if in the case that 2 rows have the same, is it possible to set a second value to order by? how do I order two tables by date so that the most recent are first and the most unrecent last? like table 1 should be first then a table 2 then a table 1. does this make sense? I have a database of assorted. Each row contains defined QUANTITIES for each column item. Example: columns for shirt, tie, pants, socks. A row would indicate a purchase of 2 shirts, 1 tie, 0 pants, 3 socks for customer A. Followed by a row indicate a purchase of 1 shirts, 1 tie, 4 pants, 2 socks for customer B, etc. Now I want to sort EACH item, group them by quantity, and get an ordered list by quantity, that provides me with something like this: 1 shirt customer B 2 shirt customer C 3 shirt customer F 3 shirt customer H 4 shirt customer D, etc. I am using this code for my query: $query = "SELECT brisket, COUNT(brisket) FROM pass GROUP BY brisket ORDER BY brisket ASC"; but it is not organizing the info in a correlated manner. Help? Hello, Am trying to get my records in ascending order from the database using 'ORDER BY' but they come randomly. What might be the problem? By not using the order by function in SQL. Like I have $match_1 and $segment_1. They are two seperate tables so how would I order them like the ORDER BY in sql. Is there a way to do that? |