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
The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Alright this should be the last question I have with regards to this particular project. I've got everything working as it should and I'm trying to make a report button. That is to say you click the button and it sets the field REPORT to 1 instead of 0 (default) in the sql and I can go from there on fixing it.

I've been working with forms so I know how to make a form and how to change the value in the sql but is there any way for me to make just a single button that executes the php code with no user input beyond the action of clicking the button?

It would be preferable for this to be done without any sort of page reloading or anything to make it as painless as possible to flag a video as reported.

Adbot
ADBOT LOVES YOU

Zorilla
Mar 23, 2005

GOING APE SPIT

The March Hare posted:

I've been working with forms so I know how to make a form and how to change the value in the sql but is there any way for me to make just a single button that executes the php code with no user input beyond the action of clicking the button?

Probably with hidden fields:

code:
<form name="sendreport" action="sendreport.php" method="post">
	<input type="hidden" name="report" value="1" />
	<input type="submit" name="submit" value="Report" />
</form>

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Oh - thanks. I didn't know that existed. I'll give it a go in the morning and report back with results.

Mine GO BOOM
Apr 18, 2002
If it isn't broken, fix it till it is.
The submit button is its own field. Can look for $_POST['submit'] == 'Report' and skip the hidden variables.

Zorilla
Mar 23, 2005

GOING APE SPIT

Mine GO BOOM posted:

The submit button is its own field. Can look for $_POST['submit'] == 'Report' and skip the hidden variables.

Yeah, I only wrote it the way I did because I prefer to explicitly check to see if $_POST["submit"] has been sent before checking the rest of the form. Whatever works, though.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Mine GO BOOM posted:

The submit button is its own field. Can look for $_POST['submit'] == 'Report' and skip the hidden variables.

Internet Explorer doesn't send the value of the submit button if the user submitted the form without clicking it, e.g. by pressing enter in a text field, so sometimes it can be useful to identify the action in a hidden value.

Stephen
Feb 6, 2004

Stoned

DaTroof posted:

Internet Explorer doesn't send the value of the submit button if the user submitted the form without clicking it, e.g. by pressing enter in a text field, so sometimes it can be useful to identify the action in a hidden value.

Holy poo poo I have been wondering why a submit button is posted sometimes and not others for probably over a year now, I just haven't been bothered enough to look into it. Thanks!

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Alright, while that does work like a charm I would really like to be able to execute this code (a simple sql entry) without any sort of a page load/reload on the user end. Is this a pipe dream or is this possible?

cka
May 3, 2004
You'd have to rig up an Ajax request to process the form without reloading the page, but that ain't hard at all (especially if you're using something like jQuery in your project.)

The March Hare
Oct 15, 2006

Je rêve d'un
Wayne's World 3
Buglord
Alright I'll look into ajax. I'm not using jQuery (don't even know what it is) but now that I know this is not something PHP can do I guess I'll go read about Ajax :)

e; looked up jQuery, guess I'll give this a go. Thanks a bundle!

The March Hare fucked around with this message at 19:10 on Aug 26, 2008

moana
Jun 18, 2005

one of the more intellectual satire communities on the web
I'm trying to create a page where my students can enter in answers, and it will email their answers as a txt file to me so I can grade it.

I've got it so I can save their answers as a file specific to their name (e.g. "BethHarrison.txt"). However, I'd like to have that file sent to me by email. Any idea how to do this?

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


moana posted:

I'm trying to create a page where my students can enter in answers, and it will email their answers as a txt file to me so I can grade it.

I've got it so I can save their answers as a file specific to their name (e.g. "BethHarrison.txt"). However, I'd like to have that file sent to me by email. Any idea how to do this?

Did you try searching the documentation?

moana
Jun 18, 2005

one of the more intellectual satire communities on the web

duz posted:

Did you try searching the documentation?
Sorry, the page you linked to doesn't say anything about attaching files, just text messages (is that what I should do instead?). I've been looking through a lot of the documentation, but it just seems very complicated and I'm very much new to programming in PHP so I don't know what's essential and what's not (lots of these have things like a subject, comment, name, etc, stuff I don't need). I guess I was hoping for an easier explanation, since I don't need an email FORM and that's what most of these pieces of code seem to do.

duz
Jul 11, 2005

Come on Ilhan, lets go bag us a shitpost


The easiest thing is probably just read in the file and send it inline.

moana
Jun 18, 2005

one of the more intellectual satire communities on the web

duz posted:

The easiest thing is probably just read in the file and send it inline.
Ok, I will try to do that then. Thank you so much!

HewlettZ
Apr 12, 2006
Panty Raider
I'm currently working on a site using a free PHP shopping cart that utilizes session variables to track the items/cart.

http://www.freebert.com/Products/FreePHPShoppingCart/

is the cart I'm currently using. My question is how can I send the contents of the cart via email to my business email?

I currently have a PHP Email form setup but I'm not sure how to pass the cart contents to the variable.

in summary I would like to have a "send order" button where it will email the cart contents of their session to my business email.

electric_vaseline
Mar 30, 2007
Feel the electricity...in your pants.

HewlettZ posted:

I'm currently working on a site using a free PHP shopping cart that utilizes session variables to track the items/cart.

http://www.freebert.com/Products/FreePHPShoppingCart/

is the cart I'm currently using. My question is how can I send the contents of the cart via email to my business email?

I currently have a PHP Email form setup but I'm not sure how to pass the cart contents to the variable.

in summary I would like to have a "send order" button where it will email the cart contents of their session to my business email.

Well, I went to the site to try and get a feel for it, see what kind of documentation there is and whatnot, and I must say that looks absolutely atrocious. Have you heard of Zen Cart? It's totally free with a huge community to support it and a website that doesn't look like it belongs on GeoCities. You can email orders with it quite easily too.


However, if you really want to stick with that. It would just be a matter of parsing the session data and then
php:
<?
mail($my_business_email, $subject, $mail_body, $header);
?>
...getting the info from the session or cookies though would require intimate knowledge of how the shopping cart works though.

HewlettZ
Apr 12, 2006
Panty Raider
I have looked at Zen Cart I think the problem with that is I already have a site created in html/php and ZenCart seems to be a standalone package with their own templates.

I couldn't really find a good php shopping cart package that integrates into an already functioning site.

Unboxing Day
Nov 4, 2003

I'm having tons of issues with CakePHP. It seems like if you ever venture out of the realms that tutorials and the inadequate manual covers, it has a 'right' way to do things, but good luck finding the 'right way' that fits what you're trying to accomplish, and trying to figure out that 'right way' involves a ton of source diving and refactoring of code you've already written to something 'acceptable' that you hope to god you can fix later on down the line. I find myself blindly following tutorials almost to the letter, and trying to do something 'clever' or apply anything I've learned in a Cake tutorial or manual to something else always seems to get me in trouble.

Are there frameworks out there that allow a little more flexibility, or is this sort of thing indicative of all of the frameworks out there?

Unboxing Day fucked around with this message at 15:41 on Aug 29, 2008

Alex007
Jul 8, 2004

Emo Businessman posted:

Are there frameworks out there that allow a little more flexibility, or is this sort of thing indicative of all of the frameworks out there?

CodeIgniter is awesome AND very flexible.

SA thread: http://forums.somethingawful.com/showthread.php?threadid=2758594

bt_escm
Jan 10, 2001

Emo Businessman posted:

I'm having tons of issues with CakePHP. It seems like if you ever venture out of the realms that tutorials and the inadequate manual covers, it has a 'right' way to do things, but good luck finding the 'right way' that fits what you're trying to accomplish, and trying to figure out that 'right way' involves a ton of source diving and refactoring of code you've already written to something 'acceptable' that you hope to god you can fix later on down the line. I find myself blindly following tutorials almost to the letter, and trying to do something 'clever' or apply anything I've learned in a Cake tutorial or manual to something else always seems to get me in trouble.

Are there frameworks out there that allow a little more flexibility, or is this sort of thing indicative of all of the frameworks out there?

I think the Zend Framework (http://framework.zend.com/) is all kinds of awesome.

Stephen
Feb 6, 2004

Stoned

Emo Businessman posted:

I'm having tons of issues with CakePHP. It seems like if you ever venture out of the realms that tutorials and the inadequate manual covers, it has a 'right' way to do things, but good luck finding the 'right way' that fits what you're trying to accomplish, and trying to figure out that 'right way' involves a ton of source diving and refactoring of code you've already written to something 'acceptable' that you hope to god you can fix later on down the line. I find myself blindly following tutorials almost to the letter, and trying to do something 'clever' or apply anything I've learned in a Cake tutorial or manual to something else always seems to get me in trouble.

Are there frameworks out there that allow a little more flexibility, or is this sort of thing indicative of all of the frameworks out there?
The more I use CakePHP, the more I hate it. It's absolute garbage. There are so many little tweaks and bugs that need workarounds that it's more hassle than it's worth. There are a few things I like such as the pagination plug-in, but alltogether, it's just horseshit.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'm trying to hash some stuff using the Adler32 algorithm, but my results are not coming out right:
php:
<?
/* How the client does it (in Javraaagh!)
   java.util.zip.Adler32 checksum = new java.util.zip.Adler32();
   checksum.update((String)(user_id + timestamp + key).getBytes());
   return checksum.getValue();
*/
$sharedKey = 'Hah! No.';
$userNumber = '13574725';
$timeStamp = '29501416062008';
$hashContext = hash_init('adler32');
hash_update($hashContext, $userNumber);
hash_update($hashContext, $timeStamp);
hash_update($hashContext, $sharedKey);
//result is the same if I concat the the data and call hash_update once
//and/or if I call hash('adler32',$catData)
$result = hexdec(hash_final($hashContext));
?>
(Don't tell me to use some other hash algorithm because I can't. Our result has to match the client's result.)

Our $result is not matching what the Java equivalent (in the comment) is coming up with, and, just in case you feel like telling me it's Java's fault, Python's zip.alder32() method gives me the same answer as the Java method, so I'm 99% certain that either I'm doing something wrong or PHP is hosed up somehow. Since PHP is fairly widely used, I would assume someone would have found this problem before me and fixed it, so I can only conclude that I'm doing something wrong. Question is: what?

Munkeymon fucked around with this message at 21:46 on Aug 29, 2008

Leavy
Feb 15, 2003

rufus

Emo Businessman posted:

I'm having tons of issues with CakePHP. It seems like if you ever venture out of the realms that tutorials and the inadequate manual covers, it has a 'right' way to do things, but good luck finding the 'right way' that fits what you're trying to accomplish, and trying to figure out that 'right way' involves a ton of source diving and refactoring of code you've already written to something 'acceptable' that you hope to god you can fix later on down the line. I find myself blindly following tutorials almost to the letter, and trying to do something 'clever' or apply anything I've learned in a Cake tutorial or manual to something else always seems to get me in trouble.

Are there frameworks out there that allow a little more flexibility, or is this sort of thing indicative of all of the frameworks out there?

I've built probably 20+ sites in CakePHP. I used to get frustrated as hell with it all the time as a lot of the older tutorials put you in a sort of tunnel vision with how it's supposed to work.
It also doesn't help that even comparing the 1.2 version from a year ago to now, you're faced with huge differences in how you're expected to do things.

I'd say just ignore the tutorials except for the "getting started" ones, and for any stumbling block to run into along the way, search their google group and sort by date (very important since the difference in code I mentioned).

It gets a lot of flak for the "conventions" it asks you to adhere to, but there's almost nothing that's not overridable...you just have to know where it is, and that's half the problem. But I can say that a complex set of tables set up for Cake with the appropriate relationships defined is a thing of beauty when you start querying that data. I don't think I could handle 3NF without going insane if it wasn't for their model structure.

Just out of curiosity, what's one of the things you had to struggle with?

edit: if I had to start all over learning a PHP framework given the knowledge I have today, I'd 100% say to go with Zend framework.

Leavy fucked around with this message at 21:43 on Aug 29, 2008

Safety Shaun
Oct 20, 2004
the INTERNET!!!1
{long post about why my include() was broken}

I fixed it but thank you.

Safety Shaun fucked around with this message at 03:32 on Aug 30, 2008

hey mom its 420
May 12, 2007

My PHP is really rusty and I ran into this problem when building a site for something I'm making. I have an associative array with strings as the keys and they point to arrays:
php:
<?
$contents = array
    ( 'introduction' => array( ...
    , 'starting-out' => array( ...
    , 'types-and-typeclasses' => array( ...
    , 'syntax-in-functions' => array( ...
    , 'higher-order-functions' => array ( ...
    , ...
    )
?>
What I want is a function that will take a key and return the key before it and after it. So if I call it like prevnext("types-and-typeclasses"), I want to get two strings back, namely ["starting-out", "syntax-in-functions"]. I implemented this function already but it looks very inelegant. Basically I use a while loop and the next function to traverse the array and then when I find the element I want, I gently caress around with calling prev once, storing the string, then next twice, storing the string, going back once with prev and then returning those two strings. It seems awfully hackish.

tef
May 30, 2004

-> some l-system crap ->

electric_vaseline posted:

However, if you really want to stick with that. It would just be a matter of parsing the session data and then
php:
<?
mail($my_business_email, $subject, $mail_body, $header);
?>
...getting the info from the session or cookies though would require intimate knowledge of how the shopping cart works though.

Escaping the data too - although unlikely, there is the possibility of header injection in php if the adress or subject can be controlled by the user.

MononcQc
May 29, 2007

Bonus posted:

My PHP is really rusty and I ran into this problem when building a site for something I'm making. I have an associative array with strings as the keys and they point to arrays:
php:
<?
$contents = array
    ( 'introduction' => array( ...
    , 'starting-out' => array( ...
    , 'types-and-typeclasses' => array( ...
    , 'syntax-in-functions' => array( ...
    , 'higher-order-functions' => array ( ...
    , ...
    )
?>
What I want is a function that will take a key and return the key before it and after it. So if I call it like prevnext("types-and-typeclasses"), I want to get two strings back, namely ["starting-out", "syntax-in-functions"]. I implemented this function already but it looks very inelegant. Basically I use a while loop and the next function to traverse the array and then when I find the element I want, I gently caress around with calling prev once, storing the string, then next twice, storing the string, going back once with prev and then returning those two strings. It seems awfully hackish.
Not sure if this is what you're looking for, quick and dirty:

php:
<?
#based on the array you described
function getPrevNext($dict, $current_key) {
    $keys = array_keys($dict);
    $num_key = array_search($current_key, $keys);
    return array('prev'=>$keys[$num_key-1], 'next'=>$keys[$num_key+1]);
}

print_r(getPrevNext($contents,'types-and-typeclasses'));

?>
outputs:
code:
Array
(
    [prev] => starting-out
    [next] => syntax-in-functions
)
If there's no previous or next entry, it should set the corresponding return value in the array to NULL
edit: fixed poo poo. didn't test properly and if there was no key corresponding, would return the firt one as next.

This one will throw an exception if the key doesn't exist:
php:
<?
function getPrevNext($dict, $current_key) {
    try {
        $keys = array_keys($dict);
        $num_key = array_search($current_key, $keys);
        if($num_key===False)
          throw new Exception ("key '{$current_key}' not in array");
        return array('prev'=>$keys[$num_key-1], 'next'=>$keys[$num_key+1]);
    }
    catch(Exception $e) {
        echo $e;
    }
}
?>

MononcQc fucked around with this message at 16:07 on Aug 30, 2008

hey mom its 420
May 12, 2007

Ah, awesome! Yeah, that looks much more elegant! My PHP's real rusty, I totally forgot about array_keys and array_search. Thanks!

kalicki
Jan 5, 2004

Every King needs his jester
So I'm teaching myself PHP for a specific project involving copying .flv files from one site and rehosting at another (EA Sports World videos to get around their 5 video limit specifically), and I've run into a wall at getting the videos to transfer directly from their server to mine.

I've tried using get_stream_contents and couldn't get that to work, and now I'm trying cURL, and can't get that to work. Any thoughts? Here's what I've got right now that isn't working:

php:
<?
$ch = curl_init();
$save = fopen("videos/test.flv", "r+");
curl_setopt($ch, CURLOPT_URL, "$URL");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $save);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
fclose($save);
?>
$URL being properly defined of course.

Also, I've just got it as test.flv for now, but I'd like to save it as the same actual filename, which in this case is something like: http://videocdn.easw.easports.com/easportsworld/media2/ncaa09/526101/882A0001_4_FLV_VIDEO_iOk.flv
and I'd like to save it as videos/882A0001_4_FLV_VIDEO_iOk.flv; how would I do this?

Sorry if these questions come off as too newbieish, but well, I am, and I've scoured google. Thanks.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

kalicki posted:

So I'm teaching myself PHP for a specific project involving copying .flv files from one site and rehosting at another (EA Sports World videos to get around their 5 video limit specifically), and I've run into a wall at getting the videos to transfer directly from their server to mine.

I've tried using get_stream_contents and couldn't get that to work, and now I'm trying cURL, and can't get that to work. Any thoughts? Here's what I've got right now that isn't working:

php:
<?
$ch = curl_init();
$save = fopen("videos/test.flv", "r+");
curl_setopt($ch, CURLOPT_URL, "$URL");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $save);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
fclose($save);
?>
$URL being properly defined of course.

Also, I've just got it as test.flv for now, but I'd like to save it as the same actual filename, which in this case is something like: http://videocdn.easw.easports.com/easportsworld/media2/ncaa09/526101/882A0001_4_FLV_VIDEO_iOk.flv
and I'd like to save it as videos/882A0001_4_FLV_VIDEO_iOk.flv; how would I do this?

Sorry if these questions come off as too newbieish, but well, I am, and I've scoured google. Thanks.
CURLOPT_RETURNTRANSFER will make the curl_exec function return the data you need instead of just outputting it.

For the filename, just use your favourite method of pulling the filename out of the url. There's a function for that or something. There's a function for everything.
I used this: http://ca3.php.net/manual/en/function.basename.php


I would probably separate the url functions and the writing functions instead of interspersing them, too.
php:
<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "$URL");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $save);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);

basename($URL);
$save = fopen("videos/$filename", "r+");
fwrite($save,$data);
fclose($save);
?>
Note that the only things I added were the $data variable, the basename function, and the fwrite function

kalicki
Jan 5, 2004

Every King needs his jester
Thanks, I've gotten it working... kind of.

It now saves this :V

code:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a
href="http://ll-341.ea.com/easportsworld/media2/ncaa09/526101/882A0001_1_FLV_VIDEO_Jym.flv">here</a>.</p>
</body></html>
So I turned on CURLOPT_FOLLOWLOCATION, but then get:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in public_html/ea/upload.php on line 26

Then, dropping the redirected url into my function works, so at least that part is filled. I guess I'll try messing about with the couple functions that deal with this error in the help here unless anyone has a better suggestion: http://ca3.php.net/manual/en/function.curl-setopt.php

Thanks!

edit: Nevermind, got this part working. Made it so it downloads the 302 page, eregi through it for the link, and then redo another cURL with it.

kalicki fucked around with this message at 22:58 on Sep 1, 2008

Alex007
Jul 8, 2004

I'm trying to use preg_replace to perform word censor with PHP but it seems my regexp doesn't work as exprected.

At first I was using str_replace, but they are too easily evaded, instead of "gently caress" just type "fuuck" and it gets displayed and not filtered.

This is my code:
php:
<?
    $Msg = 'gently caress !';
    
    echo 'Before: '.$Msg.'<br><br>';
    
    $Censor[] = '{f*u*c*k*}';
    $Msg = preg_replace($Censor, '*static*', $Msg);
    
    echo 'After: '.$Msg.'<br><br>';
?>
$Censor is an array because I plan on adding more words.

This is the result:
code:
Before: gently caress !

After: *static*F*static**static* *static*!*static*
I'd expect it to output "*static*" for "gently caress", "fuuuuccckkk" and "fuckkkkkk", etc. But it seems to catch every letter separately and not the whole word.

What am I doing wrong ?

EDIT: Got it, had to use a + instead of a *, since * matches 0 or more, and + matches 1 or more.

Alex007 fucked around with this message at 03:03 on Sep 3, 2008

waffle iron
Jan 16, 2004
That is a pretty horrible way of filtering because it will match on anything that contains f, u, c, and k in that order, whether it be a word or a paragraph.

Edit: Actually it isn't but the you have people putting in underscores or spaces and the whole filtering falls apart again.

waffle iron fucked around with this message at 05:11 on Sep 3, 2008

Alex007
Jul 8, 2004

waffle iron posted:

That is a pretty horrible way of filtering because it will match on anything that contains f, u, c, and k in that order, whether it be a word or a paragraph.

Edit: Actually it isn't but the you have people putting in underscores or spaces and the whole filtering falls apart again.

Yeah that's the next step now that I have my regexps under control.

Here's a regexp that catches a lot more

code:
$Censor[] = '{f+\s*u+\s*c*\s*k+(\s*i+\s*n+\s*g+)?(\s*y+\s*o*\s*u+)?}i';
If catches gently caress / loving / fuk / gently caress you, with spaces and letter repetition.

But drat, it's almost unreadable. Now I remember why I used to hate regexp :(

Alex007 fucked around with this message at 11:50 on Sep 3, 2008

Leavy
Feb 15, 2003

rufus

Alex007 posted:

Yeah that's the next step now that I have my regexps under control.

Here's a regexp that catches a lot more

code:
$Censor[] = '{f+\s*u+\s*c*\s*k+(\s*i+\s*n+\s*g+)?(\s*y+\s*o*\s*u+)?}i';
If catches gently caress / loving / fuk / gently caress you, with spaces and letter repetition.

But drat, it's almost unreadable. Now I remember why I used to hate regexp :(

Regex Buddy
It's the only piece of "development" software I've bought with my own money because it's such of a wonderful piece of program.

jasonbar
Apr 30, 2005
Apr 29, 2005

Leavy posted:

Regex Buddy
It's the only piece of "development" software I've bought with my own money because it's such of a wonderful piece of program.

A bit off topic, but there is also Regex Coach - which is free. I don't know how it compares to Regex Buddy, but it is a solid helper for testing out expressions quickly.

ijustam
Jun 20, 2005

SOLVED: Just made the array push from inside the class.

So I have this class:

php:
<?
class Course {
    // This class is used for generic classes (such as those with no pre-reqs)
    public $className;
    public $classDept;

    function getDept($connection) {
        $query = "SELECT `Name` FROM `dept` WHERE ID = $this->classDept;";
        $deptResult = mysql_query( $query, $connection ) or die( mysql_error() );
        if (!mysql_num_rows($deptResult)) die();
        while($row = mysql_fetch_array($deptResult, MYSQL_ASSOC)) {
            return $row['Name'];
        }
    }
}
class ComplexCourse extends Course {
    // Tack on some vars for more complex courses
    // What classes MUST be taken prior?
    public $preReq = array();
    // What classes MUST be taken parallel?
    public $coReq = array();
    // What classes invalidate this class?
    public $notReq = array();
}
?>
I query my DB, and if the class has a pre-req, I load it into ComplexCourse. I use an array for the prereqs because it's common for a class to have more than one requirement. For each occurrence of a prereq, I need to tack it into the prereq array. But.. it doesn't work?

php:
<?
array_push($courses[$classesRow['ID']]->preReq,$reqRow['Requires']);
?>
The array is always empty. I do a print_r() or a sizeof() and they're always empty (null or 0 respectively). Is there something special I need to do in order to append an array that's defined inside of a class?

ijustam fucked around with this message at 23:31 on Sep 6, 2008

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am trying to create a PHP applet that will monitor IIS log files (using the tail command) for a specific event and perform an action when that event is found.

I know how to parse a log file when it is written to disk, but how do I do this in such a way that the real time log stream is monitored?

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Agrikk posted:

I am trying to create a PHP applet that will monitor IIS log files (using the tail command) for a specific event and perform an action when that event is found.

I know how to parse a log file when it is written to disk, but how do I do this in such a way that the real time log stream is monitored?

I guess you could do this:
php:
<?
$pipe = popen('tail -opt /path/to/logfile','r');
while(!feof($pipe))
{
    //print stuff here
}
fclose($pipe);
?>
That would never close if tail never died, but I guess if thats what you think you want then whatevs.

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