Jump to content

galvin

Members
  • Posts

    614
  • Joined

  • Last visited

Everything posted by galvin

  1. Thanks very much for your insight!
  2. I have been tasked with attempting to recreate a web app that allows a user to upload a photo and then cut out a specific part of an image that will be saved as a transparent PNG, with the main use being removing backgrounds from an image (i.e. cutting out a face to use as an avatar, etc) I found two online tools that already do this in different ways: 1. Smart Scissors: Quick video shows how you can drop anchor points with your mouse and it will try to auto find the border and "snap to". Pretty slick but doesn't work perfectly when I played with it. And requires a separate "invert" option to handle all scenarios. http://fotoflexer.com/demos.php 2. Clipping Magic: This one is very cool and surprisingly accurate. You basically paint rough green lines over the stuff you want to keep and red lines over the stuff you want to cut out and a live preview lets you see the result. https://clippingmagic.com/tutorials/basics I am not asking for anyone to give me any code whatsoever, just curious, do you think both of these types of things are doable strictly using PHP (using GD and maybe some other custom PHP classes floating around the web)? Are you able to tell what they both use now? Actually looks like Smart Scissors uses Flash, but not sure about Clipping Magic. I ideally would make something more like Clipping Magic. I just don't want to start building in PHP if there are things that some of you smarter people on this site can tell I will never be able to accomplish using solely PHP, even if I was the best PHP developer ever. Any info, direction, advice would be greatly appreciated. Thanks!
  3. On this dev url , the blue down "auto scroll" arrow under the headline text uses a simple anchor to jump to a spot on the page (and some javascript to slow down the scroll, but I don't think that matters as far as my question goes). As you can see, I'm also using Skrollr to animate objects and when you scroll down manually, the page kind of 'sticks' when the iMac reaches the top of the page. THAT is where I'd like the "auto scroll" arrow button to jump to and STOP. Right now, it scrolls to that spot, but then keeps going a little further. I've tried putting the anchor element in all different spots, but none get the desired resting place. That got me wondering if you can specify that an anchor scrolls down to a certain scroll position (for example, 300 pixels) rather than to an actual anchor element. In other words, my skrollr code fixes the monitor to the top of the page when the user scrolls 300 pixels. So that is where I need the "auto scroll" down arrow to jump to. Anyone know if this is possible, or have another idea? Thanks!
  4. Wasnt sure whether to put this in Javascript or CSS, sorry... I'm using Skrollr at this dev URL (http://workwave.joomlatest01.mms-dev.com/) to make all the desk items "slide away" NOTE: things are messy currently but you get the gist of what happens (i.e. the clutter moves away and the software on the monitor replaces it) I'm using this "helper" function, found here (https://www.bram.us/2014/01/01/skrollr-css-animations-linked-to-scroll-position/)... var setSkrollr = function($el, data) { for (var i = 0, l = data.length; i < l; i++) { // loop all data entries (scroll positions + css property & value) var d = data[i], // the current data entry px = d[0]; // the scroll position (in pixels) css = d[1]; // the css property + value to set $el.attr('data-' + px, css); } } So the skrollr code for these moving desk items looks like this currently... jQuery(function($) { setSkrollr($('#t3-mainnav'), [[0, 'height: 100px'], [300, 'height: 50px']]); setSkrollr($('#t3-mainnav .container'), [[0, 'top: 25px; height: 100px'], [300, 'top: 0px; height: 50px ']]); setSkrollr($('#filecabinet'), [[0, 'top: -60px; left: 60%; display: block;'], [300, 'top: 280px; left: 200%; display: none']]); setSkrollr($('#calculator'), [[0, 'top:520px; left:0%'], [300, 'top:700px; left:-200%']]); setSkrollr($('#stapler'), [[0, 'top:440px; left:12%'], [300, 'top:700px; left:-200%']]); setSkrollr($('#pens'), [[0, 'top:280px; left:38%;'], [300, 'top:580px; left:-200%; ']]); setSkrollr($('#postits'), [[0, 'top:470px; left:70%; display: block;'], [200, 'top:700px; left:200%; display: none;']]); setSkrollr($('#cup'), [[700, 'top:640px'], [1800, 'top:-500px'] ]); setSkrollr($('#map'), [[0, 'top:530px; left:73%; display: block'], [200, 'top:700px; left:200%; display: none; ']]); setSkrollr($('#calendar'), [[0, 'top:500px; left:22%;display: block'], [300, 'top:740px; left:-200%; ']]); setSkrollr($('#monitor'), [[0, 'display:none'], [100, 'display:block; top: 100%'], [300, 'top:11%; position: fixed'], [700, 'top:11%'], [1600, 'top:-100%'] ]); setSkrollr($('#headline'), [[700, 'top:90px'], [1800, 'top:-400px'] ]); setSkrollr($('#desk'), [[700, 'top:560px'], [1800, 'top:-500px'] ]); setSkrollr($('.toplink'), [[0, 'display:block'], [10, 'display:none']]); skrollr.init({ smoothScrolling: false }); I can change the size of the images based on screen resolution using CSS Media Queries and "scale" to reduce the size of the images as the screen width decreases. But right now things are POSITIONED using that skrollr helper function above and I can't change the positions based on screen resolutions. In other words, whatever position I specify in the helper function is the position always. So I can say start the map 85% from the left and it will always be 85% from the left regardless of screen size. So visually it starts in different spots, i.e. if things are positioned OK on a 1920 monitor, when you go down to a 1024 monitor, things are not ideally positioned. It would be a lot of work, but if I could adjust starting/ending positions in media queries, I could make things look perfect at pretty much every resolution. Anyone know if this is possible? I'm new to Skrollr so may just be missing something. Or if anyone has other ideas on how to do this animation easier/more efficiently, please let me know. Thanks!
  5. Thank you both for the suggestions. The adjustments change weekly, but not every request or anything, so I will definitely look into storing them in a table since that seems to be the best route. I will also read up on TEMPORARY tables whether I use them or not. Thanks again!
  6. Thanks for reply.... a. There are around 900 artists b. Every artist will have a value, which can be 0 (i.e. zero would not adjust the original rank at all) c. Not exactly. I don't put the "adjusted" ranks into a table or replace anything. Essentially, I set the original rank each week which does get stored in a database. Each week, adjusted ranks are calculated on the fly and sometimes used, sometimes not. There's no real reason to keep the adjusted ranks in a table since they change quite a bit, and from week to week. It's hard to explain so let me use an easier to digest similar example since I'm also working on fantasy sports site. A fantasy football site might rank players each week. But sometimes scoring is based on PPR (points per reception) so rankings for PPR might be a little different than standard scoring. And most commonly, PPR adjustments would work off of year-to-date statistics, specifically "number of receptions". So each week, the rankings might load based on standard scoring and then if the user clicks "PPR Scoring", the page would look at all reception statistics and create an adjustment to the rankings based off of those stats. So each player would have adjustment number. Then when displaying the rankings again using PPR scoring, the code would re-rank according to the "ppr adjustment". That sounded good in my head, but I may have just confused things ever more. If I have, I apologize. Hopefully it kind of makes sense. If anything, I'd love to hear more about creating a TEMPORARY table. That thought never crossed my mind. Is this common? If I ever ending up getting a lot of traffic accessing the artists ranking page, could it be bad to have a table created and then subsequently (i assume) deleted every single time the page is accessed?
  7. I have these two tables... schedule (gameid, homeid, awayid, weekno, seasonno) teams (teamid, location, nickname) This mysql query below gets me schedule info for ALL 32 teams in an array... $sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } } However, I only want to get info for one specific team, which is stored in the $teamid variable. This should be very easy, right? I have tried multiple things, including this one below (where I added an AND statement of "AND (h.teamid=$teamid OR a.teamid=$teamid)"), but this one still outputs too much... $sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014 AND (h.teamid=$teamid OR a.teamid=$teamid)"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } } Below is the array that the above outputs. In a nutshell, all I want is that 1st array ([1]) which has, in this example, the Eagles full schedule. It's not giving me too much else and I guess I could live with it and just ignore the other stuff, but I'd rather be as efficient as possible and only get what I need... Array ( [1] => Array ( [1] => Jaguars [2] => @ Colts [3] => Redskins [4] => @ 49ers [5] => Rams [6] => Giants [7] => BYE [8] => @ Cardinals [9] => @ Texans [10] => Panthers [11] => @ Packers [12] => Titans [13] => @ Cowboys [14] => Seahawks [15] => Cowboys [16] => @ Redskins [17] => @ Giants ) [27] => Array ( [1] => @ Eagles ) [28] => Array ( [2] => Eagles ) [4] => Array ( [3] => @ Eagles [16] => Eagles ) [14] => Array ( [4] => Eagles ) [15] => Array ( [5] => @ Eagles ) [3] => Array ( [6] => @ Eagles [17] => Eagles ) [] => Array ( [7] => @ Eagles ) [16] => Array ( [8] => Eagles ) [25] => Array ( [9] => Eagles ) [11] => Array ( [10] => @ Eagles ) [7] => Array ( [11] => Eagles ) [26] => Array ( [12] => @ Eagles ) [2] => Array ( [13] => Eagles [15] => @ Eagles ) [13] => Array ( [14] => @ Eagles ) )
  8. Say I have a table called artists with these fields (artistid, rank). Then say I have an array called $rankadjustments with a value for each artist (like 1, 7, 3,-3, 5, 9, etc). I am doing a MYSQL query that gets the info from artists table and sorts according to the rank field like this... $sql = "SELECT * FROM artists ORDER BY rank"; Easy enough. But what if I would like to bring that data back sorted by (rank + rankadjustment). For example, if the artist ranked 1st had a rank of "1" from mysql, but had a rankadjustment of "5" from the rankadjustment array, his "true" rank would be "6". Again, rankadjustment is NOT a field in my table, otherwise it would obviously be simple. It's calculated on the fly and stored in an array. FYI, the array has an index with their "artistid". For example, $rankadjustment[341][8] would be the artist with an artistid of "341" has a rank adjustment of 8. Is there a way to do this IN the query itself? It doesn't seem possible but wanted to find out for sure. If not, what is best way to do? I assume... Get the data sorted JUST by rank and put it all into an array, then create a new array that adds rank to rankadjustment and reorder by the "new" rank amount? I guess that wouldn't be too bad but again, wanted to make sure I'm not missing something that would allow me to do it all in the query (or just more efficiently). Thanks!
  9. Fair question . I am working on a web app that is not close to going live and I'm doing a lot of testing. I have lots of records in my testing database all with the same weeknumber (since that's all i needed up to this point) but I recently added a lot of code that not only displays each weeks data, but also SUMS all data over multiple weeks. I can't test how well that works till I have multiple records for each user. And yes, I could duplicate one or a handful manually and test my code, but there are even more convoluted reasons that I won't bore you with that make it ideal for me to have many, if not all, records duplicated. In a nutshell, it's a statistics website with lots of numbers and there will be a lot of SUMming going on, over muyltiple weeks. Once the site is live, I will be adding all the stats every week, but for now, I just need a bunch of data over multiple weeks (whether it's the same or not) to make sure everything will work properly once I start doing that
  10. Is there a way to duplicate all rows in a table AND change one field's value for each new row? For example... TABLE: comments FIELDS: commentid userid comment weeknumber Say there are only 5 comments in there like this (I have MANY rows, but keeping sample size small for example's sake)... 1-17-hello-3 2-41-hey-3 3-18-yo-3 4-67-sup-3 5-12-hola-3 I would like to duplicate them AND make the "weeknumber" = 4, so the table ultimately has 10 rows like this... 1-17-hello-3 2-41-hey-3 3-18-yo-3 4-67-sup-3 5-12-hola-3 1-17-hello-4 2-41-hey-4 3-18-yo-4 4-67-sup-4 5-12-hola-4 Is this doable? Thanks...
  11. Barand, what you wrote is what I need, just didn't need the SUM part of it, only need the CASE (sorry again for my terrible explanation). Thank you so much!
  12. Sorry I'm really having trouble explaining In plain english, I'm saying...I want to bring back a row for EVERY student in the "students" table, regardless of whether they have any entries in the "grades" table or not. But I would like to know if they specifically have a record in the "grades" table for Period 3. So, based on what you wrote, if it would make Period_3==1 if there was a grade for period 3, or Period_3==0 if there was NOT a grade for period 3, then theoretically that would be all I needed bc I could just run that check and know whether that student had a grade for period 3. I apologize if this doesn't clear things up at all. I have a feeling what you wrote is along the right lines of what I need so I will experiement with that and see what happens. Thank you!
  13. Sorry, one more follow-up to this main question... Let's say I don't want to limit my search to this left join (i.e. LEFT JOIN grades g ON s.studentid = g.studentid AND g.period = 3) but would still like to have that information handy (i.e. still know when a student has an existing grade in period 3). I imagine you can do some type of "AS" statement instead of a LEFT JOIN? Something along these lines, which not surprisingly didn't work when i tried SELECT s.studentid , s.lastname , c.classname , g.grade , g.period , (LEFT JOIN grades g ON s.studentid = g.studentid AND g.period = 3) as period_3_exists FROM students s INNER JOIN classes c USING (studentid) ORDER BY s.lastname Then while looping through the results, I can check if period 3 grades exists by looking for ($row['period_3_exists']==1).
  14. Awesome, thanks again for your VERY helpful information!...
  15. Hopefully quick follow-up... What if each student gets multiple grades and I only want to check if a certain grade exists? For example, what if in grades, there is a field for "period" and it can be 1, 2, 3 or 4. How could I alter the MySQL query to see if a grade exists for SPECIFICALLY period 3? In other words, if period 1 and 2 grades are there, I don't care. I only want to know if period 3 is there. But I still want all the info about every student as originally intended. Can this be done in the mysql query, or do I need to get that data and check it after with PHP? Like maybe add g.period, as in... SELECT s.studentid , s.lastname , c.classname , g.grade , g.period FROM students s INNER JOIN classes c USING (studentid) LEFT JOIN grades g USING (studentid) ORDER BY s.lastname And then run some if statements on $row['g.period'] once I get all the data and put it in an array? I imagine that would work, but if I can do it all in the MySQL query, that would be preferred. Any input appreciated as always. Thanks Greg
  16. Say you have three tables like this... STUDENTS (studentid, name) CLASSES (studentid, classname) GRADES (studentid, grade) And not all students have grades yet. If you're doing a mysql query like below, is there anything you can add to the statement to check if a grade exists for each student? So that if while lopping through the results of the main query, I can easily do something with the students who don't yet have a grade yet (like maybe mark their names in red). I can do this by putting a whole separate mysql query inside the looping of the main query, but that seems terribly inefficient to call the database again for EVERY student. $sql = "SELECT * FROM students, classes, grades WHERE students.studentid = classes.studentid ORDER BY students.lastname"; $info= mysqli_query($connection, $sql); if (!$info) { die("Database query failed: " . mysqli_error()); } else { //code } Thanks! Greg
  17. Cool, very easy to understand explanation. Some of the normalization stuff I'm reading is making my head explode. Thanks again for your thoughts!
  18. Good point, mac_gyver, thank you. So at the end of the day, there is really no situation where doing it the first way would make any sense, right?
  19. I am still trying to fully comprehend table normalization and I'm not asking anyone to explain it bc it's not a simple thing to explain. But I'm working on a football website that tracks players stats each week (catches, yards and touchdowns) and it seems like setting it up this way would make it the easiest (maybe laziest?) to retrieve data to display wherever I want... tablecalled players with these fields: playerid playerfirstname playerlastname week1catches week1yards week1touchdowns week2catches week2yards week2touchdowns ... and so on 17 times till... ... week17catches week17yards week17touchdowns I know that is likely making most of you want to puke but if doing it this way makes it extremely easy to pull this info for display on the site, why is it so wrong? Is the problem that it's much slower than what I THINK is the proper way, ie... table called players with these fields: playerid playerfirstname playerlastname AND table called stats with these fields: playerid week catches yards touchdowns Again, not asking for an explanation of normalization, just if anyone has any quick reasons why the first way is as god awful as I fear it is, I'd appreciate the knowledge. Thanks!
  20. Say you have a string that you know has two, and exactly two, periods in it, like this... $string = "3.12.8" How can you grab the three different values that are separated by periods (in this case, 3, 12 and ? I was thinking use strpos to find the position of the first period, then could use that info to grab everything up to that position. But then I couldn't figure out how you would find the position of the SECOND period. And even if I could get the exact positions of the two periods, it seems like there should be an easier way to simply retrieve values separated by specific characters. Is there a specific function for this type of thing, or was my initial though correct with having to do it in two parts essentially (find positions of periods, then use that knowledge to get the values)? Thanks!
  21. I am updating all my code from mysql to mysqli. Currently using PHP 5.4 but will update to 5.5 once all this updating is done. Anyway, I have this old function for making data safe for inserting into mysql database. I changed all instances of "mysql" to "mysqli"... function mysqli_prep($value) { $magic_quotes_active = get_magic_quotes_gpc(); $new_enough_php = function_exists("mysqli_real_escape_string") ; //i.e. PHP >= v4.3.0 if($new_enough_php) { //PHP v4.3.0 or higher //undo any magic quote effects so mysqli_real_escape_string can do the work if($magic_quotes_active) { $value = stripslashes($value) ;} $value = mysqli_real_escape_string($connection, $value); } else { //before php v4.3.0 // if magic quotes aren;t already on then add slashes manually if(!magic_quotes_active) { $value = addslashes($value); } // if magic quotes are active, then the slashes already exist } return $value; } When I load that page that calls this function, I get... Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in (mypath) This is my $connection by the way, which works fine on other pages that need it... $connection = mysqli_connect('localhost', 'myusername', 'mypassword', 'mytable'); if (!$connection) { die("database connection failed: " . mysqli_error()); } Any ideas what I'm doing wrong?
  22. I'll start by apologizing for the stupid decision that led to this question. A few years ago, I created a PHP/Myysql site with a login system and I created a field in the MySQL called "password" and it stored literally the exact password people entered (I know, I know). The site has proven to have nice traffic potential, so I am going to re-vamp everything, including storing passwords properly (i.e. hashed). My first question... Is there a way to convert regular text passwords to hashed passwords? For example, I could create a new field in the "User" table for "hashedpassword" and write a script that takes all the insecure passwords and turns them into hashed passwords. Then deleted the previous "bad" password field from the database. This would allow me to do it without the customer every knowing anything changed. Quick googling appears to support that it IS doable rather easily, with something like... UPDATE mytable SET password = MD5(password) If not, I guess I would have to create a thing where the first time omeone logged in after I put hashing in place, the site would force them to change their password. I'd rather not annoy the visitors if it all possible. Second question, what is the proper/recommended hashing method to use? Some people seem to poo-poo MD5. If you agree, should I use: MD5 SHA MD5 with a salt SHA with a salt Something else i never heard of NOTE: My site is a fantasy sports site, so the data involved is not overly important. Maybe a salt is overkill? Or is being overly safe never a bad thing? Lastly, don't need to address this, but if anyone can explain it like I'm 5 that would be great because i must be missing something... if you can easily turn a regular password into a hashed password, couldn't hackers easily do the reverse, which would render the hashing almost useless? I get that salting helps, but before salting (i.e. doing ONLY MD5), I don't see how hashing helped that much (if you could reverese figure out the password). What am I missing? Thanks! Greg
  23. Just curious how other people feel about this. I am working on an application where a lot of info is pulled from MySQL and needed on multiple pages. Would it make more sense to... 1. Pull all data ONCE and store it in SESSION variables to use on other pages 2. Pull the data from the database on each new page that needs it I assume the preferred method is #1, but maybe there is some downside to using SESSION variables "too much"? Side question that's kind of related: As far as URLs, is it preferable to have data stored in them (i.e. domain.com/somepage.php?somedata=something&otherdata=thisdata) or use SESSION variables to store that data so the URLs can stay general/clean (i.e. domain.com/somepage.php)? Both are probably loaded questions but any possible insight would be appreciated. Thanks! Greg
×
×
  • 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.