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
DaTroof
Nov 16, 2000

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

Soks posted:

Edit: This one even works on IE 6.0, amazing. I actually know my way around Java code decently, just never used it for anything web based, so I'm pretty confident I can get the code here to do exactly what I want... with only a little help.

It's JavaScript, not Java. I'm sure you can still figure out how to work with it, but the difference is not trivial.

Adbot
ADBOT LOVES YOU

Dolemite
Jun 30, 2005
I need some help here.

I was assigned a project where I need to fix a sort by feature on a web page. I know what the problem is - a variable is not receiving the input I feed to it.

My question: Anyone know of a good debugger to use with PHP? I need to be able to trace what is happening as the scripts run.

What happens is:

1.) Initial home script runs

2.) Home script loads two product info scripts

3.) The product info scripts load templates and other stuff

This whole thing is a nightmare. I need to be able to track what the script is doing, be able to pause it, etc. I remember when I dabbled in Ruby, Apatana had a sweet debugger you could use to set break points, step through the execution line by line, and see all variables at once at any time.

Does any such equivalent exist for PHP? I'm at my wits end here. This project is so massive that tracking the flow of this is drat near impossible! :(

spiritual bypass
Feb 19, 2008

Grimey Drawer
I like NetBeans and xdebug. You'll need authority over the webserver you're working with, so I recommend running your project locally.

Also, print_r all over the place.

Dolemite
Jun 30, 2005
Just checked out the NetBeans webpage and whoa, this sounds like what I need!

NetBeans download page posted:

You can inspect local variables, set watches, set breakpoints, and evaluate code live

Perfect! Can't wait to try this out! Thanks :)

josh04
Oct 19, 2008


"THE FLASH IS THE REASON
TO RACE TO THE THEATRES"

This title contains sponsored content.

Speaking of which, what's people's opinion around here with regards to netbeans? I'm a big fan, it's so much less effort than eclipse was to set up and use, but I'm told it's less powerful.

EDIT: For PHP development, obviously.

josh04 fucked around with this message at 02:17 on Nov 25, 2009

spiritual bypass
Feb 19, 2008

Grimey Drawer

josh04 posted:

Speaking of which, what's people's opinion around here with regards to netbeans? I'm a big fan, it's so much less effort than eclipse was to set up and use, but I'm told it's less powerful.

EDIT: For PHP development, obviously.

I love NetBeans for PHP, but I find it also does great stuff for Java, C, and Ruby. I don't like to use it as a database frontend, though.

I also love the CSS editor and the JavaScript hints that tell you about browser compatibility.

smith7800
Sep 25, 2004
Is it possible to write a php script on one server that creates files on another server without the use of ftp?

yatagan
Aug 31, 2009

by Ozma

smith7800 posted:

Is it possible to write a php script on one server that creates files on another server without the use of ftp?

Yes, multiple ways. I would use one of these two:

Sockets - basic client/server model with the client requesting the server save the file - http://php.net/manual/en/book.sockets.php

Route through a shared database. Looping script checks a database table for entries, then flags/deletes them and creates the file.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
This isn't a pure PHP question per se, but I hope you guys can help.

Basically, I'm working on a system where users own a variety of different items. For the purpose of this example, I'll make an analogy with a shop: Users can own bread, cars or TVs. The table structure is set out such that each item type exists in two tables: `item` and `useritems` (EG: `types_of_bread`, `userbread`)

That's all gravy, but each item can have a series of modifiers. Essentially, these can either add stats to the item (for example enhance the car's maximum speed) or change the item completely (bread -> toast)

In either case the modification needs two (pseudo)"events" -> "onapply" and potentially "onremove" that fire when the user activates the modification. I am wondering how to implement this. A rather messy solution, would be to put raw PHP in the DB, and eval() it, but that stinks of bad design and potentially horrific debugging.
code:
| ID	| name	| onapply		| onremove		|
-----------------------------------------------------------------
|0	|toast	|<? removeItem(bread, 	| <? //Not applic ?>	|
|	|	|$user); addItem(Toast,	|			|
|	|	|$user);		|			|
|	|	|?>			|			|
|	|	|			|			|
-----------------------------------------------------------------
Then I thought about writing the events in SQL and querying them with PHP.

Does anyone have a better solution to this problem. Ideally, I would love to over-engineer the problem by writing my own language :P

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Fruit Smoothies posted:

This isn't a pure PHP question per se, but I hope you guys can help.

Basically, I'm working on a system where users own a variety of different items. For the purpose of this example, I'll make an analogy with a shop: Users can own bread, cars or TVs. The table structure is set out such that each item type exists in two tables: `item` and `useritems` (EG: `types_of_bread`, `userbread`)

That's all gravy, but each item can have a series of modifiers. Essentially, these can either add stats to the item (for example enhance the car's maximum speed) or change the item completely (bread -> toast)

In either case the modification needs two (pseudo)"events" -> "onapply" and potentially "onremove" that fire when the user activates the modification. I am wondering how to implement this. A rather messy solution, would be to put raw PHP in the DB, and eval() it, but that stinks of bad design and potentially horrific debugging.
code:
| ID	| name	| onapply		| onremove		|
-----------------------------------------------------------------
|0	|toast	|<? removeItem(bread, 	| <? //Not applic ?>	|
|	|	|$user); addItem(Toast,	|			|
|	|	|$user);		|			|
|	|	|?>			|			|
|	|	|			|			|
-----------------------------------------------------------------
Then I thought about writing the events in SQL and querying them with PHP.

Does anyone have a better solution to this problem. Ideally, I would love to over-engineer the problem by writing my own language :P

Serialize can store objects / classes in a db, but I'm not sure that's what you need, because I'm not sure I fully understand your problem.

Does one user change ALL bread to toast, or just his own bread?

spiritual bypass
Feb 19, 2008

Grimey Drawer
I don't know what to tell you about the database itself, but the classes sound like a task for the decorator pattern.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
I guess I missed out an important statement:

The idea is to make the modifications completely DB-only. I can't have any static code in any libraries.

I will look up decorator patterns when I get back from work, and serialize too.

EDIT: I've got home from work and the decorator pattern is what I was using. The trouble is, the decorator functions need to be stored in the DB.

Potentially, I could write my own little interpreter for mylanguage -> SQL - since the decorations only alter the database - but serialize() or the json_encode function aren't really the perfect option, since storing a function as an array still requires a little too much parsing, probably.

There's always bytecode ;-)

Fruit Smoothies fucked around with this message at 23:17 on Nov 28, 2009

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Surely you should be using OOP and having a "bread" class, etc?

Putting PHP in the DB is kind of horrible.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.
It is a bad idea to put code in the DB (as you seem to realize). For your own sanity, and the sanity of others who may need to work with your code someday, please permanently remove that from your list of options.

You should explain a little bit more on the problem you are trying to solve. Whats the big picture? Whats your class structure, why does this need to be in the DB? The examples thus far have been a tad confusing.

If it absolutely must be in the DB perhaps you can use, or develop, some sort of XML rules engine.

code:
<Events>
  <OnApply>
    <RemoveItem>
      <Target>User</Target>
      <Item>Bread</Item>
    </RemoveItem>
    <AddItem>
      <Target>User</Target>
      <Item>Toast</Item>
    </AddItem>
  </OnApply>
  <OnRemove />
</Events>

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Creating your own horrifying xml-based DSL and sticking that in the database is still putting code in the DB.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
Well it doesn't NEED to be in the database per se, but it makes add / removing new modifications a lot easier than creating static code for each modification.

It's for a game which requires a system whereby any item / statistic is able to be modified. There is also future room for development where other users may be able to create their own modification.

I guess an array (JSON) / XML structure is slightly less messy than an eval()'d PHP solution.

Begby
Apr 7, 2005

Light saber? Check. Black boots? Check. Codpiece? Check. He's more machine than kid now.

Fruit Smoothies posted:

Well it doesn't NEED to be in the database per se, but it makes add / removing new modifications a lot easier than creating static code for each modification.

It's for a game which requires a system whereby any item / statistic is able to be modified. There is also future room for development where other users may be able to create their own modification.

I guess an array (JSON) / XML structure is slightly less messy than an eval()'d PHP solution.

You might think its easier to put it into a DB, however what about changes? What you if you have 2000 items that all call the RemoveItem() function. Then lets say you decide that you have to add a third argument to that function? Now you are going to have to edit 2000 database items and modify that function somehow. Sounds like a shitstorm. Not to mention the enourmous security holes that could be present there, especially if users can make changes.

Same thing as storing XML rules in a DB as Plorkyeran stated. What if your XML structure changes? Its not like you can just apply some simple transform to a bunch of files.

Really your database should be just for storing data, not any kind of logic or anything like that. That should all be outside the db. If I were you I would hard code all your classes and functionality, get your game working, then try to tackle this problem after the fact, when you really need this feature. Like its a good idea to keep in the back of your mind that you want users to be able to edit this stuff, but if its not a requirement for v1.0, then don't waste your time on it until you really need it.

If you have logic stuff in database records, you are going to regret it. Its going to be like that one fat girl you brought home from the bar and woke up next to and wish you could forget, but then you keep seeing her around town and every time it makes you cringe.

Personally I would rather create a bread class and a toast class than have to deal with all these headaches.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums

Fruit Smoothies posted:

Well it doesn't NEED to be in the database per se, but it makes add / removing new modifications a lot easier than creating static code for each modification.

It's for a game which requires a system whereby any item / statistic is able to be modified. There is also future room for development where other users may be able to create their own modification.

I guess an array (JSON) / XML structure is slightly less messy than an eval()'d PHP solution.

Then create some sort of event class and have a bunch of preset things that they can do. You can't have users modifying PHP code. Full stop. Eval-ing PHP from the database is a horrific idea.

If the events are within the game, then perhaps your own in-game scripting language type thing would suffice, as it would create an abstraction and prevent players touching the PHP. However, unless you knew what you were doing, I'd very much recommend that you avoid giving users too much power, especially in PHP.

Why is modifying static code difficult if you have it version controlled and deployed from a SCM?

Also, read into abstract classes, etc.

So you could have class bread extends food, or class spoon extends weapon or whatnot.

Fruit Smoothies
Mar 28, 2004

The bat with a ZING
I would never be foolish enough to let the users have access to the raw PHP. I am waiting for a fellow goon to do the artwork, so I thought I might-as-well get the database as perfect as I can in v1.

As for the function params changing, this isn't likely to happen. The DB fields are going to be the inner code for a function, and thus any parameter changes will be done in the hard code.

As for the solution, I think an array based structure is a good idea. XML is a little too long-winded really, so I think I'll just go with array=>JSON

code:
array = (
	[remove][ItemID][NUM] = $n
	[add][ItemID][NUM] = $n
)
I don't know how to handle if statments, but then again I could make it so any conditions that aren't met in the array force abort.

I hope you don't slate me too much for this choice.

spiritual bypass
Feb 19, 2008

Grimey Drawer
You could use the string-as-function feature to call your PHP code based on a function name stored in the database.

I realize that's horrible, but it's less horrible than storing an entire function there.

Parker Lewis
Jan 4, 2006

Can't Lose


josh04 posted:

Speaking of which, what's people's opinion around here with regards to netbeans? I'm a big fan, it's so much less effort than eclipse was to set up and use, but I'm told it's less powerful.

EDIT: For PHP development, obviously.

I'm liking it a lot on my Mac for larger scale projects. Being able to type $myObject-> and have it pop up a list of all the methods (with PHPDoc comments included), even when the class is defined by a file in a separate directory, is pretty sweet.

I always had a distaste for Java apps and NetBeans seems a little overkill/bloated when working on smaller one-off scripts so I still find myself using TextMate when I need to do something quick like make a minor change to a remote file over SFTP.

I used TextMate as my only editor for a long time but now I find that I miss a lot of the code hinting/debugging stuff from a real IDE like NetBeans whenever I try and work on those sorts of projects in TextMate. It's sort of jarring having two main editors with all different shortcuts and navigation keys, though, so I may just end up sticking to TextMate and missing out on some of the niceties from NetBeans.

Quick tip for fellow Mac users, you can get Quartz font smoothing and make text look a whole lot better in NetBeans by adding

code:
-J-Dapple.awt.graphics.UseQuartz=true
to the netbeans_default_options in /Applications/NetBeans/NetBeans <version>.app/Contents/Resources/NetBeans/etc/netbeans.conf

Parker Lewis fucked around with this message at 22:07 on Nov 30, 2009

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 am in the market for a new job. I know PHP and MySQL very very well. And that's it. This seems to be limiting my opportunities. What do folks recommend as another language to learn while I try to find a PHP/MySQL job?

Fruit Smoothies
Mar 28, 2004

The bat with a ZING

rt4 posted:

You could use the string-as-function feature to call your PHP code based on a function name stored in the database.

I realize that's horrible, but it's less horrible than storing an entire function there.

I did contemplate call-user-function() but I think I'm happy with my array structure.

yatagan
Aug 31, 2009

by Ozma

Golbez posted:

I am in the market for a new job. I know PHP and MySQL very very well. And that's it. This seems to be limiting my opportunities. What do folks recommend as another language to learn while I try to find a PHP/MySQL job?

Something heavily object oriented like Java, C++, or a .NET language.

Munkeymon
Aug 14, 2003

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



If anyone else uses Notepad++ for your PHP development, you might want to avoid 5.6

Matching brace highlighting stopped working consistently for me after I installed it.

Small White Dragon
Nov 23, 2007

No relation.
What's the difference between MYSQLI_USE_RESULT and MYSQLI_STORE_RESULT?

The documentation for mysqli_query doesn't explain the difference between them (and when/why one should be used over another), and most places seem to just copy from there.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Here's a link that seems to have a good explanation on the differences.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums

Fruit Smoothies posted:

I would never be foolish enough to let the users have access to the raw PHP. I am waiting for a fellow goon to do the artwork, so I thought I might-as-well get the database as perfect as I can in v1.

As for the function params changing, this isn't likely to happen. The DB fields are going to be the inner code for a function, and thus any parameter changes will be done in the hard code.

As for the solution, I think an array based structure is a good idea. XML is a little too long-winded really, so I think I'll just go with array=>JSON

code:
array = (
	[remove][ItemID][NUM] = $n
	[add][ItemID][NUM] = $n
)
I don't know how to handle if statments, but then again I could make it so any conditions that aren't met in the array force abort.

I hope you don't slate me too much for this choice.

I still fail to see why your code needs to be in the DB as opposed to in a class.

every
Apr 24, 2008

Hey everyone. I'm a PHP beginner and I'm trying to figure out how to do a "Read More" link in an article. So I'm pulling in an article from mySQL, and after some length, but not in the middle of a word or anything, I'd like to have it say "Read More" with a link onward. How is this done??

Sorry to ask such a rudimentary question on here, but you can imagine googling "php 'read more'" kinda gives a mixed bag of results. Thanks!

Supervillin
Feb 6, 2005

Pillbug

growing posted:

Hey everyone. I'm a PHP beginner and I'm trying to figure out how to do a "Read More" link in an article. So I'm pulling in an article from mySQL, and after some length, but not in the middle of a word or anything, I'd like to have it say "Read More" with a link onward. How is this done??

Sorry to ask such a rudimentary question on here, but you can imagine googling "php 'read more'" kinda gives a mixed bag of results. Thanks!

That's cause you should search for php "read more link" :)

http://programming-in-php.blogspot.com/2009/10/function-to-show-read-more-link-in-php.html

That one truncates after x chars, then backs up to the nearest space so you avoid cutting a word in half.

every
Apr 24, 2008

Exactly what I was looking for. Thank you.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
You could also do this using Javascript so the read more link doesn't reload the page, just replaces the contents of the DIV with the response from request that fetches the rest of the article in HTML.

every
Apr 24, 2008

That's good to note, but all I need it to do for now is link to the next page. On another note, what am I doing wrong here?? How can I get the form action to grab the city id # from the function?

code:

<form name="search_rentals" action=a href="<? 'pages/properties/69.php?cid=' . $data[id]?>">
    <div class="search_lite">
        <h2>Select a City</h2>
    </div>
    <div class="search_lite">
        <div style="float:left;"><?=city()?></div>
        <div style="clear:both;"></div>
        <input type="hidden" name="ms_search_home" id="ms_search_home" value="ms_search_home" />
        <input type="hidden" name="city_id" id="city_id" value="0" />
        <input type="image" src="/filebin/images/search_rentals.jpg" name="search_rentals" class="rentals_center_btn" />
    </div>
</form>
    <?
    function city() {
        $sql = "SELECT * FROM city WHERE hidden != 'Yes' ORDER BY sequence ASC";
        if ($res = mysql_query($sql)) {
            $return = '<select name="city" id="city" class="small_input">';
            $return .= '<option name="city" value="0">Select a City</option>';
            while ($data = mysql_fetch_array($res)) {
                $return .= '<option name="city" value="'.$data[id].'">'.stripslashes($data[name]).'</option>';
            }
            $return .= '</select>';
        }
        return $return;
    }
    ?>

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Aren't you just missing the word "echo"?

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
OK, I'm avoiding work so here's a possible rewrite.

code:
<form name="search_rentals" action="pages/properties/69.php" method="GET"><!-- or POST, whatever works for you -->
<!-- I hope $data is defined somewhere previous to this -->
    <input type="hidden" name="cid" value="<?php echo $data['id']; ?>" /> 
    <input type="hidden" name="ms_search_home" value="ms_search_home" /> //??
    <input type="hidden" name="city_id" id="city_id" value="0" />
<!-- you seem to have 'cid', 'city', and 'city_id' all in here and I suspect they're all the same thing. -->
    <div class="search_lite">
        <h2>Select a City</h2>
        <div style="float:left;"><?php echo city($data['id']); ?></div> <!-- float necessary? should go in CSS file if it is -->
        <div style="clear:both;"></div> <!-- I'd just take out these divs and use a <br /> -->
        <input type="image" src="/filebin/images/search_rentals.jpg" name="search_rentals" class="rentals_center_btn" />
    </div>
</form>
<?php
    function city($currentcity) {
// you probably want to use a boolean for `hidden` in the DB, but maybe you don't have control of it? 
// Also avoid "SELECT *" if possible.
        $sql = "SELECT `id`, `name` FROM `city` WHERE `hidden` != 'Yes' ORDER BY `sequence` ASC"; 
        if ($res = mysql_query($sql)) {
            $return = '<select name="city" id="city" class="small_input">'; // are you using the id here?
            $return .= '<option value="0" disabled="disabled">Select a City</option>';
            while ($data = mysql_fetch_array($res)) {
                $selected='';
                if($currentcity==$data['id']) $selected=' selected="selected"';
// you probably don't need stripslashes() here if the data in the DB is correct. You might want htmlspecialchars() though.
                $return .= '<option name="city" value="'.$data['id'].'"'.$selected.'>'.stripslashes($data['name']).'</option>'; 
            }
            $return .= '</select>';
        }else{
            die("Query failed! ".mysql_error());
        }
        return $return;
    }
?>
ed: don't use "name" on <option>s

Tad Naff fucked around with this message at 16:51 on Dec 8, 2009

every
Apr 24, 2008

Actually, that whole thing was monumentally wrong.

Rat Supremacy
Jul 15, 2007

The custom title is an image and/or line of text that appears below your name in the forums
Why do you have functions in your loving HTML seriously what the gently caress?

You should probably look into organising your code before you write another line. HTML goes in templates (with minimal PHP for things like loops and variables), functions go in logically grouped function files that are included (if you're going with a procedural approach for some reason). You do not use the ancient mysql extension, you use PDO because it is sane and has nice prepared statements. Being a beginner is no excuse now that there is such emphasis on writing clean, maintainable code.

Rat Supremacy fucked around with this message at 13:43 on Dec 8, 2009

DirtyDaub
Jul 26, 2007
Keeping it real for generations at a time
I need some help.

Im overhauling my company's website, and i've been re-making everything from scratch so far. The only thing I don't have the knowledge to re-make is the store locator, cause its written in php (of which i have no base of understanding). So right now Im just linking the old store locator into the new site, which is fine temporarily.

The problem is, I cant figure out how to style the old locator to make it match the new site because it uses some style template written in XTPL, and I cant find any documentation about it.

So, is there someway around this? Or do I have to salvage the old data, make a new one, and teach myself php in the process?

This is the site:

old: https://www.bergfurniture.com

new: https://www.bergfurniture.com/new_site.asp

store locator: https://www.bergfurniture.com/storelocator/store_locator.php

McGlockenshire
Dec 16, 2005

GOLLOCKS!

DirtyDaub posted:

The problem is, I cant figure out how to style the old locator to make it match the new site because it uses some style template written in XTPL, and I cant find any documentation about it.

I hate to be that guy, but it took me two seconds with Google to find that XTPL refers to PHP XTemplate. That's a link to the docs.

Adbot
ADBOT LOVES YOU

DirtyDaub
Jul 26, 2007
Keeping it real for generations at a time
haha, yeah my bad. I actually did find that site a while ago but couldn't really understand what any of it meant. After staring at the examples for a little bit longer I started the get it. The main problem was I couldn't figure out how to edit the xtpl file (dreamweaver doesnt recognize it), but I played around with it and found out I can open it up and edit it in notepad.

problem solved.

Thanks for the help.

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