« first day (1993 days earlier)      last day (2955 days later) » 

12:55 AM
Hi, does anyone know how do I conditional output the this message?
echo "<li>"."<img src=''>"."</li>"
I want to conditional echo out the "<img scr='#'>"
 
Wes
1:07 AM
echo "<li>";
if(...){
   echo "<img>";
}else{
   echo "something else";
}
echo "</li>";
 
<li>
<?php if(...): ?>
  <img>
<?php endif; ?>
</li>
 
Wes
don't you know that a kitten dies every time you use the alternative syntax for control structures?
 
Thank!@Ronni @Wes!
 
Kittens die every time I hit the php template files
 
Wes
1:25 AM
kittens die harder - yelling "yippie ki-yay motherf***er" - when i hit blade, twig and similar stuff templates
 
1:37 AM
mornin
 
o/
 
Wes
\o
"this interface offers the functionality X, with which the consumer is enabled|allowed to determine whether..."
is it correct to use "enabled" like this? is there a synonym that doesn't imply authorization/allowance :\
the consumer is offered to, maybe? granted?
 
"enabled" may be fine, though might also be weird depending on the context.. do you have the entire sentence?
 
Wes
i should have paid more attention in english class... i hate the younger silly me
 
simpler would likely be "the consumer can determine"
 
Wes
1:50 AM
The method `asKeys()` returns an object reflecting the Map's keys as a fully-featured `Set`
instance, with which the consumer is enabled to determine whether the Map contains
key-mappings, remove them, and perform any other `Set` operation;
i know that's not the only problem with that sentence :B
 
yeah, go for the simple "can" version of the phrase
 
Wes
yeah, KISS always works :P
 
it's less cumbersome
 
Wes
yeah indeed. i do have the tendency to overly complicate things sometimes...
 
check out raymond carver if you get the chance.. he was an american short story author gifted in making every word count
I recommend the book "will you please be quiet please" - great collection of his stuff
 
Wes
2:02 AM
is it just ~50 pages, right?
...nope
 
my copy is 251 pages
speaking of which, I need to reread it too.. my english turned more unwieldy than I'd like
 
Wes
yep that was a sample. found it for 3$
amazon is ridiculously expensive for old books
 
it's more instructive for story telling than technical writing, but the same principles apply... plus it's a goddamn pleasure to read
some years back there was a used book store I frequented and became friends with the manager and his assistant. They became my personal shoppers. I wouldn't even need to look around - it got to where I'd walk in and they'd greet me with whatever books I was supposed to buy.
This was the one they were most emphatic about.
 
Wes
must be a great book
looks like i'm forced to buy it on amazon
the biggest mistake i do with english is trying to understand words i don't know by guessing them, like by looking at surrounding words and trying to grasp the meaning. that works but somehow these new words don't get fixated in my brain cells :B i should be checking for synonyms or sentences using those words every time but that gets boring easily
however i think i've somehow progressed with english in the past years, mostly by reading you guys chatting here... :B
 
2:25 AM
your english is very good.. for some reason I mistook you for canadian for a while
 
Wes
it looks good because i'm very good at hiding my deficiencies :B
 
what's the difference?
 
Wes
the difference is that i have to rethink several times my original sentence from italian so that i can translate it to english
 
having to put in effort doesn't make it less good, just less easy
 
Wes
yeah it's actually an intensive job sometimes, especially when chatting in here i wish i could answer immediately without checking dictionaries infinite times :B
 
2:33 AM
@Wes that's actually the way I learn everything. fuzzy logic it's called I think?
 
Wes
patent pending
 
you got beaten alreaady sorry :p
 
Wes
booo
i think it's normal, no? like i've guessed most (not the hardest part, perhaps) i know about programming just reading something at the first.
 
it's how people learn the bulk of their native languages, so yeah I'd say it's normal
 
Wes
otherwise we'd be just monkeys memorizing data
 
user1694691
What's the best way to define package-wide constants to support auto-loading?
 
oi
 
Wes
explicitly require the file containing them. sadly there is no way yet to autoload constants @PeterTòmasScott
 
user1694691
@Wes Such is life.
 
Wes
@PeterTòmasScott chat.stackoverflow.com/transcript/message/29550848#29550848 you know who to ping for that :D
 
user1694691
3:11 AM
I briefly considered implementing a dummy interface on the classes and then defining the required constants in the interface file, since that would effectively define the constants through auto-loading... but then I realised that was stupid and require_once does the same thing but with clearer semantics.
 
user1694691
Anyway, if I'm to get any sleep tonight I had better go now.
 
3:30 AM
use a class constant?
 
3:49 AM
If I have a MySQL table with a date column, is there an efficient way to select the ordered dates with an additional calculated column of the next date - 1 day?
Given:
my_date
2015-01-02
2015-03-07
2015-08-09
Result:
my_date    my_calculated_date
2015-01-02 2015-03-06
2015-03-07 2015-08-08
2015-08-09 NULL
 
ugh... using variables maybe. I would insert the current value associated with the value of the last row stored in said variable in a temporary table, then select that... but would I be tasked with that I'd select the rows then iterate over them php side to construct the desired array.
 
that almost deserves a question, I think some power rep hungry sql dudes such as barmar could answer that
 
I think I will post up; haven't done that in awhile :-P
What about a subquery?
SELECT
    t1.my_date,
    (SELECT
        t2.my_date
        FROM my_table t2
        WHERE t2.my_date > t1.my_date
        ORDER BY t2.my_date
        LIMIT 1) AS my_calculated_date
    FROM my_table t1
Or won't that work; note: I'm tired and typing this on a phone, lol
 
Wes
4:05 AM
@NorthbornDesign are them ordered or you need to figure out which is the closest next date?
 
useless crap
 
Figure out. Assume no natural order.
 
@NorthbornDesign hey that seem it would actually work. if you also order t1
 
Wes
i don't know postgres but that on mysql would be crap
 
you mean slow?
 
Wes
4:11 AM
yeah
maybe use a variable? dunno if postgres supports them
 
well, that can be leveraged by caching the results. also who knows, maybe it just have to be run onced for moving shit from database to database purpose
 
Well, it does work.
But yea, I'm worried about performance.
I'll have to bench.
 
Wes
order by is the killer
you can't change the table structure, right?
 
join with an offset perhaps
 
Wes
id | date | next_date_id
 
4:17 AM
I'll proceed to keep my opinions on the matter silent... you're drunk Félix, get home
 
Wes
my sql-fu is rusty
@PaulCrovella how do you create a counter without using a variable?
 
@PaulCrovella Could you elaborate?
SELECT
    t1.my_date,
    (SELECT
            DATE_SUB(t2.my_date, INTERVAL 1 DAY)
        FROM
            my_table t2
        WHERE
            t2.my_date > t1.my_date
        ORDER BY t2.my_date
        LIMIT 1) AS my_next_date
FROM
    my_table t1
ORDER BY t1.my_date;
^^ That works nicely, but performance is questionable.
Thankfully, its going to be operating on a table that should stay small, indefinitely; the potential for growth is very small and slow.
 
@NorthbornDesign similar to what's happening in this question
 
4:23 AM
Ah, select ordered twice with row number, and join on row number + 1?
 
yep
in my head it went a little different (my sqlfu is questionable), but basically that..
 
Wes
oh cool mysql can't self join subqueries -__-
 
mornin
 
Wes
@NorthbornDesign seriously though if you can you should have a "next_date_id" column
 
@Wes No, I shouldn't.
 
Wes
4:36 AM
why?
 
Because of course I shouldn't.
Seriously though, because normalization-to-the-extreme.
 
maintaining that would suck
 
Wes
maintaining a sql that almost certainly is going to be a mess would suck more...
nope, can't do it. mysql is terrible
 
moin
 
Wes
SELECT * FROM (SELECT * FROM a) AS a1 JOIN a1 AS a2 ON a1.whatever = a2.whatever i don't think it's possible to something like this in mysql without explicitly creating a temp table
morning joe
 
4:48 AM
SELECT FROM my_pants
3
 
hehe
 
5:00 AM
mornin
 
moin @Ekin
 
gud morning
 
posted on March 31, 2016

New Cyanide and Happiness Comic

 
Morning all, anyone able to help me out with some PHP PDO login? I am trying to take what the user types for username and password and check it with the database. Also I am using autoloading, however my PHP is very rusty and was wondering if anyone can provide some assistance :D
I got the user input part in place, it is mostly the SQL part that is troubling me.
 
what exactly is the problem, that you are seeing?
 
Well, the problem for me is to actuallly understand how it should be made, one sec I can pastebin my code
Ok, this is my login form: pastebin.com/WP9gh0jM and this is my database stuff: pastebin.com/PPxSYCNa and in my database I have a username called test and with a password 1234, and my user has an id of 1. So now when in my login form I put test and 1234, I want it to check with the db if that username && password is present in the DB and if it is, pass it on to the next page (gallery.php)
 
5:41 AM
first of all, you should NEVER store plain-text passwords in a databases
instead you hash them and store the hashes: php.net/manual/en/function.password-hash.php
 
I get the following error Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/............../App/Controller/dbConnecterController.php on line 52 and line 52 is: } else {
and yes of course, that is for testing purposes and I intend to add hashing
this is just to make it simple for myself while getting the connection part correct.
 
you have tried to makes
 
I also intend to sanitize my input fields to prevent some SQL injections
 
while () {
    ...
} else {
    ...
}
 
5:44 AM
oh
 
@Spiderix you need table that holds username and password hash. then you just hash the password you get from the form and check if select username from users where username=? and hash=?. The ? mean its a prepared statement. Do not concatenate the username and hash, else you risk sql injection, e.g. someone could tamper with your db in unexpected ways.
and morning everyone
 
@Spiderix you do not sanitize fields with PDO, instead you use prepared statements - those send the query and data separately to the server
another issue: you should be selecting the user's password hash from the database and then compare it on the php end (using php.net/manual/en/function.password-verify.php)
 
doog roaming
 
oiy
 
Aha I see, ok thanks. Ok now I moved my else, so it matched the if on top pastebin.com/uCAGjYJc but however I get Parse error: syntax error, unexpected end of file in /home/...../App/Controller/dbConnecterController.php on line 61 and line 61 is just ?>
oh, I think I messed up a bracket or something
 
5:52 AM
@Spiderix you pastebin doesnt have 61st line
 
yea, I removed some spaces, I believe it is 57 now
 
btw, @Spiderix explain this line to me:
if ($username == $usernameDb && $password == $passwordDb) {
what is the point of it? (there is a reason, why I am asking you this)
 
Yes, I was thinking if what the user inputs equals what's in the DB then do w.e is in the if statement
 
Be gentle, this is my first time with PHP :D
I am still getting confused by the syntax
 
5:57 AM
your next step should be adding password hashing using these functions: php.net/manual/en/book.password.php
 
@Spiderix also you should check it inside the database query without retrieving password from database
 
^ that might sound confusing from his point of view
 
Oh, it does indeed :D
 
@Spiderix sorry it's by mistake on mobile there is no option for delete or edit..
 
`SELECT count(...) FROM users where username = ... AND password = ...`

then you see if it's > 0, then there is this user and his password matches, if no rows are returned, then there is no such combination in database
 
6:00 AM
@AnmolRaghuvanshiVersion1.0 lies, you select the comment in the mobile UI and you get an option to edit or delete
 
I really miss dedicated SO chat application
 
Ok, I will try that password hashing thing, see how it goes, meanwhile I am getting the following error:

Notice: Undefined property: PDOStatement::$fetchColumn in /home/............/App/Controller/dbConnecterController.php on line 41

Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php5/sessions) in Unknown on line 0 my current dbConnecterController.php file: http://pastebin.com/XdNAzHaU and line 41 is the while loop
 
can anyone tell me why calling an image url from mysql with ajax isn't working? $("#img_logo").attr("src", "img_logo"); it works if i replace "img_logo" with the url of an image. "img_logo" is the field name in mysql, and at the moment it replaces the src of the img to "img_logo" and has an error that it can't find the image. any ideas?
 
@AnmolRaghuvanshiVersion1.0 hehe no worries :D
 
no teresko,may be I missed that...
 
6:04 AM
I assume in my DB, I will have to change the password field to take 255 varchars?
 
@Spiderix hashing takes any length string and converts it into a fixed size footprint
 
aha I see
 
the result of password_hash() is always 60 symbols
 
Just to note am I asking a really dumb question or is it just no one can be bothered?
 
@AboutLeros this question makes no sense. JQuery can't access mysql tables
 
6:07 AM
no, but php can . . . and JQuey can access that.
I'm using the id to echo out data.
 
@Spiderix in the second instance (inside the while) you were calling fetchCollumn as a variable not as a function
also, it should be while ($info = $result->fetch(PDO::FETCH_ASSOC)) there
 
@tereško there is an http plugin for mysql, so in theory jQuery could access it via ajax. not that it's a good idea in mostly any cases, but in theory it could work.
 
where does info come from?
 
you have these lines in your code
$usernameDb = $info['username'];
$passwordDb = $info['password'];
 
Oh, lord I am so blind :S
 
6:13 AM
I should actually be asking you, @Spiderix, "where does $info come from"
 
well here's my code if anyone feels like looking. jsfiddle.net/dwL0Le7o/1
 
haha, been working on this login for a week now, so I gotta say I am getting slightly forgetful.
 
FYI, the fetchColumn() method is for taking a vertical slice ... I don't think that's what you need there
 
Hmm ok, it does not give any errors now, however it gives a blank page and not redirecting me to header('Location: /pages/gallery.php');
Aha I see.
 
are you, at any point, checking whether anything even exists in $_POST['username'] ?
 
6:18 AM
@tereško a config file under version control an environment specific configuration file
 
@tereško hmm nope I don't check it, I assumed it wasn't needed since it is just to get a username and password but I check it further down with the DB
to see if the username is present in the DB
 
the first step is to make sure that the login for actually has been submitted
 
I mean, it connects fine with the DB, because if I provide a wrong username it gives "Username not in the DB, talk with the owner to add you!" which I have added in the code
but when I provide the correct information it simply gives a blank site
 
6:25 AM
@SergeyTelshevsky it's like 2 days old. Where have you been?!
MS is trying to retain it's status as a "developers OS"
 
posted 14h ago! and I don't follow MS news :D
 
also @tereško this is the structure of my source code pastebin.com/swYQswpK
Ah, I think I see the problem with the blank webpage
 
Also, there's a Subsystem for UNIX applications in Windows.
 
Hmm, in headers how can I use a global constant? header('Location: VIEW_DIR . /pages/gallery.php'); the constant is define('VIEW_DIR', realpath(DIR . '/../views'));
 
@Spiderix sprintf('Location: %s/pages/blah', VIEW_DIR)
 
6:35 AM
@littlepootis what? you mean cygwin & msysgit?
 
@SergeyTelshevsky No, Windows SUA
 
btw, I am already handling % in urls with this piece of code pastebin.com/FXVEGR5w is it then needed to use the thing you posted?
 
@Spiderix completely different thing
 
Ah ok
 
the %s is a placeholder. it will get replaced with the content of VIEW_DIR. The s means, its treated as a string.
!!docs sprintf
 
6:38 AM
[ sprintf ] Return a formatted string
 
hmm, it is still giving a blank site, but gives the error "Username not in the DB, talk with the owner to add you!" if I type it wrong
by it I mean username or password, so it is able to check properly
 
6:52 AM
@littlepootis discontinued?
 
@SergeyTelshevsky no. I'm pretty sure they use it to run ubuntu (linux) user space applications on Windows.
Perhaps that's how bash on W10 works
It translates Linux System calls to Windows sys calls
 
@littlepootis no, they killed SUA with 8.1, the new linux subsystem is something different
 
@PaulCrovella they killed it?
 
@littlepootis yes, windows 8.1 removed SUA.. the new thing is built on the remains of astoria
 
6:57 AM
@littlepootis it's likely a fork of freebsd' linux compatibility layer
 
-1
Q: Convert MySql query to Laravel query/

AnkitMYSQL Query select d1.update_id from ( select update_id, count(update_id) as ct from updates_tags where tag_id in (67,33,86,55) group by update_id) as d1 where d1.ct=4 It gives me Update_id as a results. I want to convert it in Laravel Query builder. Looking forward to your help.

If somebody knows laravel. Please help me to build laravel query.
 
I gotta run, thanks for the help guys, I might bother you later again. have a nice day.
 
@PaulCrovella It sit corrected
 
Laravel query…?! wtf
 
@gordo I need to convert into laravel standards
 
7:02 AM
> laravel standards
 
@Ankit it's more like telling us to write code for you
 
$update = DB::table('tags')
->select('t_id', 'u_id', DB::raw('count(*) as total'))
->whereIn('t_id',$tags)
->where('total','=',count($tags))
->groupBy('u_id')
->lists('u_id');
I already do
but it is not working properly
@sait
 
7:05 AM
@Ankit stackoverflow.com/a/36262130/208809 sounds like a good suggestion to me.
 
@Gordon it is not working
I tried
 
Your SQL query isn't working?
 
E_DOESNT_WORK is now a defined php error level?
10
 
@littlepootis is working with MySQL perfectly
but when we try in laravel with using custom queries
 
@tereško but there's no "Send this error to PHP team" button as there is in all the cool apps
 
7:07 AM
@tereško it should be. Also needs an exception though. Might be a good RFC for tomorrow.
class ItDoesntWork extends Exception {
    public function __construct() {
        parent::__construct("It doesnt work");
    }
}
4
 
@Gordon automatically triggered on hitting a keyboard hard enough or any other part of the PC
 
my desktop PC does not come with gyro sensor ... and, frankly, I would be really worried if it did
 
well you need that for that exception
 
@SergeyTelshevsky sorry but that wrecks my workflow
 
7:13 AM
"the new 2U, now with a gyroscope"
 
@littlepootis I won't even open it, my favorite xkcd
 
morning!
 
@tereško : I edited the question please check.... stackoverflow.com/questions/36260657/query-execution
 
who said that ?
my browser just made a ping noise ...
 
hmm, ItDoesntWorkException cannot inherit from Exception because most methods are final. This means I cannot overloads the stacktrace methods to return null. So it would include the stacktrace with helpful information. That is clearly undesired.
 
7:27 AM
Hi guys i am back
Can anyone tell me what is an custom MVC
I am pretty new to MVC..
 
yesterday, by astrosixer
MVC is a framework
 
@astrosixer @Wikipedia can tell you everything to get you started
 
@DamienOvereem that probably will return something terrible
 
Most likely, but think of the learning opportunities when trying to distinquish the good from the bad
 
7:36 AM
5
A: Trying to understand MVC Models, Advice?

GordonIt is a common misconception that the M in MVC is just about the database. MVC's main aim is to separate the presentation layer from the remaining application in a way that M does not know about VC. V and C form the UI, an outer layer by which users can interact with your application. C handles ...

 
Lol
"CakePHP says"
> Models represent data and are used in CakePHP applications for data access. A model usually represents a database table but can be used to access anything that stores data such as files, LDAP records, iCal events, or rows in a CSV file.
Also,
 
@Jimbo rails legacy
 
Anonymous
@Gordon if you have simple function like password hasher, does it make sense to include it inside models?
 
Well it doesn't go in the controller or view :-)
 
Anonymous
but still, .. it seems wrong
 
Anonymous
7:41 AM
I say always use a Util class.
 
@samayo in general, Util classes are a symptom of misplaced responsibilities
 
Anonymous
Yeah, but there is no other way to group small application features that don't belong to any specific domain
 
@Gordon and/or a fear of functions
 
why cant you have an \Acme\User\PasswordHashService?
or \Acme\User\PasswordHash value object?
 
Anonymous
If I have to do the same thing for every little function, the library would be unimaginable, but I agree that is a good place to put it.
 
7:52 AM
youtube.com/watch?v=p9jXV6VUpwE .. this is a pretty good weekly news review show
 
Anonymous
~2:30 Hours
 
Anonymous
Ain't nobody got time for dat :p
 
how can i select a row by id? if for example your displaying a dynamic modal and you want a different image on each one. so each modal is displaying the what is on the row, using the row id
 
@AboutLeros select * from table where id = ?
 
Anonymous
SELECT ... WHERE id = {id}
 
7:58 AM
@samayo I put it in the background
 
Anonymous
@tereško The whole thing is fishy, not sure if I buy the story.
 

« first day (1993 days earlier)      last day (2955 days later) »