-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
echo "<script src='swfobject.js'></script>"; echo "swfobject.embedSWF(" . $path . ", " . $id . ", " . $width . ", " . $height . ", " . $version . ")"; echo "<img src=$image>"; This isn't going to output correct javascript syntax. Firstly you didn't wrap the js in script tags. 2nd, you didn't wrap your values in quotes. The number arguments might work without them but the path certainly won't.
-
lines 1-7 in my code would replace your line #10, since you said it occasionally hangs up on the initial connect. Lines 8-12 in my code is an example of what you'd do afterwards. Basically all the rest of your code would go inside the if part of the if..else, and whatever you want to do to gracefully fail would go inside the else
-
Super nested ifs - Better as switches? Multiple logic expressions
.josh replied to brentman's topic in PHP Coding Help
can't even begin to give you a solid answer without solid details, but generally speaking, database will usually always win out on efficiency in terms of selecting stuff. -
The search term you want to use is "pagination"
-
3. Explain what the actual problem is.
-
IMO it's not a good idea to let your script keep trying to connect indefinitely. Instead, you should rewrite your stuff to gracefully fail and log the fail. But I think it's okay to try a few times before gracefully failing. You can do like: $attempts = 0; $maxAttempts = 10; while ($attempts < $maxAttempts) { $conn_id = ftp_connect($ftp_server); if ($conn_id) break; $attempts++; } if (!$conn_id) { // do stuff to gracefully fail } else { // good to go, do stuff }
-
regex isn't really good for trying to parse code. Having said that, you're going to have to make some assumptions and hope for the best no matter how you slice this, short of running the page through something that can properly render the javascript. But here's my take: preg_match('~var flashvars\s*=\s*(\{.*?\});~s',$content,$flashvars); $flashvars = str_replace("'",'"',utf8_encode($flashvars[1])); $flashvars = array_map('utf8_decode',json_decode($flashvars,true)); This should (again, taking some liberties and hoping for the best), convert it into a php associative array. Array ( [file] => http://***pods/lawandsociety/P130631MLJMuƱiz-Fraticelli.mp3 [width] => 492 [height] => 60 [controlbar] => bottom [dock] => false [icons] => false [logo.hide] => false [logo.position] => bottom-left [playlist] => none [skin] => http://***/wp-content/plugins/flash-video-player/skins/overlay/overlay.swf [autostart] => false [bufferlength] => 1 [item] => 0 [mute] => false [repeat] => none [shuffle] => false [smoothing] => true [stretching] => uniform [volume] => 90 )
-
get_magic_quotes_gpc would not make your column blank. Your problem is elsewhere.
-
$user = array_slice(str_getcsv($string),6,1);
-
right. you already mentioned that. and i already responded to that. was there anything in particular you didn't understand about my response?
-
Migrating a script from one website to another
.josh replied to DRDTechAdmin's topic in PHP Coding Help
well phpMyAdmin is just a convenient interface for interacting with the database; it's not the actual database. But the database the script was using on your old site is probably also on your old site's server. Somewhere in your files should be config info for the database, for host, username, password and database name (and possibly table and column values as well). Sometimes it's coded separately in a "config" file. Sometimes people just pass the info directly to the php database connection function. If it's the latter, look at your php code that has the database stuff in it. You should see some sort of line involving connecting to the database. Something like mysql_connect, mysqli_connect, or maybe some sort of database class with "connect" somewhere in it. Basically you're looking for the "host" value. If it's "localhost" then the database is located on the same server the php script ran on. If it's a remote location then that may be slightly better news for you. If it's pointing to your office's database/server then..well actually, if it's doing that and just dumping the files onto your new server didn't work, then probably your office's database/server needs to be configured to allow remote connection from your new site. But back to "localhost" since it is very likely this - if this is the case then as mentioned, the database for your old site is setup on your old site's server, same as your script (more or less, but i'm trying to not needlessly complicate things). So you will need to go to your old site's database and at a minimum copy how it is setup, but on your new site. This is relatively easy with phpMyAdmin, but it sounds like you don't have it on your new server. Or else you do and you haven't found it. In any case..yeah since this is all new to you, I would not really recommend poking at it yourself. Alternatively.. if for now you don't care about the stuff being stored in the database (and you're sure some other script doesn't depend on it), you could always strip out the part of your script that involves database interaction. Remove all that stuff, including the condition your mail functions are wrapped in. That way your script will mail the stuff out at least (well, assuming the mail server is configured properly!). -
Migrating a script from one website to another
.josh replied to DRDTechAdmin's topic in PHP Coding Help
you need more than the php code/files that handle the database. You will need to setup the database itself with relevant table(s) and column(s). That isn't php code or files to copy over (though you could export the schema from your other server's database to make the process easier). This is something you will need to do through a web admin interface like cpanel/phpmyadmin or on the server command line. -
Migrating a script from one website to another
.josh replied to DRDTechAdmin's topic in PHP Coding Help
random thought: perhaps your old site utilizes a database and you didn't port that over? -
I think saying something would "utterly fail" at something it isn't designed to do in the first place is being a bit harsh and misleading. It's like saying a fish would utterly fail at flying. Well it's not built for the sky in the first place, so if anything is failing, it's your own expectations and/or understanding of it.
-
There is a way to run code when the script ends but that's not really what you are looking for, since the script ends when the script finishes executing and the response is given. To do what you want, you need to do it client-side with javascript, which isn't really reliable. Alternatively you could store the session id and info in a database and have a script constantly check against a "last active" timestamp and then put that script on a cronjob to be run every x amount of time. It's not a solution for making it happen immediately, but it's a step up from trying to rely on a client-side solution.
-
Except that lying to get free shit (which is the same as stealing) is wrong. Even moreso since you can afford it.
-
Poor OOP practices that programmers should avoid
.josh replied to Hall of Famer's topic in Miscellaneous
If you think procedural code is bad and less professional, substandard, mark of a poor programmer, etc. then you're doing it wrong. Listening to shit like this is about as hilarious as listening to fanboys harp on how awesome mac or *nix is and how much microshaft sucks. -
php is the easiest to learn out of the ones you listed. But it really depends on what it is you want to be doing. If you want to make websites and web-based mobile apps, learn php or perl, and you will want to also learn javascript. If you want to make desktop applications, learn one of the other languages in your list. I personally would go for java or C++. Probably out of those two I'd go for java since it's also popular for developing mobile apps.
-
how change include path on diffrent select option
.josh replied to Abhishekphp's topic in PHP Coding Help
include -
one method is to strip the extra spaces before they go into the database. Alternatively, at the time of searching, you can split the search word up at the space and join it with a % and do a LIKE query instead of a = query. For example, $search = "Sample School"; $search = preg_replace("~\s+~","%",$search); $query = "SELECT school FROM tableName WHERE school LIKE '$search'"; This will return the stuff with multiple spaces..but it will return stuff that have anything else inbetween as well, such as "Sample foobar School". If you want to more explicitly only return ones with multiple spaces, you can do a variation of the above, but with a regex approach: $search = "Sample School"; $search = preg_replace("~\s+~",'\s+',$search); $query = "SELECT school FROM tableName WHERE school REGEXP '$search'";
-
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.