-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Okay I'll give you an example with a script I wrote for something at my job. Basically the purpose of the script is to receive .csv files from some place, parse the data, generate another .csv file based on some defined rules, and send the data back. Well the script itself has lots of moving parts, but the core of it is a while loop that loop. Read a line from the input file, process the line, output the new line to the new file. And within this loop there are two key functions that are run: a function that decides whether or not the input row should be processed, and a function that actually defines the rules for generating the data for the output file. Now here a point in which the script is broken off into a child class. Those two functions are defined in a child class, because from a bigger picture, a user can setup multiple "processes" that receive their own files and have their own rules defined. So the core of that part of the script - the while loop - is the same, but those 2 functions differ from process to process. So what happens if those functions are called and they don't exist? The "core" or "engine" breaks down. So that's where abstract declaration steps in. I can declare abstract public function isValid(); abstract public function generateRow(); in my parent class, and then when someone wants to make a new process, they must define those functions or else the script won't run. The php engine will yell and scream at them and refuse to go any further until they define it. Now, they can do whatever they want inside that function, as long as its defined. It is basically forced acknowledgement that my parent class requires those functions in order to run. Sure, I could put into my parent class a way to check if the function exists, but that's sort of the point: making it easier to ensure that they exist.
-
dot josh tried to impart good sense a laid out and structured defense but advice went unread for verbosity bred a "too long; didn't read" offense
-
well yeah, i knew it was possible and that that people have already done the hard work involved in figuring out out the algorithm. My point was a matter of principle. It's not like finding shortest route across the country or even a town, where there are a million things to consider. Traffic, weather vs. road type. Speed limits. Stop signs. How often you stop for gas or potty breaks. Possibly getting lost or taking the wrong turn despite having a map. It's a store. You can easily fit the entirety of it in your head, the only real variable being how many other people are shopping that day, which this map generator couldn't solve for anyways, short of tapping into the store cameras and doing some real-time evaluation of traffic flow. As I said, the main reason people end up doing a lot more footwork than they need to in a store, is because they don't know where in the store the items are in the first place. So they spend extra time walking around looking for them. Then there are the people who mostly know where their stuff are located, and they have their list, but they don't really take the time to re-order the list based on location. This right here is the biggest gap in potential distance traveled. And most people will see that from having the map with the dots. Or even just having the reorganized list without the map. So, handing someone a reorganized list is already good enough. Handing them a map with locations marked is slightly better since it would also show where on an aisle something is. But connecting the dots is overkill, and I guarantee you most everybody will look at the map and be like "no shit sherlock" about the lines. At best, it *might* save you a few feet, depending on how scattered things are around the store vs. aisle paths. Nobody would notice that difference, unless they go through some kind of excruciating pain every step they take, in which case, why the hell are they grocery shopping in the first place? So IMO, even if someone else already did the hard part and you just have to essentially c/p the code into your script and let it do its thing, doesn't mean it's a good idea to add it in. And since OP said this is for a school assignment, all the more reason he shouldn't do it. If the OP were to take the time to work out the logic for himself and add it in, okay that would definitely give him brownie points. But I guarantee you c/p'ing some 3rd party snippet into the mix to make it look more shiny will NOT earn him more brownie points, and if anything, might possibly hurt him.
-
as far as showing what the "shortest path possible" to get the items is.. IMO that's probably a bit overkill for a store. It's not like when you're driving somewhere and it's a much larger scale.. it's a store. Any average person should be able to clearly see for themselves the "shortest path possible", and it will almost certainly involve just going from one end of the store to the other down the relevant isles. For most people, the hassle of getting a list of items from a store is knowing where they are in the first place, which you'd be marking on the map.
-
Create a database table with 3 columns: one for item, another for X coordinate, and another for Y coordinate. The X and Y coordinates will be the x,y pixel offsets on your map image where the item is located: Item X Y =========== Milk 50 50 Bread 20 40 etc.. Unfortunately, this will mostly be some manual work, though there are some tricks to help make it easier. For example, if it were me, I would output the store map image on a page and write some javascript to loop through all the items in the store. Have a click event listener to capture the current x,y mouse coords when i click on the image and increment to the next item. Then in the end I'd have a js object with all my items and x,y coords mapped out and I could easily move that to a database. Then you make a form where the user can specify the list of items. You receive the list of items and then do a database query to get the X and Y coordinates for each item in the user specified. Then you use the GD library to create an image resource with the map of the store as the canvas, and draw a point on the map using the x,y coordinates. Or overlap some icon or text onto the map, whatever you want to make it look like. Then you output the image. Just google for captcha or watermark tutorials, it's the same principle.
-
would also like to point out that true will only equate to 1 and false will only equate to 0 or '' if they are loosely compared. If you strictly compare them then they do not equate. For example: if (true == 1) echo "true == 1 "; // this will echo if (true === 1) echo "true === 1 "; // this will not echo if (false == 0) echo "false == 0 "; // this will echo if (false === 0) echo "false === 0 "; // this will not echo if (false == '') echo "false == '' "; // this will echo if (false === '') echo "false === '' "; // this will not echo
-
well how do you know what you are(n't) getting unless you're looking at it somehow?
-
what are you doing to compare the returned value
-
come on man, make an effort. First set $device to false. then the switch stuff. Then wrap a condition around the button to check if $device is not false.
-
Let user to take picture from webcam/smart phone
.josh replied to pascal_22's topic in PHP Coding Help
yes, you can have a form field to select an existing image (file) on the phone and upload it. -
simple script showing the basics of IMAP with yahoo (use your own username/password): /* connect to yahoo */ $hostname = '{imap.mail.yahoo.com:993/imap/ssl}INBOX'; $username = 'user@yahoo.com'; $password = 'password'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to yahoo: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'ALL'); /* if emails are returned, cycle through each... */ if($emails) { /* put the newest emails on top */ rsort($emails); /* gonna just output some basic info in table format */ echo "<table>"; echo "<tr align='left'>"; echo "<th>FROM</th>"; echo "<th>DATE</th>"; echo "<th>SUBJECT</th>"; echo "</tr>"; /* for every email... */ foreach($emails as $email_number) { /* get information specific to this email */ $overview = imap_fetch_overview($inbox,$email_number,0); /* echo basic info about it */ echo "<tr>"; echo "<td>".$overview[0]->from."</td>"; echo "<td>".$overview[0]->date."</td>"; echo "<td>".$overview[0]->subject."</td>"; echo "</tr>"; } echo "</table>"; } /* close the connection */ imap_close($inbox);
-
any particular reason why you are trying to use cURL to access your yahoo mail, instead of using IMAP or POP3 ?
-
$managerID = preg_replace('#[^0-9]#i', '', $_SESSION["id"]); This strips anything that is not a number out of the $_SESSION["id"] variable and assigns the results to $managerID. Note: there is an i modifier being used here, which makes the match case-insensitive. This is not necessary for this pattern, since only numbers are expressed. $manager = preg_replace('#[^A-Za-z0-9]#i', '', $_SESSION["manager"]); This strips anything that is not a letter or number out of the $_SESSION["manager"] variable and assigns the results to $manager. Note: there is an i modifier being used here, which makes the match case-insensitive. This is not necessary for this pattern since the pattern already explicitly matches for upper and lowercase letter ranges. This is the pattern delimiter, what specifies the beginning and end of the pattern. You can use pretty much any non-alphanumeric character. A lot of people use / instead because in some languages, that's the only thing available. But using # or ~ is also popular because many times people use regex to parse html/xml content and since / comes up a lot in that content, you have to escape it if you're matching for it within the pattern itself so that php doesn't doesn't get confused by where your pattern actually ends.
-
Detect Mobile Devices - PHP - $_SERVER['HTTP_ACCEPT']
.josh replied to Jayram121's topic in PHP Coding Help
$_SERVER['HTTP_ACCEPT'] just specifies what type of file types or media the client can/will accept as a response. This isn't really useful for mobile device detection specifically, though indirectly I suppose you could use it for some feature detection, which I guess is indirectly relevant to displaying stuff.. Anyways, normally you would parse $_SERVER['HTTP_USER_AGENT'] to detect the mobile device. -
<?php $ua=$_SERVER['HTTP_USER_AGENT']; switch(true) { case stripos($ua,'android') : $device = 'android'; break; case stripos($ua,'ipad') : $device = 'ipad'; break; case stripos($ua,'iphone') : $device = 'iphone'; break; } ?> <ul class="pageitem"><li class="button android"><input name="Submit" value="App Downloads" onclick="window.location='apps.php?id=<?php echo $device; ?>' " type="submit" /></li></ul>
-
Okay so for your percents per level, basically you will want to have a map/table for each of your levels. One way to do this is to just hardcode an array with the percents you want. For example: $percents = array(1=>80,20=2);I just showed your first and last level as an example; you'd add levels 2-19 with your own values. The benefit if doing it this way is that you have more control over balancing your game. Alternatively, if you just want to do something simple like make it an even(ish) spread, you could automate this with a formula: $percents = array(); $minLevel=1; $maxLevel=20; $minPercent=2; $maxPercent=80; for ($p=$minLevel;$p<=$maxLevel;$p++) { $percentInc = ($maxPercent-$minPercent)/($maxLevel-1); $percent = $maxPercent-(($p-1)*$percentInc); $percents[$p] = $percent; } This will give you an array of percents like this: Array ( [1] => 80 [2] => 75.8947368421 [3] => 71.7894736842 [4] => 67.6842105263 [5] => 63.5789473684 [6] => 59.4736842105 [7] => 55.3684210526 [8] => 51.2631578947 [9] => 47.1578947368 [10] => 43.0526315789 [11] => 38.9473684211 [12] => 34.8421052632 [13] => 30.7368421053 [14] => 26.6315789474 [15] => 22.5263157895 [16] => 18.4210526316 [17] => 14.3157894737 [18] => 10.2105263158 [19] => 6.10526315789 [20] => 2 ) IMO you should prolly throw some rounding into the mix but that's a judgement call you'll have to make.
-
so is the problem, that GA numbers don't match up hits shown in your server log? How big of a difference is it?
-
why would you even mention for him to go to the site and do it in the console? The whole point of coding is to automate something so that you don't have to manually do it yourself.
-
you cannot use javascript to get contents from a page hosted on another domain, unless the target domain is specifically setup to allow cross domain scripting.
-
show what you have tried to do
-
[New Error]Warning: Cannot use a scalar value as an array in
.josh replied to coolapps's topic in PHP Coding Help
and i ignored it. This is a free, public help site. If you want free help, it must be public. If you want me to respond to your PM and work with you specifically, that will cost you money. -
[New Error]Warning: Cannot use a scalar value as an array in
.josh replied to coolapps's topic in PHP Coding Help
well what did you actually change? explain what you are attempting to do with that part of the code. -
string example: you have a value and the quotes mark the beginning and end of the value. $myString = "my value";if you want to have quotes in your string: $myString = "she said "hi!" to me"; This won't work because now php thinks the value ended at "she said ". So you can escape the inner quotes: $myString = "she said \"hi!\" to me"; or you can use single quotes: $myString = "she said 'hi!' to me"; or you can use heredoc syntax to mark the beginning and end of the string and not worry about escaping quotes: $myString = <<<EOS she said "hi!" to me another string with 'single' quotes EOS; this makes <<<EOS the beginning delimiter and EOS; the ending delimiter so you can use either or both quotes in your string without having to worry about escaping them.
-
[New Error]Warning: Cannot use a scalar value as an array in
.josh replied to coolapps's topic in PHP Coding Help
well i don't know what the intentions are, but basically up in line 49 you use $r to loop through database results, and the way the loop works is either $r gets some results (a numeric array of columns returnedfor the current row of results) or else (boolean) false. The loop doesn't end until $r gets a value of false. Then, down on line 59 you attempt to assign $r[0] to $maxnum[] well by that time, $r is false (a scalar, boolean value), not an array, so there is no $r[0] index.