-
Posts
4,704 -
Joined
-
Last visited
-
Days Won
179
Everything posted by kicken
-
If you want all the posts from the last two days, then you would use this query: SELECT * FROM mediaPost WHERE post_category=$cid AND post_enabled=1 AND post_created >= DATE_SUB(NOW(), INTERVAL 2 DAY) The post_created column needs to be of a DATE, DATETIME, or TIMESTAMP type for this to work. If no posts were made in the last two days, then that query would return nothing. If you want to return all posts from 2 days prior to the most recent post (which is what your original post hints at) then you need to use a sub-query to determine the most recent post first. For example: SELECT * FROM mediaPost WHERE post_category=$cid AND post_enabled=1 AND post_created >= ( SELECT DATE_SUB(MAX(post_created), INTERVAL 2 DAY) FROM mediaPost WHERE post_category=$cid AND post_enabled=1 )
-
Need help adding TD dymanic attributes in HTML table
kicken replied to eldan88's topic in PHP Coding Help
That won't work if you try and pass more than a single attribute via $attr. Because you overwrite (=) rather than append to (.=) $tr_attribute in the loop body, it will only contain the last item from $attr at the end of the loop rather than all items. $tr_attribute = ''; if (is_array($attr)){ foreach ($attr as $key=>$value){ $tr_attribute .= ' '.$key.'="'.$value.'"'; } } $row = "<tr{$tr_attribute}><td>{$data_name} </td> <td>{$data}</td></tr>"; return $row; -
First, Your listed table contents and query are not accurate. For example, your query says the stage field is in the student_times table, but your tables show it as in the student_points table. Your total field is similarlly reversed. Even if you fix that, the total comes out to 78, not 104. Be sure when you as for help that the information you post is accurate or you are just going to end up confusing people and wasting time. As for why the total is 104 (or 78 as your sample shows) rather than 26 as you'd expect is because your join ends up duplicating rows in the second table. For each row in the first table, it matches all the rows in the second table, eg: student_points 42 21 math 56 is joined with student_times 42 21 math 22 43 21 math 1 45 21 math 2 46 21 math 1 Then student_points 43 21 math 524 is again, joined with: student_times 42 21 math 22 43 21 math 1 45 21 math 2 46 21 math 1 And so on, so your ultimate result prior to grouping and summing is: MEMBER_ID TOTAL STAGE 4 111 23 15 44 34 21 22 56 21 2 56 21 1 56 21 1 56 21 22 251 21 2 251 21 1 251 21 1 251 21 22 524 21 2 524 21 1 524 21 1 524 When you apply the group and sum then, you get 22+1+2+1+22+1+2+1+22+1+2+1 = 78 You could resolve the duplicating of the second tables rows by doing a sub query first, but you'd still end up with the total duplicated due to the original table and a result set like this: MEMBER_ID TOTAL STAGE 4 111 23 15 44 34 21 26 56 21 26 251 21 26 524 What you probably need to do is introduce another table, however without knowing more about what your application does I'm not sure what to recommend. If you want to explain your overall app goals and table design then perhaps someone can recommend a better approach.
-
First off, this: $rotaDate = date('5/1/14'); Is wrong. The date function accepts a format string (ie, 'm/d/Y') and returns a date in that format. Since your string doesn't have any format codes you get it back unchanged so it "works" but it's essentially the same as just doing: $rotaDate = '5/1/14'; Which is what you should be doing to just assign a date string to a variable. As for the line in your function, if you just want the static '5/1/14' date, then set that as the argument in the constructor for DateTime: $rotaDate = new DateTime('2014-5-1'); Otherwise, pass in your $rotaDate variable as a second argument to use as a default. Eg function customData($line, $defaultDate){ if($line==getNewLine()){ return $defaultDate->format("jS F Y"); } ... } $rotaDate= new DateTime('2014-5-1'; //Or any other dynamically determined date customData($line, $rotaDate);
-
That would work. Rather than a boolean field, I would just make a general status field so that in the future if you want to add additional states (ie, cancelled) you can. You'd have a separate table with a list of possible statuses then the status field in the order table would be a foreign-key reference.
-
If you believe you have found a bug, then you should report it to phpMyAdmin, not here. There is nothing we can do about it.
- 1 reply
-
- phpmyadmin
- bug
-
(and 2 more)
Tagged with:
-
Validating max number of characters in input field
kicken replied to eldan88's topic in PHP Coding Help
$i gets defined eventually yes, but not before you try and use it, which is why the notice error appears and why the code ultimately fails. What you have, if expanded out into a more verbose code is: //isset($_GET['____']) && $i=$_GET['____'] . is_int($i) if (isset($_GET['____'])){ $tmp = $_GET['____']; $tmp = $tmp . is_int($i); $i = $tmp; if ($i){ //Something } } The code is wrong, as one can obviously see from the expanded out version. If you want to check is_int($i) after $i is assigned you would write: isset($_GET['____']) && ($i=$_GET['____']) && is_int($i) -
in_array checks the values, not the keys. To check the key you can use either array_key_exists or isset. $date='10/3/14'; if (isset($array[$date])){ $array[$date]['US'] = 100; }
-
Warning: strpos(): Empty needle in SearchScript.php on line 7
kicken replied to tobimichigan's topic in PHP Coding Help
You'd need to setup $dir to be equal to whatever file-system (ie, not http: something) path you want to scan. If you do this with a relative path, or by creating a path using php's magic constants then you can probably use the same value both locally and remotely. Otherwise you'd need to check which server you're on using $_SERVER['HTTP_HOST'] or similar and set the variable accordingly -
Do you want the script to run on machine1 or machine2? If you want it to run on machine1, you need to download it first to a local file then run that file with exec(). If you want it to run on machine2 you'd have to configure the server to run it when requested.
-
The only way you can identify someone is to require them to register an account prior to downloading the software. Even this can be worked around by people just registering multiple accounts though. There is no way without a registration process to accurately identify one person vs another person, so if you try you'll most likely only stop/annoy legitimate users while someone actually trying to abuse the trial would be more or less unaffected. This is why most trial programs do not restrict the downloads but instead either contain some kind of code to lock the program after x number of days or have limited functionallity. Download the installer all you want, it'll only work for x days after the initial install or only with some restrictions.
-
It's all in the manual, start reading and come back if you have a more specific question.
-
Yes, according to the change log it changed in 5.0.5:
-
Php Inheritance, dynamic properties and new static() constructor
kicken replied to pepito's topic in PHP Coding Help
PHP doesn't really have it's own built-in reflection, it is just lazy about validating things and does so at run time rather than compile time. From a design perspective, your parent class should be completely un-aware of what methods or properties a child would define, so it makes sense that from within the parent's code, this should only ever reference an item defined on that parent (or one of it's parents). If you want the parent to be able to call methods defined in a child, then that parent should be abstract with those methods defined, but not implemented, eg: abstract class Sortable { //define, but don't implement abstract protected function compare($a,$b); public function sort(){ //Somewhere in here we call $this->compare($a,$b); } } Assuming the statement about .NET is true (I'm not that familiar with it) then .NET would enforce that design pattern at compile time by verifying anything you try and access exists. Since PHP doesn't do that you can get away with referencing things on a child and just run the risk of a fatal/notice error at runtime if you ever happen to try it with a child that doesn't define the method/property being referenced. -
Understanding what a framework is doing behind the scenes.
kicken replied to kutchbhi's topic in Frameworks
It can be hard to grasp a high-level concept from looking at just the code sometimes, it's generally best to look into the documentation for the framework for any explanations first. You can combine that then with going through the relevant code to get a better picture of not only what is being done but how it's being done. Each framework is going to do things differently, so you should pick a single framework and work on learning that fairly well. Symfony has some pretty good documentation about it's internal workings that would make a good starting point. A benefit also is to setup something like XDebug so that you can step through code as a request is processed to better follow it's path and see what is going on. -
Extract contents of <td> tag, with <td> having specific ID.
kicken replied to Beun's topic in PHP Coding Help
Don't use regex at all for this. Use the DOMDocument extension to parse the HTML and extract the contents you need. <?php $html = '<html><head><title>blah</title></head><body> <table><tr><td id="blah">the content</td></tr></table> </body></html>'; $doc = new DOMDocument(); $doc->loadHTML($html); $td = $doc->getElementById('blah'); if ($td){ echo $td->textContent; } else { echo 'TD Not found'; } Depending on what the content is that you want, you may need to do more than just access the textContent property. There are a number of different ways to get at the content. -
I can't for the life of me move from mysql_* to prepared queries
kicken replied to r3wt's topic in PHP Coding Help
This is going to be much slower than the usual fetch methods. Not sure where you got the idea that it is better. Each time you call a function you have a fair bit of overhead. Using mysql_result like you are means you're making 4 function calls each row when you really only need one, plus you have the extra num_rows call which would be unnecessary using the traditional fetch loop. I recommend using PDO rather than mysqli. It's api is much simpler and functions much more similar to traditional mysql_* fetch loops than mysqli does. You also need to learn more about SQL and joins, doing another query while processing the results of the previous query is pretty much always a terrible idea. Most of the time you can do what you want in just one query with a JOIN. Also, do not use SELECT *. List out your columns that you need. Using * makes the code less readable and your queries less efficient. <?php //$db is an instance of PDO $sql = " SELECT w.Id , w.Market_Id , w.Name , w.Acronymn , price.Price FROM Wallets w INNER JOIN ( SELECT history.Market_Id, history.Price FROM Trade_History history INNER JOIN (SELECT Market_Id, MAX(Timestamp) Timestamp FROM Trade_History) mostRecent ON mostRecent.Market_Id=history.Market_Id AND mostRecent.Timestamp=history.Timestamp ) price ON price.Market_Id=w.Id WHERE w.disabled='0' AND w.Market_Id='1' ORDER BY w.Acronymn ASC "; $sqlx = $db->query($sql); $sqlx->setFetchMode(PDO::FETCH_ASSOC); foreach ($sqlx as $row){ $coinid = $row["Id"]; $base = $row["Market_Id"]; if($base == '1') { $pair = "BTC"; } if($base == '4') { $pair = "LTC"; } if($base == '3') { $pair = "OSC"; } $coinnm = $row["Name"]; $coinac = $row["Acronymn"]; $last_trade = $row['Price']; if($last_trade > 9){ $p2disp = round($last_trade); }else{ $p2disp = sprintf("%2.8f",$last_trade); } ?> <li class='box2'><p title="Trade <?php echo $coinnm; ?>" onclick="window.location = 'index.php?page=trade&market=<?php echo $coinid; ?>&base=<?php echo $base; ?>';"><?php echo $coinac.' / '.$pair;?><br/><?php echo $p2disp; ?></p></li> <?php } ?> -
Note that open_basedir won't prevent someone from reading another users files if you still allow things like exec()/system() as they could just use those to get around the restriction. If you are using PHP-FPM one thing you can do is setup a separate pool for each user and set the chroot directive to lock them into their home directory. There wouldn't be any way the user could get around that restriction.
- 2 replies
-
- php
- open_basedir
-
(and 3 more)
Tagged with:
-
To stop the interval you need to save the return value of setInterval then call clearInterval when you want to stop it. var intervalId = setInterval(function(){ ... }, 2000); $.post('work.php', function(){ clearInterval(intervalId); ... });
-
Can I get soem help with loading a script onlond that has vars
kicken replied to Mancent's topic in Javascript Help
Just call your convertVideo function from the document ready function. Eg: $(document).ready(function(){ convertVideo($('#source_videos button')); }); -
I don't have a /etc/php.ini, is it a problem?
kicken replied to renatov's topic in PHP Installation and Configuration
If you want the change reflected in all three environments, then yes you would. Another option would be change two of the files to symlinks pointing to the third, then you would only need to edit one file. The reason it is setup like it is by default is so that you can have different configuration settings for CLI vs CGI vs Apache Module. CLI for example commonly has less restrictions as it's a more controlled environment and serves a different purpose.- 7 replies
-
- php.ini
- installation
-
(and 2 more)
Tagged with:
-
mysql_num_rows returns 1 but mysql_fetch_assoc returns null?
kicken replied to homer_3's topic in PHP Coding Help
You're using the wrong variable. $sql should be $rv. -
Hide A Browse Button When A Specific Box Is Checked
kicken replied to phdphd's topic in Javascript Help
What you wrote will work, the problem is that you have jsfiddle configured to wrap your code in an onload event which means your showhide function is no longer available at the global scope. If you either change the fiddle settings or export that function to the global scope then it works fine: - http://jsfiddle.net/xSvLc/59/ -
His minified script has a guard in it so that it is only usable from his domain. You will need to get the original source and host it yourself.
-
You're not using your average value when converting back to RGB, rather you are just using the sum of all the pixel HSL values. You need to calculate the average for each or H, S, L and then use those to convert back to RGB with. $mycolors = array(array(255,0,0),array(255,126,126),array(86,13,0)); $average_color_hsl = array(0,0,0); $lux = new Lux_Color(); for($n=0; $n<count($mycolors); $n++): $hsl = $lux->rgb2hsl($mycolors[$n]); // returns 0 => Hue, 1 => Saturation, 2 => lightness $average_color_hsl=array_map(function($a,$b){ return $a+$b; }, $average_color_hsl, $hsl); endfor; $average_color_hsl = array_map(function($a) use ($n) { return $a/$n; }, $average_color_hsl); $average_RGB = $lux->hsl2rgb($average_color_hsl); $average_color = $lux->rgb2hex($average_RGB); die("$n : $average_color rgb(".implode(',', $average_RGB).')');