Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sab669
Sep 24, 2009

Pretty simple question, how do you send data from one form to another via a hyperlink?

I'm not able to test this at the moment, but are you able to just do:
<a href="update_user.php?<? $POST_['userID'] ?>">Update User</a>

Basically, on users.php it lists all the users in the database, and there is a form at the bottom to add a new user to the database. The aforementioned list is printed out so they're clickable links to the update_user.php form.

But then on update_user.php, I don't know how to actually pull out their userID from the previous page to run my select statement from the database.


God I hate PHP so much.

Adbot
ADBOT LOVES YOU

indulgenthipster
Mar 16, 2004
Make that a pour over

Sab669 posted:

Pretty simple question, how do you send data from one form to another via a hyperlink?

Something like this:

code:
<a href="update_user.php?userid=<? $_POST['userID'] ?>">Update User</a>
Then on the update_user page, you can pull that userid with:

code:
$_GET['userid'];
Security issues aside, that is the most simple approach.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Sab669 posted:

Pretty simple question, how do you send data from one form to another via a hyperlink?

God I hate PHP so much.

Not to white-knight PHP, but I very much doubt any other web language would handle this differently. How else do you expect to have a link send information to another page? You have to rely on something being in either a GET variable or a POST variable in this situation. How PHP handles those is not, I believe, any worse than any other language. It seems pretty basic. (Now, if we get into $_REQUEST then it gets dicier, but no one should be doing that anyway, imo)

This seems akin to saying, "Pretty simple question, but how do I accelerate? God I hate Fords so much."

Sab669
Sep 24, 2009

Golbez posted:

Not to white-knight PHP, but I very much doubt any other web language would handle this differently. How else do you expect to have a link send information to another page? You have to rely on something being in either a GET variable or a POST variable in this situation.

This seems akin to saying, "Pretty simple question, but how do I accelerate? God I hate Fords so much."


Fair enough- I guess I should've just said, "god I hate web development", as I'm much more comfortable working with a console / windows forms.
I wasn't trying to bash the language or anything. I do like web development and I think there's a lot more power in it than working with window forms as I said, but for now it just doesn't make sense to me.

Sab669 fucked around with this message at 17:46 on Aug 8, 2011

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Sab669 posted:

Fair enough- I guess I should've just said, "god I hate web development", as I'm much more comfortable working with a console / windows forms.
I wasn't trying to bash the language or anything. I do like web development and I think there's a lot more power in it than working with window forms as I said, but for now it just doesn't make sense to me.

Ah, okay then. Yeah, it can seem very convoluted to do the simple act of communicating between pages. It can be a really big leap to grok how the interaction between forms and data works, not to mention the fact that every request is almost completely atomic, independent of all previous and future requests, meaning you have to communicate the state of the program with each request, either through a form variable or in a session. I remember when I was first starting, I would always type up the form, then immediately below it type up the code to process the form, and then stare in confusion while I tried to figure out just what order this was all supposed to go in.

Comprehending the general flow of the program is probably the biggest early hurdle.

sonic bed head
Dec 18, 2003

this is naturual, baby!
I am a long time Java guy who just started at a company with a fairly recently built legacy PHP application. It's half in Zend + PHP5 OO and half in horribly procedural + millions of globals type code.

I am trying to figure out how I can create a separate package of PHP code that I can reuse in multiple contexts. For example, in Java, I can create a whole new java project, then package it as a jar and then include that jar wherever I want.

The problem I'm having is how I can do this and still maintain two different autoloading functions because I need this to work within and outside the Zend framework context.

I looked at this blog post - http://jacwright.com/40/php-package-management-and-autoloading/ and it seems to give a fairly straightforward solution, but I don't know if that is the standard way of doing things.

Thank you for your help!

McGlockenshire
Dec 16, 2005

GOLLOCKS!
If you're on PHP 5.3, you might want to look at using namespaces and a PSR-0 autoloader. If you also really, really want to bundle your PHP files together, take a look at the PHAR extension, included by default in 5.3.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I'm finally taking the leap into moving from mysql into either PDO or mysqli. I have experience with mysqli, so I'd prefer that, but first I wanted to ask about my biggest annoyance with it:

Is there any way (including 3rd party libraries) to get an associative array out of a bound query result?

I hate having to do $o->bind_result($foo, $bar, $fnord, ...). It's so uncivilized.

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Golbez posted:

I'm finally taking the leap into moving from mysql into either PDO or mysqli. I have experience with mysqli, so I'd prefer that, but first I wanted to ask about my biggest annoyance with it:

Is there any way (including 3rd party libraries) to get an associative array out of a bound query result?

I hate having to do $o->bind_result($foo, $bar, $fnord, ...). It's so uncivilized.

you mean PDOStatement->fetch(PDO::FETCH_ASSOC)?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Doctor rear end in a top hat posted:

you mean PDOStatement->fetch(PDO::FETCH_ASSOC)?

Yeah. How can I do that in mysqli? :v:

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Golbez posted:

Yeah. How can I do that in mysqli? :v:

Haha I can't read. I don't use mysqli, either, but is this what you want?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Doctor rear end in a top hat posted:

Haha I can't read. I don't use mysqli, either, but is this what you want?

A classic red herring. mysqli_result::fetch_assoc(), as you can see, is a function on the mysqli_result class. Unfortunately, when using a prepared statement, you are dealing with mysqli_stmt, which has no such function. :( All it has is mysqli_stmt::fetch(), which as stated above will only put data into variables.

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players
So you need to use get_result() first?

sonic bed head
Dec 18, 2003

this is naturual, baby!

McGlockenshire posted:

If you're on PHP 5.3, you might want to look at using namespaces and a PSR-0 autoloader. If you also really, really want to bundle your PHP files together, take a look at the PHAR extension, included by default in 5.3.

I actually don't care about bundling them together at all. I much more want them to be able to be used independently from the Zend framework as well as within it. I want it to be just like a java package that I can use. The problem I'm finding with this is that I'll have to somehow hook into the Zend autoloader in order to accomplish that. I think that I need to stop wishing that there was the java package mechanism in PHP. I don't like having to worry about all of these paths on the filesystem everywhere.

Lt Moose
Aug 8, 2007
moose

Hammerite posted:

Magic quotes may be on. Run this script and see what it says:

Yep, it looks like Magic quotes is on. I'll just use stripslashes since I might be changing hosts again in a few months.

Another question: Any reason why PHP isn't displaying my errors? Display_errors is set to 'on' and error_reporting is set to '6143' for the local value (the value of E_ALL). This is making my debugging a lot harder. A blank white page is displayed when I missed a semicolon.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Doctor rear end in a top hat posted:

So you need to use get_result() first?

Mythical. "(No version information available, might only be in SVN)" If it's saying that when we're on 5.3.x, I'm positive it doesn't exist in my 5.1.6. (Just checked - it doesn't)

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Golbez posted:

Mythical. "(No version information available, might only be in SVN)" If it's saying that when we're on 5.3.x, I'm positive it doesn't exist in my 5.1.6. (Just checked - it doesn't)

Man, I want this solved. It looks like there's a solution on Stack Overflow.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Doctor rear end in a top hat posted:

Man, I want this solved. It looks like there's a solution on Stack Overflow.

Looks like it. Thanks. Just shows how hosed up that particular part of mysqli is. I think I'm going to run with PDO for now, I'm seeing no drawbacks compared to mysqli (the performance difference appears at most trivial)...

spacebard
Jan 1, 2007

Football~

Golbez posted:

Looks like it. Thanks. Just shows how hosed up that particular part of mysqli is. I think I'm going to run with PDO for now, I'm seeing no drawbacks compared to mysqli (the performance difference appears at most trivial)...

One thing that the MySQL PDO driver does not currently support is SSL. It has been added to the PHP 5.3 branch so it's only a matter of time until the next official release. This only matters if you don't run on dedicated hardware or are connecting over an open network.

McGlockenshire
Dec 16, 2005

GOLLOCKS!

sonic bed head posted:

I want it to be just like a java package that I can use. The problem I'm finding with this is that I'll have to somehow hook into the Zend autoloader in order to accomplish that.
PHP is not Java, and you will be better off long-term not trying to write PHP code as if it is Java. Packages don't exist, and classes & namespaces are entirely different mechanisms...

ryo
Jan 15, 2003
I haven't done much with XML before.
I'm trying to access the property "results-count" of "api:pagination" in the following XML document:

code:
<?xml version="1.0" encoding="utf-8"?>
<feed>
   <api:schema-version>3.6</api:schema-version>
   <category scheme="http://www.symplectic.co.uk/publications/atom/feeds/" term="item-list" label="Item list"/>
   <id>tag:elements@_______,3.6:/publications-api/feeds/objects?categories=publications&amp;groups=33&amp;per-page=10</id>
   <updated>2011-08-08T16:31:31.5003361+01:00</updated>
   <generator uri="http://url.com/" version="3.6">Symplectic Elements</generator>
   <icon>[url]http://url.com/publications-api/symplectic.ico[/url]</icon>
   <rights>This feed is the property of the _____________, and can only be used with permission.</rights>
   <api:pagination results-count="713" items-per-page="10">
      <api:page position="this" number="1" href="http://url.com/publications-api/objects?categories=publications&amp;groups=33&amp;per-page=10"/>
      <api:page position="first" number="1" href="http:/url.com/publications-api/objects?categories=publications&amp;groups=33&amp;per-page=10"/>
      <api:page position="next" number="2" href="http:/url.com/publications-api/objects?categories=publications&amp;groups=33&amp;page=2&amp;per-page=10"/>
      <api:page position="last" number="72" href="http://ref.cam.ac.uk:8090/publications-api/objects?categories=publications&amp;groups=33&amp;page=72&amp;per-page=10"/>
   </api:pagination>
</feed>
</xml>
I've tried using simpleXML and DOM but just can't work out how to access that specific data.
For example, at the moment I have:
php:
<?
$xml = new DOMDocument();
$xml->load("publications.xml");
$pagination = $xml->getElementsByTagName("api:pagination");
echo 'length: '.$pagination->length;
?>
Which shows the length as 0.
What am I doing wrong?

Edit: upon further investigation, it looks like this has something to do with namespaces. Time to do some reading...

Edit 2: resolved, needed to use GetElementByTagNameNS with the url of the namespace.

ryo fucked around with this message at 15:22 on Aug 9, 2011

sonic bed head
Dec 18, 2003

this is naturual, baby!

McGlockenshire posted:

PHP is not Java, and you will be better off long-term not trying to write PHP code as if it is Java. Packages don't exist, and classes & namespaces are entirely different mechanisms...

I know, I'm just actually trying to understand those mechanisms and utilize them in the way that I need. I'm trying to create a completely separately deployable module of PHP that I can include in different contexts. In order to do that, it seems like I have to create a custom autoloading function that will be able to find my classes no matter where they are included from.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

sonic bed head posted:

I know, I'm just actually trying to understand those mechanisms and utilize them in the way that I need. I'm trying to create a completely separately deployable module of PHP that I can include in different contexts. In order to do that, it seems like I have to create a custom autoloading function that will be able to find my classes no matter where they are included from.

Check out how PEAR and PECL do it, may give you some ideas.

sonic bed head
Dec 18, 2003

this is naturual, baby!

fletcher posted:

Check out how PEAR and PECL do it, may give you some ideas.

Thank you! That's what I'm looking for. I didn't realize that you could use PEAR to do that. I had always thought that PEAR was a way to write C++ extensions to PHP. :D shows how much know.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
See also ths rant about namespaces and autoloaders, which you may also find useful.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
I'm working on an autocomplete for SSN-like numbers. So if they search for '123', it should find the number 444123555. I want to bold the results, thus, 444123555. I then, however, want to format it as an SSN - thus creating 444-12-3555.

Is there some way to say 'put the dash after the nth digit' in PHP? Because I don't want the nth character, just the nth digit - if I could say 'put a dash after the third digit and the fifth digit, ignoring non-numeric characters like <, b, and >' that would be awesome. Is this doable in a regex?

Peanut and the Gang
Aug 24, 2009

by exmarx

Golbez posted:

I'm working on an autocomplete for SSN-like numbers. So if they search for '123', it should find the number 444123555. I want to bold the results, thus, 444123555. I then, however, want to format it as an SSN - thus creating 444-12-3555.

Is there some way to say 'put the dash after the nth digit' in PHP? Because I don't want the nth character, just the nth digit - if I could say 'put a dash after the third digit and the fifth digit, ignoring non-numeric characters like <, b, and >' that would be awesome. Is this doable in a regex?

Maybe something like this, where it matches 3 numbers with any amount of non-numbers interspersed:
code:
$str = '444<b>123</b>555';
$pattern = '#^'
  .'((?:[0-9][^0-9]*){3})'
  .'((?:[0-9][^0-9]*){2})'
  .'((?:[0-9][^0-9]*){4})'
  .'$#'
;
$str = preg_replace($pattern, '$1-$2-$3', $str);

echo $str;
//string '444<b>-12-3</b>555' (length=18)

Bastard
Jul 13, 2001

We are each responsible for our own destiny.

Golbez posted:

I'm working on an autocomplete for SSN-like numbers. So if they search for '123', it should find the number 444123555. I want to bold the results, thus, 444123555. I then, however, want to format it as an SSN - thus creating 444-12-3555.

Is there some way to say 'put the dash after the nth digit' in PHP? Because I don't want the nth character, just the nth digit - if I could say 'put a dash after the third digit and the fifth digit, ignoring non-numeric characters like <, b, and >' that would be awesome. Is this doable in a regex?

Top of my head: split the string based on a regex with preg_split(), then join the resulting array back together with implode using '-' as the glue.

Or go to town using preg_replace().

butt dickus
Jul 7, 2007

top ten juiced up coaches
and the top ten juiced up players

Golbez posted:

I'm working on an autocomplete for SSN-like numbers. So if they search for '123', it should find the number 444123555. I want to bold the results, thus, 444123555. I then, however, want to format it as an SSN - thus creating 444-12-3555.

Is there some way to say 'put the dash after the nth digit' in PHP? Because I don't want the nth character, just the nth digit - if I could say 'put a dash after the third digit and the fifth digit, ignoring non-numeric characters like <, b, and >' that would be awesome. Is this doable in a regex?

After you've found it, add the dashes and do something like this?
code:
$ssn = '12-345-6789';
$search = '456';
$pattern = preg_replace('/(\d)/', '${1}-?', $search);
$search_result = preg_replace("/($pattern)/", '<strong>${1}</strong>', $ssn);
echo $search_result;
e: missed parens and tag close
e2: if you don't want it to bold hyphens after the match you could do this instead:
$pattern = implode('-?',str_split($search));

butt dickus fucked around with this message at 17:43 on Aug 10, 2011

TheGopher
Sep 7, 2009
Got a couple of questions for ya'll if you wouldn't mind.

Was helping a customer out at work who was having issues installing the MongoDB extension for php. It kept throwing this error when running pecl install mongo:

code:
shtool at '/tmp/pear/temp/mongo/build/shtool' does not exist or is not executable.
This is on a Debian Squeeze box and php5-dev was installed. I was at a total loss for why it was happening, and didn't find any helpful info from googling around. Only real pertinent info I have is that the directory /tmp/pear/temp/mongo directory existed, but it was empty. Curious if anybody has any insight into why this error was getting thrown.


Second question. I'm teaching myself php and am trying to figure out how to parse XML. I've taken a look at the documentation for parsing XML, but I'm hoping somebody can point me in the right direction of something beginner friendly. I'm trying to parse something like this: http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]=S2KingKtulu&nick[]=S2Moebiwan

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

TheGopher posted:

Got a couple of questions for ya'll if you wouldn't mind.

Was helping a customer out at work who was having issues installing the MongoDB extension for php. It kept throwing this error when running pecl install mongo:

code:
shtool at '/tmp/pear/temp/mongo/build/shtool' does not exist or is not executable.
This is on a Debian Squeeze box and php5-dev was installed. I was at a total loss for why it was happening, and didn't find any helpful info from googling around. Only real pertinent info I have is that the directory /tmp/pear/temp/mongo directory existed, but it was empty. Curious if anybody has any insight into why this error was getting thrown.


Second question. I'm teaching myself php and am trying to figure out how to parse XML. I've taken a look at the documentation for parsing XML, but I'm hoping somebody can point me in the right direction of something beginner friendly. I'm trying to parse something like this: http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]=S2KingKtulu&nick[]=S2Moebiwan

The user you are trying to install it as probably doesn't have permission to execute scripts that are in /tmp. Google found me this: http://www.php.net/manual/en/apc.installation.php#104496

For parsing XML, check out SimpleXML.

fletcher fucked around with this message at 09:12 on Aug 11, 2011

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
We have code that odbc_connect()s to an off-site database. It then, of course, gets the data one line at a time, odbc_fetch_assoc() style.

Is there any way to shotgun that data? Say, "Get every single row, all at once, and save it to this file?" Because the connection between us and them has become a bottleneck and I'm looking for any way to improve it beyond "get a row, write to a file, repeat".

McGlockenshire
Dec 16, 2005

GOLLOCKS!
Are you able to use PDO's ODBC support?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

McGlockenshire posted:

Are you able to use PDO's ODBC support?

I believe so, what would I do?

Edit: PDOStatement->fetchAll — Returns an array containing all of the result set rows hm!

Except it doesn't let me dump to a file, it pulls into an array... and considering some of these results sets are multi-gig, I doubt I have the memory to handle that. And because their data is ... well let's just say we have to create primary keys for it when we pull it in, so I doubt I could just a LIMIT clause to do my bidding. Foiled again!

Golbez fucked around with this message at 14:28 on Aug 17, 2011

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine
Followup: Looking at our network usage chart, our connections to them seem to be strictly throttled - when each connection finishes, there is a very visible and sharp stairstep in the bandwidth used. Is that potentially something being caused on our side, or should I ask them to open up more tubes?

McGlockenshire
Dec 16, 2005

GOLLOCKS!
It's probably on their side.

Is it possible to switch the file generation to their server instead of transferring the gigs over the internets?

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

McGlockenshire posted:

It's probably on their side.

Is it possible to switch the file generation to their server instead of transferring the gigs over the internets?

I doubt it. This is a combination of ancient technologies that somehow fits inside an ODBC wrapper so we should probably be happy we get this much.

revmoo
May 25, 2006

#basta
What do you guys think about Kohana?

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

revmoo posted:

What do you guys think about Kohana?

It's what I use. If you are really up on you OOP and very comfortable looking at the framework source as the documentation, it's great. If not, code igniter 2 is solid, and has good documentation and a helpful community.

Adbot
ADBOT LOVES YOU

revmoo
May 25, 2006

#basta
Oh cool. Got any tips for learning it? I'm learning it for work right now.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply