« first day (818 days earlier)      last day (4129 days later) » 

2:00 PM
is serverside validation really necessary for a authenticate php application i.e use can only enter acess form if he is registered only
 
user652649
edit: so @DaveRandom will smoke 10 cigs instead of 40 today
 
@igorw Right, forgot about $that = $this, I'm so used to doing it anyway (I write a lot of JS) that I forgot you don't have to in PHP5.4
 
user652649
$that = $this ahah
 
user652649
i use
 
user652649
var _this = this;
 
2:01 PM
@DaveRandom Aha I understand, sorry was just confused
 
there is no chance of spoofed form also
 
user652649
@user1914940 seriously if you want to free daverandom i will try to help you
 
@wes Well yes I really feel bad because he helped and still helps me so much, I already feel bad..
 
@DaveRandom This happened to me once. An ajax call to a php page caused a 500 server error. But accessing the php page via the browser gave the correct response. I still wonder what the problem was then though. I solved it by just renaming the php function. Anything like this ever occur to ya? If yes, mind sharing the reason.
 
downloading at 11 MB/s is awesome :P
 
2:03 PM
If not, never mind.
 
can any one tell me because i have lot of fields to validate on serverside
 
user652649
@user1914940 so gimme the code!
 
Just a sec Ill make pastebin
 
@user1914940 OK so now you've done that, you need to get the ID of the database record in JS. Now because of the way jQuery (and generally Javascript) works, the function you passed to .click() will have it's magic this variable set to the element of the button that was clicked. The id="" value can be got via this.id.
 
@ShyamK can you help me
 
2:08 PM
To avoid collisions with other element ids, I added a prefix of solveit-button- - so you'll need to split the actual number of the ID off that string because that's all we need to send back to the server. The reason I used the - delimiter was to make it easy to split the string to an array and just get the last element from it. Do you know how to do this in Javascript?
 
@wes Here, hope its good: pastebin.com/BDhJTEtV
@DaveRandom Uhh nope, sorry.
 
user652649
@DaveRandom do you like jquery? read: jquery's syntax/way it is designed?
 
user652649
@user1914940 i'm reading
 
@SivagopalManpragada For eg. say there is a date field and the registered user enters his name in that field for fun.
He has javascript turned off in his browser, so no client side validation will work. So if there was no server side validation, you would save that value to the db, right? Now is this what you want?
 
@ShyamK Probably the handling of a request header, but it's pretty much impossible to say without seeing it happening. I would debug that by: looking at the server error log (always first port of call for 5xx errors), inspecting the requests ajax vs straight browser request and looking for the differences, and then working through the code based on those variables.
 
user652649
2:10 PM
@user1914940 first of all... the content you display to user, in the browser's area... is always inside <body> HERE </body></html>
 
user652649
then cut this: </body></html> and paste after your content
 
@wes Not really, no. Actually style wise it's not too bad (considering it's hindered by being based on JS) but it's so disasterously inefficient that I avoid it wherever possible.
Although I do tend to do quick dev in jQ and rewrite to vanilla later when I need to get things working quickly.
 
user652649
i'm a java-ish syntax then i dont like it
 
Same goes for all JS frameworks really.
 
user652649
but also i don't like how method chain works
 
2:12 PM
Don't chain methods then.
Good rule of thumb anyway
Only time I ever do it is with DOM, because of the ridiculous verboseness of the API
 
user652649
and i don't like it because it is async and sync at the same time... .dosomething().then().bla()
 
user652649
@DaveRandom dom4 is a lot more compact
 
I cant seem to be able to echo the $id and it doesnt say any error :S
 
That can be a bit brain melting, what I really don't like about that is that there is no way to force an async procedure to be sync.
 
@DaveRandom I have never really had to look at the server logs. But I will have to some day. So I better read up on that.
 
2:15 PM
It's a real PITA when you want to return a value instead of calling a callback. it's not very often, but sometimes a callback just makes no sense.
 
user652649
but thats sad because i'm devloping a dom4 compatible framework and i was about to asking you help, if you are interested xD
 
user652649
@user1914940 sorry... introduce me to what you are trying to do here
 
@ShyamK 5xx is server error. Every 5xx code (in a sane server) is accompanied by a message in the server logs that gives you at least a vague clue what the root cause is
@user1914940 Sorry, where? In the id you mean?
 
@wes Ohh sorry :) The code inside ajax.php works good, but now I would like to make it run when user clicks a button.
@DaveRandom The one from index.php so that I can then use it (if thats the way you ment)
 
user652649
oh.. then jquery.. i don't use jquery lol
 
2:18 PM
@wes I'm not saying JS frameworks have to be horrible, they just often are. In fact my only real gripe with them is that they usually try and do too much, and add too much sugar, which makes them very very inefficient. Whenever I see $(this) in the wild I die a little inside
@user1914940 OK, can you show the code you've got at the moment for index.php (the bit that doesn't work)?
 
user652649
@DaveRandom my framework's design doesn't have that shit ,yeah.. i hate that too...
 
@DaveRandom Ohh ok it works now. So what is now left, sorry? At the momment button does nothing
 
@user1914940 OK, so instead of alert("testing");, see what happens when you do alert(this.id);
 
Tried that before :) Nothing really happens
 
@wes OK well whatever you're doing stick on GitHub, I always like to nosy through people's code :-)
@user1914940 So no alert?
 
2:21 PM
Nothing at all.
 
any console error?
 
OK well you probably have an error in the JS somewhere then. What browser do you use?
 
Chrome
 
user652649
@user1914940 you have to set up a xmlhttprequest object on click event
 
user652649
right? an ajax call
 
2:22 PM
Morning folks
 
@user1914940 Good. Press F12, change to the "console" tab at the bottom and press a button - see if you get an error message
 
user652649
@user1914940 you wrote: $('.solveit-button').click(function() {
 
user652649
that selects nothing because you probably have
 
Nothing, ther eis only ">" in that console
 
user652649
class="solveit-button-33"
 
user652649
2:24 PM
<td><input type="button" class="solveit-button solveit-button-<?php echo $id; ?>" value="Solved" /></td> change with this
 
@wes solveit-button-<?php echo $id; ?> should be in an id to make life easier
(seeing as how it's a database id anyway)
@user1914940 Can you show the generated HTML source on a pastebin please? (so just copy/paste the contents of view source)
I just feel the need to say at this point that Sage Line 50 is an awful piece of software.
 
user652649
@DaveRandom it would be better that @user1914940 learn first "web1.0" forms, instead of ajax calls?
 
also console.log('some message'); is better than alert('some message');
alert(); pauses JS execution, until you click OK
 
Here is the source code: pastebin.com/7VtmmPyB
 
@wes We explicitly don't want to use forms (no page refresh) I think from what he has said he has a basic handle on forms. Although actually you do raise a good point that I missed when explaining how ajax works that might have made it easier to understand
@user1914940 Where did that <br /> come from in that id? I suspect that's you problem. It shouldn't be there.
 
user652649
2:29 PM
:holymaccheroni: <input type="button" class="solveit-button-2<br />" value="Solved" />
 
Oh wait no, you've actually replaced the class with the id.
<td><input type="button" class="solveit-button" id="solveit-button-<?php echo $id; ?>" value="Solved" /></td>
@user1914940 ^^ that's what I meant
 
@wes lol
 
@wes -__________________-
 
@DaveRandom Ok using this line:

<input type="button" class="solveit-button" id="solveit-button-<?php echo $id; ?>" value="Solved" />

Now I get alert message: solveit-button-3<br />
 
user652649
now lets party!
 
2:31 PM
@user1914940 Wait, what? Where's that <br> coming from?
 
user652649
<?php echo $solved = $array['solved'].'<br />';?> from that @DaveRandom
 
I have no idea either :S
 
user652649
<?php echo ($solved = $array['solved']) . '<br />';?>
 
Wtf lol missed that, is that in a td?
 
user652649
but isn't really needed <br> here anyway
 
2:32 PM
@user1914940 Remove those <br>s. <br> has no place in modern HTML, anywhere.
 
user652649
then @user1914940 remove all . '<br />'
 
user652649
including the dot
 
Actually those assignments are pointless as well.
Might as well just use $array['solved'] etc throughout
 
user652649
yes xD
 
Ohh yes now it works, I removed all <br />s from while loop
 
2:34 PM
OK so now when you press the button, you see an alert of solveit-button-<id>?
 
yes.
 
user652649
@user1914940 when you do $bla = $bam; you are coping/referencing the value of $bam into $bla
 
(where <id> is the right id for the button)
 
each button gets correct ID
yes, :)
 
user652649
in your case you don't need that, just <?php echo $array['text']; ?>
 
2:35 PM
Ohh I see, thanks :D
 
user652649
@user1914940 also try to write <?=$array['text']?> that is the shorter way to write <?php echo $array['text']; ?> (but depending by how you configured php, it may not work)
 
OK, you're most of the way there. First I suggest you split the number from the rest of the string using the mechanism I suggested before (split to array on - and get the last element). Go have a quick google and try and work out how to do that yourself (it's not hard), should be easy to find.
 
@wes its bad practice to use short tags
 
user652649
@ShyamK no more in php 5.3
 
@ShyamK <?= no longer requires short tags as of 5.4.0
@wes 5.4 ;-)
 
user652649
2:37 PM
ok 5.4 xD
 
@DaveRandom Do you mean with explode?
 
Still can't really use it in the real world yet though, until 5.2 is properly dead, never mind 5.3
@user1914940 Basically yes, the JS equivalent is called something else (it's a very logical name though)
 
user652649
@DaveRandom off topic question: do you undrstand why "abstract static methods" aren't still available in php, since now late state bindings exist?
 
If I google "js explode" I get the right answer in the first result
 
brokenstring
 
2:40 PM
@wes No. I have been annoyed by that before, but since then I'm finding it less and less possible to work out why you would ever use a static method in PHP.
 
> <?= no longer requires short tags
requires short tags?? what do you mean?
 
static variables have a point to them, methods do not
@ShyamK As in short_open_tag does not have to be enabled in order for <?= to work
 
user652649
@user1914940 no offense but you're trying to skip a lot of steps.. you are trying to learn html+php+js+mysql at the same time... you know that is nearly impossible?
 
(since 5.4)
 
@DaveRandom ahh... okay...
 
2:41 PM
@wes Yes I know, I am only learning html css php and sql but I have to deal with js and other stuff here, thats why I ask a lot, I would like to finish this now :)
 
user652649
@ShyamK that they work independently by how you set the short_open_tags pref
 
Right, brb a few minutes, need to actually concentrate on something for work
 
@wes yes. Dave cleared that up
 
user652649
@ShyamK and it is a good thing. f**k xml syntax! xD
 
0
A: Regex lookahead more than one element

shiplu.mokadd.imThis conditional sub-pattern will do it. (?(?=a)(a)([def])([ghi])|([bc])([def])([gh])) Here is a sample demo that show it works.

 
user652649
2:43 PM
@user1914940 what are you trying to explode/split ?
 
@wes ya... I prefer json to xml... stupid xml...
 
@wes Well if I heard correct I need to split number from everything else ( solveit-button-3 )
 
user652649
@user1914940 ok, you don't need that... paste the <input type="button" that you have now
 
<input type="button" class="solveit-button" id="solveit-button-<?php echo $id; ?>" value="Solved" />
 
user652649
change it to <input type="button" class="solveit-button" data-solvebutton="<?php echo $id; ?>" value="Solved">
 
2:45 PM
why?
 
Now I get nothing as a result of onclick alert
 
user652649
wait!
 
Sorry :)
 
Is there seriously no HTML chat room?
 
user652649
paste the jquery code that you have now
 
2:47 PM
<script type="text/javascript">
    $(document).ready(function() {
        $('.solveit-button').click(function() {
            alert(this.id);
        });
    });
</script>
 
Ah, there is a CSS room, but its last activity was 4 days ago.
 
user652649
@user1914940 change the click handler with
 
user652649
$('.solveit-button').click(function() {
alert(this.getAttribute("data-solvebutton"));
});
 
Good morning
 
Yep, now it works.
 
2:49 PM
@wes instead isn't alert(this.id.split(solveit-button-')[1]);better?
 
user652649
@ShyamK how a split can be better than a plain attribute? xD
 
user652649
@user1914940 now what you need to do? send the ajax call?
 
@wes Well yes, I need to connect it to ajax.php somehow now because code in ajax.php already works
 
Hi guys.
 
user652649
@user1914940 do you know how ajax works?
 
2:53 PM
@wes Well...not really just had about 5min of read about it
 
I have an array, that is outputting characters in UTF-8. However, as the array is not outputting as I really want it to, I'm reconverting some of the values into keys, and reassigning the arrays to the new keys (old values).

However, it is cutting my characters just before assigning them to a new array. This is my code:

foreach ($regional as $k => $v)
{

$id = $regional[$k]['id'];
$name = $regional[$k]['name'];
$regional[$id] = $name;
unset($regional[$k]);
}
 
@wes you made him change to this data-solvebutton="<?php echo $id; ?>". Did not see that. My bad
 
If i make an exit right after $name it will show me the name correct. However if i make an exit right after $regional[$id] it cut my characters.
 
user652649
in practice an ajax call (also known as xmlhttprequest) is nearly equivalent to what you do when you open a webpage. it is a "hidden" web client
 
user652649
from the result of the call you can get the page content that you have requested
 
user652649
2:57 PM
in your case ajax.php
 
user652649
paste me the code of ajax.php
 
<?php
ini_set('display_errors', 1); error_reporting(~0);
require("db_connec.php");

// Fetch and sanitise the data
  $id = (int) $_REQUEST['id'];

  // Run the query
  $success = mysql_query("UPDATE reklamacije SET reseno='1' WHERE id=$id");

  // Prepare the result object
  $result = new stdClass;
  $result->success = $success;
  if (!$success) {
    $result->error = mysql_error();
  }

  // Output the result as JSON
  echo json_encode($result);
 
<?php echo " Hello everey one"; ?>
 
user652649
@user1914940 ok.. you don't have actually sanitized any data.. you know that? xD
 
user652649
btw... wait
 
3:04 PM
Sorry, what do you mean?
 
user652649
 
Ok
Is there anything else to add? As of now its not working
 
user652649
$success = mysql_query("UPDATE reklamacije SET reseno='1' WHERE id='" . mysql_real_escape_string($id) . "'");
 
user652649
i don't know... paste both pages code
 
user652649
@user1914940 oops
 
user652649
3:14 PM
change this line url: 'ajax.php?id=' + idToGet,
 
user652649
i missed a "="
 
Also I fixed that last = you told me
 
user652649
it is working?
 
Nope, nothing happens when button is clicked
 
line 15 url: 'ajax.php?id' + idToGet, change it to url: 'ajax.php?id=' + idToGet
there is a missing =
 
user652649
3:18 PM
yes @ShyamK i've already noticed that xD
 
user652649
my bad
 
Tried that still nothing happens
 
I was replying to him... not you, wes
 
user652649
press f12 @user1914940
 
user652649
do you see any error in the console?
 
3:19 PM
Yep when I click button nothing shows in console
No, just >
 
user652649
reload the page after you opened the console
 
user652649
then try to click
 
Nothing at all
just >
 
user652649
 
user652649
@ShyamK @ShyamK yes but that missing = was my mistake xD
 
3:22 PM
Nope, nothing works now even button
it worked before tho
 
user652649
@user1914940 repaste the entire page
 
@ircmaxell good morning
Any progress getting your reddit account back?
 
@wes Cant use pastebin atm:

<?php
ini_set('display_errors', 1); error_reporting(~0);
require("db_connec.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    $('.solveit-button').click(function() {
            var idToGet = this.getAttribute("data-solvebutton");
 
= is still missing
 
user652649
FFFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUU
 
user652649
3:25 PM
@ShyamK yes, that ^
 
user652649
                        url: 'ajax.php?id=' + idToGet,
 
hi all
 
Ok fixed, still nothing
 
@Dezigo hi
 
user652649
@user1914940 even in the console?
 
3:28 PM
@wes nope
 
user652649
@user1914940 but! you removed the $.ready part
 
From where? :O
 
@wes shouldn't that throw an error? cos the dom was not ready.
 
user652649
 
removal of the .ready part I mean
 
user652649
3:31 PM
@ShyamK no, because $('.solveblabla') returns an empty array
 
Ohh ok yes, now I get success:true if I click a button
 
@wes oh... right jQuery... yuck...
 
user652649
@ShyamK damn jquery!
 
user652649
@user1914940 now you are getting the ajax.php's content what you need to do after that?
 
3:33 PM
I only get success:true now
Now I need to run that query when I press on button
to chenge that item's value to 1
 
user652649
what query? the one inside ajax.php? you are already running it... see your db, the value should be changed
 
@user1914940 Also create some kind of notification for the user, that his click was successful or not.
 
@MikeB Not yet, no reply
 
@wes Well yes but how can I run it now
 
user652649
@user1914940 you mean run it again?
 
3:39 PM
I never ran it yet
 
did the value change?
 
user652649
when you visit ajax.php you are running it
 
Yes, but I want to run it as soon as they press button
 
click the button... that will 'visit' the ajax.php page
 
Ohhh yes it works :D:D
 
user652649
3:41 PM
@user1914940 when you click button and you see success=true, you had ran that query
 
@wes Ohh yes it works :) Thanks man
 
user652649
@user1914940 paste both pages code again... i will help you to improve some things
 
@wes @ShyamK @DaveRandom Yo guys you dont know how thankfull I am for all your help :) I got it finally working now. I will be going now and be back on monday ok? :)
 
Happy to help :D
 
No I mean really...thank you very much guys :)
 
user652649
3:43 PM
you are welcome... do we deserve a pizza? xD
 
You deserve a Beer and a pizza ;)
 
user652649
ahah yeah
 
Which is a great combo ;)
 
user652649
as an italian and an alcoholic, I can only approve
 
Haha ;) We are neighbours then :D I am from SLO
Ok, now I will be going just wanted to say thanks again for all the help you guys are amazing :)
 
user652649
3:47 PM
we are really close because i'm currently 400km from slovenia!
 
user652649
xD
 
Ohh :) Cool
 
Ok now Im really going, thanks again and all have a wonderful weekend, take care ;)
 
user652649
bye!
 
3:51 PM
@wes lol...
 
user652649
@NullPointer what
 
@wes user1914940 really wanted to thank you ..
 
@Pekka웃 proper tags please or the backlog/plugin won't pick it up
 
Woohoo! It took quite a bit of work, but I've got my system set up so I can run my physically installed Linux from VirtualBox :D
 
3:53 PM
hello again @all
 
@Pekka웃 its [tag: here without any space ]
 
@DaveRandom fixed. You have a plugin that collects these things? cooooool
Shit that is cool. Nice work @Gordon
 
user652649
@NullPointer he should have to thank daverandom only xD
 
3:56 PM
I should probably do a write-up on how I did it, considering there was some random experimentation and educated guessing involved where I couldn't find any resource on the web about the process
 
^^ needs no star, already pinned ;-)
 
Is that what those other star icons are?
:)
 
@Sharlike Stars are meant for interesting/helpful chat messages
 
I mean the difference between the hollow and filled-in stars on the sidebar
 
Yeh, hollow ones are "pinned", they stay there for 2 weeks
lol who starred that? :-P
 
3:58 PM
@Sharlike Outlined stars are pinned
 
Got it, thanks guys
 
They will remain at the top of the star list even if it has no stars
 
user652649
 
love you .. @NullPointer for that project link ... you are aewsome ..
 
user652649
this is something that would have been better had not learned
 
user652649
@NullPointer
 
@wes ignore some default avatar people
 
>:C
 
user895378
@NullPointer especially that @PeeHaa guy.
 
@rdlowrey lol...
 
user652649
4:04 PM
i will watch default avatars while smoking weed
 
@rdlowrey Yeh and that @NikiC. What an idiot that guy is.
:-P
 
@rdlowrey lolz
I saw that
 
user895378
@DaveRandom For realz. We should just go ahead and put both of them on the tiny avatar list.
 
user652649
 
@nullpointer ok i have changed my avatar
 
4:07 PM
I'm going to call you apple man
 
@Sharlike i am not man ... idiot
 
you are apple?
 
lol @ the irony of misspelling the word "idiot"
 
user652649
lol
 
4:10 PM
@Jocelyn Y U NO CLOSE VOTE?
 
@DaveRandom lol
 
@DaveRandom no more close votes available. No fun :-(
 
@Jocelyn already? My, you have been busy today
 
@Jocelyn yey ... i have 40 yet ...
 
@NullPointer I am sure you can find easily where to use all of them
 
@wes ..?
 
4:14 PM
No commas and no underscores IIRC
 
user652649
 
4:17 PM
There is a sandbox for this you know...
 
oh snap, busted!
 
@NullPointer How did you do that? Backslash escape?
 
[tag:cv pls]
 
nup.... i have just tried [tag: ッ-웃-pls ]
 
user652649
4:18 PM
 
‌ ‌ ▲
▲‌ ▲
 
madness
 
@Neal I really loved this solution btw: stackoverflow.com/questions/8476225/…
 
My thoughts entirely
 
4:20 PM
while($madness){php = sandbox;}
 
Gave it a +1 yesterday for being so brilliant :D
 
@MarioS o rly? That is quite ugly lol
 
Needs MOAR looping
 
@DaveRandom Yup, one loop can solve it.
 
4:21 PM
@MarioS haha What made it "brilliant"?
 
@Neal no that piece of code actually made sense in my head === brilliant
 
 
user652649
 
@Jocelyn And about half of the questions in the PHP tag. Failing to check for failure returns accounts for way more questions than it should.
 
4:24 PM
Btw I have been thinking about this for a while, but when I see cv-pls tags, I imagine a black person saying b*tch please
 
racist.
 
@Jocelyn I don't understand why people make stuff up, when you can use one simple line of code to resize image... convert big.jpg -size 300x small.jpg
 
:-P
 
@DaveRandom You are right, but still I chuckle when I see the cv's :D
 
user652649
guys how do you use to represent in php rows of a database?
 
user652649
4:26 PM
for example table user/row user -> class User with singleton for each unique user.
 
user652649
i don't know how to do with extended table (JOINs) because i want to do my best to reuse rows
 
user652649
for example table userdetails (FROM users JOIN usersdetails ON..)
 
Why are they even separate tables in the first place?
 
user652649
in this case what i should do in your opinion? i want to re-use the same fetch for both classes User and UserDetails
 
user652649
@DaveRandom it is just an example
 
4:30 PM
But yeh, an array of User objects. If you want to use the same fetch to create multiple objects then you can, you just have to create both of them. But does it really make design sense to do that? If it's just and example it's a bad one...
 
user652649
ok.. i will try again, tables: users, pages... a user can own a one single page, but page can be fetched also without referencing to the user that created it
 
OK but that's two separate queries
 
user652649
in this case i don't want to use the same table for both users and relative pages, because page is optional for some users
 
So it's two separate object creation routines
 
user652649
@DaveRandom no, sometimes i query users joining their pages
 
4:35 PM
Hello, does anyone know how twitter gets tweets. Is it with ajax or just normal server side code?
 
Yes, but when you just want to get the pages it's a different query, that's what I meant - I don't mean a separate query for each table
@SaffronHarris What do you mean "gets" them?
If you mean what I think you do then ajax
 
user652649
... sorry for my english... i'm trying again... sometimes i use SELECT .. FROM users WHERE .., sometimes i use SELECT .. from pages WHERE .., and also i use SELECT users JOIN pages ON ...
 
user652649
now, i want to do my best to avoid the third query, for example, if i already had both users and pages link
 
get's the feed from the database. I was just wondering how you can get such large amount of data using ajax
 
@wes Yeh, right, so you can't expect some routine to be able to genericise that and automagically create the correct object structure, you have to get the results back into the place where you ran the query and create the structure "manually" depending on which query you ran.
 
user652649
4:38 PM
and i don't know how to design this, even if it is a good idea... a those select aren't slow at all
 
Because the returned data structure will be different, so the mapping routine needs to be different.
@SaffronHarris It's not a large amount of data. Couple of KBs per request at most.
 
user652649
@DaveRandom yes... if i can do this, you think it is a good idea? or it will be better avoid any type of data reuse across multiple classes/objects?
 
Really, ok when you receive a json encoded data from a php script, how do you loop through the data? (You know, as we use foreach in php). Or is there anyway to still display it using php?
 
user652649
i'm not sure but smells like a lot of code that is supposed to optimize something, but that actually doesn't improve performances
 
@wes Well what you are suggesting there is that you are potentially running more than one of the above user/page queries per page load - why would you do that? Once you have the data you have it, no need to query the DB again
 
user652649
4:44 PM
@DaveRandom yes, of course... but here is different. i'm talking about reusing data, not queries, across multiple classes
 
user652649
if(!isset(static::$users[$userid])) run the query;
 
user652649
return static::$users[$userid];
 
user652649
this is fine, but i'm not sure what to do when i do this kind of queries SELECT users JOIN pages ON ...
 
user652649
if i should instantiate a new user, a new page (to reuse the "join" also for User and Page)
 
user652649
or treat the join differently
 
4:45 PM
@SaffronHarris Javascript loops are almost the same as PHP. There is the traditional for (i = 0; i < length; i++) loop and variants thereof, good for looping arrays (more recently there is the sugar method Array.forEach() as well, but use sparingly, it's quite inefficient and can lead to unexpected scope problems if you aren't paying attention), and there is for (key in obj) {} which works with arrays and objects but should be used very sparingly because it's easy for properties to leak
(from the prototype)
@wes self::$users should be $this->users, a UserCollection object that you inject into the object instance. That way you can inject it into all objects that need it, and because it's an object any changes you make in one bit of code will reflect everywhere else.
(sorry for multi-multi-multi-ping)
 
@DaveRandom : thanks, so i just do the looping as usual and append it to a div, i would have to do my conditions as well in javascript. By condidtions i mean, if session userId = 1, then don't show this button etc. Isn' t that unsafe considering javascrript files can be seen?
 
user652649
yes i know the advantages... but i'm asking something different here... i think that is convenient, yes, for a lot of reasons... but smells like a huge complex code that i don't really need, because in the real world i treat User and Page independently by each other (read: UPDATE across multiple tables doesn't exist), and also i think that this code may be slower than running "about the same query" twice
 
@wes What? That makes no sense. All I'm talking about is changing the way you store the data from an array to an object, plus a small amount of reworking the way things are instantiated? How is that going to be slower than another round trip to the DB?
@SaffronHarris Well, you're not exposing any sensitive data to the client side are you? (you shouldn't be) Why would it be unsafe?
 

« first day (818 days earlier)      last day (4129 days later) »