|
DaTroof posted:It's really not all that non-trivial. Here's a solution I hacked together in a few minutes. Interesting approach to the problem. I kept trying to find a functional solution. I had thought about using a special comparator but I couldn't figure out how to tell it the external $count data. I never thought about using objects.
|
# ? Aug 12, 2008 16:50 |
|
|
# ? May 16, 2024 17:52 |
|
php:<? $_SESSION['current_vendor'] or $_SESSION['current_vendor'] = $r[2]; ?>
|
# ? Aug 12, 2008 17:54 |
|
iamstinky posted:
if $_SESSION['cuerrent_vendor'] doesn't have a value or is equal to '' or 0, set $_SESSION['current_vendor'] to the value of $r[2]?
|
# ? Aug 12, 2008 17:57 |
|
iamstinky posted:
It's just a stupid way to do php:<? if (empty($_SESSION['current_vendor'])) $_SESSION['current_vendor'] = $r[2]; ?>
|
# ? Aug 12, 2008 18:06 |
|
I hate the guy that worked here before me so much. EDIT: Of the six or so apps that I enhance, unfuck and add functionality to, I have at least 10 pages that are 1000+ line switch statements that just end because the one loving function the guy bothered to write in his entire life calls something that includes something that started an output buffer and defined a preg_replace that calls a template and then somehow magically shits out a page that is functional. iamstinky fucked around with this message at 21:39 on Aug 12, 2008 |
# ? Aug 12, 2008 19:46 |
|
iamstinky posted:I hate the guy that worked here before me so much. I'm with you on that one.. I'm currently working on a PHP index page that has a grand total of NINE mysql_connect()s for two seperate databases.
|
# ? Aug 12, 2008 20:17 |
|
How do you add a indexed value to an array via indirection? I have this: code:
Whats odd is that I can change that line to: code:
|
# ? Aug 13, 2008 07:39 |
|
nbv4 posted:How do you add a indexed value to an array via indirection? It's because of how it evaluates. Variable variables work by doing... Getting value (string) of $category['xc_dual'] now you have $string I think what you are assuming this is doing is... evaluating category to a string, then setting $string['xc_dual'] and it doesn't work that way. Edit: I just reread what I wrote and it's consuing, but there are some examples of what you want to do on the Variable Variables page. http://us2.php.net/language.variables.variable MrEnigma fucked around with this message at 07:53 on Aug 13, 2008 |
# ? Aug 13, 2008 07:50 |
|
Oh I see, order of operations. I'm surprised it didnt bring up an error or something... Anyways, I guess a double array is my only option: $times[$category]['xc_dual'] = $temp[0];
|
# ? Aug 13, 2008 08:39 |
|
nbv4 posted:Oh I see, order of operations. I'm surprised it didnt bring up an error or something... Anyways, I guess a double array is my only option: If you increased error_reporting to E_ALL | E_STRICT, it would throw a nice notice for you.
|
# ? Aug 13, 2008 15:45 |
|
Hey guys, Say I wanted to get a file's base name and extension when I upload it somewhere. How would I go about doing that? For example, if I have this in the html: code:
I've tried these and they just echo null: code:
|
# ? Aug 13, 2008 21:59 |
|
weekoldsushi posted:... This should get you going on file posting in PHP.
|
# ? Aug 13, 2008 22:09 |
|
Stephen posted:http://ca3.php.net/manual/en/features.file-upload.php As well as pathinfo().
|
# ? Aug 13, 2008 22:12 |
|
Stephen posted:http://ca3.php.net/manual/en/features.file-upload.php duz posted:As well as pathinfo(). You two are PLAYERS. Thanks!
|
# ? Aug 13, 2008 22:22 |
|
Actually I kinda blew me load a little earlier than expected. Still having problems with pathinfo(). If I do this: code:
|
# ? Aug 13, 2008 22:58 |
|
weekoldsushi posted:Actually I kinda blew me load a little earlier than expected. $file_fileinfo should be $file_info? If you're looking for the full path for the uploaded file on the remote machine, e.g. c:\My Documents\image.gif, that information doesn't get submitted. If you want the local path of the uploaded file on your server, check $_FILES['filename']['tmp_name'] instead.
|
# ? Aug 13, 2008 23:20 |
|
DaTroof posted:$file_fileinfo should be $file_info? I'm an idiot this always happens. Thank you very much. I'm sorry for wasting your time.
|
# ? Aug 13, 2008 23:22 |
|
weekoldsushi posted:
http://php.net/basename
|
# ? Aug 14, 2008 18:00 |
|
An easy question (probably): I have a record in a database that contains the < and > characters (Entrails<VP> is the element in question). When I generate an html page based on that data, the interpreter strips them off as an html tag. So: Entrails Entrails<VP> becomes Entrails Entrails causing some confusion. Without manipulating the data in the database, how can I force PHP to produce a page that displays the <> characters?
|
# ? Aug 14, 2008 19:16 |
|
Agrikk posted:Without manipulating the data in the database, how can I force PHP to produce a page that displays the <> characters? htmlspecialchars
|
# ? Aug 14, 2008 19:17 |
|
Thanks.
|
# ? Aug 14, 2008 19:22 |
|
weekoldsushi posted:
<p> tags are block-level elements, by the way, not an equivalent of a double <br />. They go around paragraphs (or otherwise grouped text). Also, add \n after each line or it displays as one long line in HTML source. Zorilla fucked around with this message at 22:48 on Aug 14, 2008 |
# ? Aug 14, 2008 22:45 |
|
How do you call a function in a way that it uses some default arguments, but takes a value for others? the function definition: function query ($q,$sort_order = "NULL",$where_clause = "", $show_query = false, $page = 0) the call I'm trying to make: //I don't want to show the query, but I do want to return a non-default results page $participants->query($q,$sort_order,$where_clause,,$the_page);
|
# ? Aug 15, 2008 20:50 |
|
vagina rodeo posted:How do you call a function in a way that it uses some default arguments, but takes a value for others? I don't think it's possible to tell PHP to use the default value for a specific call. You can either move your parameters around, to have the frequently unsued params at the end (so you can call the function without passing them) or do something like this: php:<? function some_function($v1='value1',$v2='value1',$v3=null){ $v1=(is_null($v1)?'value1':$v1); $v2=(is_null($v2)?'value2':$v2); $v3=(is_null($v3)?'value3':$v3); echo $v1; echo $v2; echo $v3; } ?> I can't say it's clean, but it'll do the job. I'd still go with changing the parameter order if you can.
|
# ? Aug 15, 2008 21:02 |
|
Alex007 posted:I don't think it's possible to tell PHP to use the default value for a specific call. You can either move your parameters around, to have the frequently unsued params at the end (so you can call the function without passing them) or do something like this: Ugh this is the first oversight in PHP I've found that really bothers me. The situation I'm in makes it stand out really badly. I'm adding an argument to a function and I was hoping default arguments would let me not have to find every time the function is called and update them with the new arguments. Thanks for the info.
|
# ? Aug 15, 2008 21:12 |
|
vagina rodeo posted:Ugh this is the first oversight in PHP I've found that really bothers me. The situation I'm in makes it stand out really badly. I'm adding an argument to a function and I was hoping default arguments would let me not have to find every time the function is called and update them with the new arguments. Thanks for the info. How would you do it otherwise?
|
# ? Aug 15, 2008 21:29 |
|
duz posted:How would you do it otherwise? Python handles this nicely. I think there was a hack somewhere that did reflection to let php do keyword arguments with defaults.
|
# ? Aug 15, 2008 21:49 |
|
You could get around this by making all your functions only take in an array, and then parsing out the variables from that OR You can also use func_get_arg and then have no defined arguments required. This means you'll need to do all your own checking, but it gives you a lot more control. For code that's already written I just make sure to pass in the would be default values to them. Like instead of passing $show_query or nothing at all, pass in false. It's kind of annoying, but you're probably not going to ever change the defaults the function anyways. And if it's new, you could use one of the two solutions above.
|
# ? Aug 15, 2008 21:57 |
|
A nice option is to instead make all defaults NULL, and do is_null() checks at the top of the function to set default values. Of course, this fails if you want to set it to NULL.
|
# ? Aug 15, 2008 23:35 |
|
Is there a simple lightweight php script (and free) that allows users to upload pictures (like gallery) that I can install in my site? Basically something that doesn't require registration or anything else, just an upload button and you're done.
|
# ? Aug 16, 2008 01:11 |
|
LastCaress posted:Is there a simple lightweight php script (and free) that allows users to upload pictures (like gallery) that I can install in my site? Basically something that doesn't require registration or anything else, just an upload button and you're done. R1ch put out a secure PHP script that did this. I don't have search enabled so I can't find it for you, but that should put you on the right track.
|
# ? Aug 16, 2008 01:41 |
|
functional posted:R1ch put out a secure PHP script that did this. I don't have search enabled so I can't find it for you, but that should put you on the right track. It's in the first post of this very thread.
|
# ? Aug 16, 2008 02:12 |
|
You're right, sorry. :\
|
# ? Aug 16, 2008 02:24 |
|
EDIT - I'm an idiot; was editing the wrong php.ini
jimbroof fucked around with this message at 21:33 on Aug 16, 2008 |
# ? Aug 16, 2008 20:50 |
|
WHORENDOUS posted:What can I do? Is there any way to troubleshoot this? None of the guides that I've looked at have helped at all. I'm ready to shoot myself in the face. Do you have PHP error reporting turned off?
|
# ? Aug 16, 2008 21:17 |
|
What's the accepted style when it comes to code formatting in PHP, especially about curly brackets ? Re-reading most of my code I can see three styles, each with their own advantages: Style A- Very spaced, easy to read, but takes a lot of place: code:
code:
code:
(Edit: Fixed indentation) Alex007 fucked around with this message at 00:52 on Aug 17, 2008 |
# ? Aug 17, 2008 00:01 |
|
Alex007 posted:How do you do you do it ? People have been arguing this for ages, but I've never seen any of those three used exactly as presented. The official documentation for PHP shows examples in this format: php:<? if ($variable == "value") { some_function(); // yeah, PHP names things this way instead of with camel casing for some reason } else { some_other_function(); } ?> php:<? if ($variable == "value") { some_function(); } else { some_other_function(); } ?>
|
# ? Aug 17, 2008 00:34 |
|
Zorilla posted:People have been arguing this for ages, but I've never seen any of those three used exactly as presented. The official documentation for PHP shows examples in this format: Yeah, the official documentation is strangely inconsistent. That said, I always use Allman style now, but used to use K&R style a few years ago. The important thing is to stick to one version in your code.
|
# ? Aug 17, 2008 00:42 |
|
Zorilla posted:People have been arguing this for ages, but I've never seen any of those three used exactly as presented. Sorry, the code tags hosed up my indentation, I've fixed it now.
|
# ? Aug 17, 2008 00:53 |
|
|
# ? May 16, 2024 17:52 |
|
Im trying to learn this language in my spare time and im trying to wrap my head around sessions. Im trying to create a 4-step registration type page where I have name and address on 1, email and telephone number on 2, acceptance of terms on 3 and a final confirmation on the final page which lists everything you have inputted. This is the code I have from the pages where information is bieng entered, this is an example of the first page; php:<?php session_start(); $_SESSION['name'] = $name; $_SESSION['address'] = $address; $name=$_POST['name']; $address=$_POST['address']; ?> <form action="two.php" method=POST> Name: <input type=text name='name'><br> Address: <input type=text name=address><br> <input type=submit value="Continue..."><p> </form> php:<?php session_start(); echo "You entered ". $_SESSION['name']; ?> Anyone have any ideas?
|
# ? Aug 17, 2008 22:31 |