-
Posts
895 -
Joined
-
Last visited
-
Days Won
1
Everything posted by phppup
-
I'm not entirely clear about what you mean. If I try to determine the number of the last loaded file, won't I still be in the same predicament?
-
I skimmed this thread from the beginning, and while I am not nearly as experienced as those who've been assisting you, I have encountered many issues in coding. My suggestion to you would be to create a NEW simple, form with ONLY one field. <form> <input type="text" name="first"> <input type="submit"> </form> Add a very basic PHP script to create a table with the one field. Load the code with ERROR detection to give you clues to every potential defect. Once you are able to successfully populate the database table with a piece of data from the form, you can THEN expand the code to include additional fields, validation, etc. Create a new version with each effort so that you always have a working template to return to and then just continue to build on the foundation until you have what you wanted. It may take longer, but you will learn and get a better understanding for the future. Good luck.
-
I want to allow users to upload images to a directory. I want the images renamed sequentially and lumped together with each upload. Eg: If Bob uploads 3 images to the BIRD directory, the files will be named BIRD1, BIRD2, and BIRD3. When Tom then uploads 6 images to this directory, they will be sequential from 4 to 9. And when Jane adds 5 the numbering will run from 10 to 14. I suspect that in each instance I will need to SELECT an "image quantity" column and initiate a number sequence from the sum at that point. But my question is more about maintaining the integrity of the sequences. If Tom and Jane upload somewhat simultaneously, how can I control the outcome to prevent Tom from having numbers 4,5,8,11,13 and 14 with Jane's images interspersed in the sequence? Obviously the two uploads will be competing based on image sizes, network speed, etc. How can I keep the separate batches organized as a group?
-
how can I retrieve the single variable that I want from the function? A similar example for what I'm attempting to accomplish $seq=""; function doThis($num=4){ for($i=0; $i<$num; $i++){ echo $i."<br>"; $seq .= $i; } echo $seq; } doThis(); echo $seq; //get variable here How can I access the variable that is created inside the function, and use it on the outside?
-
Got it. One last thing. Is this only needed in PDO? Is there a procedural equivalent? Or is it defaulted?
-
Thanks for the explanation. And that's why I asked. Just because I "like" my code doesn't mean it's doing everything that it should be doing as effectively as it could be doing it. And I want to learn and stride to do it the right way. Aside from instances with a unique parameter,should I be doing this (try & catch) regularly with all my INSERT statements? It would probably reduce the amount of code and PHP checks (ie: input length) while putting a heavier burden on the SQL database. Is that advisable? Preferable? Learned allot. Thanks again everyone.
-
So, if I'm comprehending this correctly, it not do much about determining whether the unique element is available (which the SELECT will accomplish) but MORE about determining whether the value is INSERTable (which is defined in absolute terms by the field being unique).
-
Thanks for the input from everyone. I'm trying to digest all the info, but I'm still a bit uncertain as to why this is better than my code that checks (and prevents) the acceptance of a name that already exists. Isn't something like $sql="SELECT username from table where username = $username"; if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ //BINGO! it already exists //take appropriate action } else { //proceed with the insert } doing the same thing?
-
Thanks for the example @Psycho What does this look like in procedural format? I've seen examples in procedural that use $ex->getMessage() Is that interchangable with getCode?
-
Does one bad apple (the unique value of already exists) spoil the entire insert? $firstname and $lastname (although valid) are rejected and need to be re-submitted of the $username already exists?
-
Finally found success after my last debacle. Now it's time to INSERT my data into a table. My data is $firstname, $lastname, $username Since the $username is UNIQUE, it seems advisable to use a try & catch statement. How do I isolate the $username to do this effectively? How is this method better than using IF statements?
-
I have function xyz($var0, $var1, $var2) and I want to see their values visually. I want to generate FOR-style statement to automate this process. Did creating a function with elements assigned inadvertently create an array?
-
I have variables as such $var0 = "hello"; $var1 = "good bye"; $var2 = "back soon"; I get appropriate results when I do this echo $var0; echo $var1; echo $var2; Now, I want to get the r same esults using a created string like this for($x=0; $x <3; $x++){ $test = "\$var".$x; echo $test."<br>"; } But this only provides $var0 $var1 $var2 How can I generate the respective variable elements so that they reflect their values?
-
I would choose my query based on a careful evaluation of the data held in the database. If all addresses have an accurate city and zip code and your user is searching for a nearby business you may want to prioritize the zip code search since some cities use more than one zip code to cover the geography. You then need to know the boundaries. If a large city has six zip codes, are they set up like a 2 column grid where, 1 and 4 are at the top of each column, or in a circle with 1 in the center? The USPS may not be as logical as you desire but if the user is in a specific zip code and there's a match with a business in the same zip code: BINGO. Otherwise, a citywide result that lets the user determine where he wants to visit may be the best route.
-
@kicken The future is NOW (because that was one of my thoughts initially) My data is being pulled from $my_array which is outside of the function (as opposed to inside a db). So what would be the correct way of addressing the function (as per your last example)? Ideally, I would re-populate the array with any amount of values and still be able to use the same function without having to re-work the structure.
-
I would appreciate some clarification (as I've actually never used arguments this way in functions). Experimentation seems to have revealed that this portion of the code needs to include all the related variables. function choose($x, $z) And that this choose($x, $z); to call the function must match identically. However, we have taken the argument a step further, and some clarity would be helpful. In this example we are assigning the variables in the call, but the function arguments are ALL the sought results? Similar to giving an alias tho the variable???
-
@mac_gyver Understood. Actually trying to funnel this into a more refined set of data that will allow the general processing that you referred to. I think I'm on the right path. Thanks for your input.
-
The global code only worked when ALL global values (or the ones specifically needed at the time) were present. I couldn't find a way to segregate them conditionally.
-
@Barand per reply #1 ... You'll be happy to know that I know that's a mess. But as you realized, it was meant to demonstrate what I was trying to accomplish. As for reply #2, I will have to try it in my script, but I see that it should both solve the issue by calling the function differently in each case AND removed the use of forewarned globals. (Somewhat of a tragedy really since I already made the list. LOL But then, better code is best!) Out of curiosity, of I were to attempt to group the clusters as globals, is it possible? Again, I see the wisdom and (assumed) success in your method, but an still curious. Thanks for the help.
-
I have reduced a process to function with a minimal list of global variables that are required. For simplicity, I'll offer this: If form1 is submitted, then global $a is necessary If form2 is submitted, then global $x and global $z are necessary. Rather than "register" all three, I wanted to use an IF statement to point to the specific globals necessary for the specified form input. My attempts are unsuccessful. $a = 123; $x = "hello"; $z = "there"; function choose(){ global $formSelector; if($formSelector == "form1") { global $a; } else { global $x; global $z; } //Test for result echo $z; if ($a == 123){ echo "bye bye"; } echo "test result"; } //Call function choose(); Can I segregate the globals or is a single comprehensive list the only solution?
-
I am trying to establish an array that will be the levels deep. I want to access all data, but for some reason arrays keep moving to position 1 or more. I want to be able to establish a value at [0], at [0][0], and also [0][0][0] Shouldn't those be the first values at each level? How do I set this up?
-
I'm trying to build an array as follows: Level 1 Level 2 Level 3 Examples seem to be showing similar implementation to this $myArr = array( 'level 1', array('level 2' ), array( array( 5, 6 ), array( 7, 8 ) ) ); But this seems to move the data one section deeper than necessary. In other words, there is nothing at position [0][0] or [0][0][0] (except Array which pushes me down another level). Shouldn't my access to the first item on level 1 be $myArr[0]? How can I get this lined up accordingly?
-
@requinix Am I understanding it "conceptually"? Explanation to develop my understanding or referenced tutorial, please? (I've kind of got the problem solved after removing the FUNCTION() method, but would prefer to achieve my results more systemically.
-
@Barand Then it appears that I was on the right track (sort of nesting the functions) which then actually makes the "outter" function a parent of the function within it. Is that making sense? Correct? (And eliminating the problem of passing values?)
-
In somewhat of a continuation of the previous issue: function first() { //do stuff and result $A } function two($externalArray) { //do stuff to $A when applicable and result $B } I have an external array that I have been able to access WITHOUT using the GLOBAL feature, but now I am having a problem passing values.