-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Depends on what the "something" that you are doing is. If the something that you do to v1 is always independent of what the value of v2 is, then option 1. If, however, that something also depends on the value of v2 then you have to go with option 2.
-
Store your queries in a string before executing. That way, if you have problems, it is easy to echo the string and maybe spot any errors. $sql = "SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=$q OR c.originalid=$q) AND ((c.member1=$memberid AND c.removed1='No') OR (c.member2=$memberid AND c.removed2='No')) ORDER BY c.id"; echo "<pre>$sql</pre>";
-
Have you tried testing it with your input form?
-
Have a look at the filter_input() function. Filter options will allow for range checks on integers.
- 8 replies
-
- ajoo
- input filteration
-
(and 1 more)
Tagged with:
-
Changing $HTTP_POST_VARS to $_POST won't hurt. I haven't seen HTTP_POST_VARS this century and a search on php.net manual didn't find it. stripslashes() should only be necessary if magic_quotes is on, and the default has been "off" for years. Check your php.ini settings.
-
while($rows = mysql_fetch_array($result)){ .... delete-contact.php?id={$row['id']} ...
-
HTTP_POST_VARS??? Looks like you are still using PHP v3. Time to upgrade.
-
real_escape_string() uses the database connection so you have to connect before using it
-
The page it is sent to has no way of knowing whether the input comes from your dropdown or a malevolent source. Assume anything that come from a user source (COOKIE, GET, POST) is suspect. So, yes.
- 8 replies
-
- ajoo
- input filteration
-
(and 1 more)
Tagged with:
-
try SELECT name , salary , SUM(Login_Hours) as Hrs , salary/SUM(Login_Hours) as Rate FROM users u LEFT JOIN attendance a ON u.id = a.user_id AND Date LIKE '2014-11%' GROUP BY name;
-
replacing text on page, but breaks if i use body selector
Barand replied to toolman's topic in Javascript Help
This seems to work <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $("#btnReplace").click(function() { var txt = $("body").html(); var re = /foo/gi; txt = txt.replace(re,"bar"); $("body").html(txt); }) }) </script> </head> <body> <h1>Foo Heading</h1> <p>This is foo</p> <table border="1"> <tr><td>foo</td><td>123</td></tr> <tr><td>foobar</td><td>321</td></tr> </table> <input type="button" name="btnReplace" id="btnReplace" value="Replace"> </body> </html> -
Isn't that what you are doing?
-
The dates in a BETWEEN clause are inclusive mysql> SELECT * FROM test_date; +----+------------+ | id | date | +----+------------+ | 1 | 2014-11-15 | | 2 | 2014-11-16 | | 3 | 2014-11-17 | | 4 | 2014-11-18 | | 5 | 2014-11-19 | | 6 | 2014-11-20 | +----+------------+ 6 rows in set (0.00 sec) mysql> SELECT * FROM test_date -> WHERE date BETWEEN '2014-11-16' AND '2014-11-19'; +----+------------+ | id | date | +----+------------+ | 2 | 2014-11-16 | | 3 | 2014-11-17 | | 4 | 2014-11-18 | | 5 | 2014-11-19 | +----+------------+ 4 rows in set (0.00 sec) It must be the other conditions in the WHERE clause. Try with just the date condition and see if that gets all the dates then add in the other conditions one by one
- 11 replies
-
If you have a unique key already set on inventor then inserting a duplicate is already impossible.
-
Create a unique index on (product, inventor). This will then give a duplicate key error if you attempt to add the same combination Alternatively, having set up that index, change your query to INSERT INTO products (inventar, product, price) VALUES ('$inventar', '$product', '$price') ON DUPLICATE KEY UPDATE price = $price which will update the existing record instead of trying to insert a duplicate
-
My first project - Connected but no data - MySQL\PHP
Barand replied to Mouse51180's topic in PHP Coding Help
Off-topic but a couple of points about your data. Country_name,city_name and place_name should only appear in their respective tables and not in your log table. That should only contain the place_id. Your place table should contain the city_id. Your city table should contain the country id, so if you know the place then you know the city id; if you then know the city_id you then know the country id and you can join the tables to get the names. Is number always a duplicate value of the id value? country | | +----< city | | +-------< place diver | | | | +--------< log >-------+ -
DATA: mysql> SELECT * FROM blog; +---------+----------+ | blog_id | blogname | +---------+----------+ | 1 | Blog 1 | | 2 | Blog 2 | | 3 | Blog 3 | | 4 | Blog 4 | | 5 | Blog 5 | +---------+----------+ mysql> SELECT * FROM blogtag; +------------+---------+----------+ | blogtag_id | blog_id | tag | +------------+---------+----------+ | 1 | 1 | any | | 2 | 1 | baker | | 3 | 1 | canary | | 4 | 2 | able | | 5 | 2 | beta | | 6 | 2 | canada | | 7 | 3 | alpha | | 8 | 3 | banana | | 9 | 3 | cup | | 10 | 4 | arachnid | | 11 | 4 | beetle | | 12 | 5 | anchor | +------------+---------+----------+ QUERY (to select one random tag for each blog): SELECT b.blog_id , blogname , SUBSTRING_INDEX(GROUP_CONCAT(tag ORDER BY RAND()),',',1) as tag FROM blog b LEFT JOIN blogtag USING (blog_id) GROUP BY blog_id; RESULT: +---------+----------+--------+ | blog_id | blogname | tag | +---------+----------+--------+ | 1 | Blog 1 | canary | | 2 | Blog 2 | able | | 3 | Blog 3 | banana | | 4 | Blog 4 | beetle | | 5 | Blog 5 | anchor | +---------+----------+--------+
-
Why the LEFT join? INNER join is much faster And do you need to load the csv file every time you need to run the query?
-
$lines = array( "The cat jumped over the wheel.", "My four wheels are cool.", "My car has a wheel and a cat on another wheel." ); foreach ($lines as &$line) { $p = strpos($line, 'cat'); if ($p===false) continue; $part1 = substr($line, 0, $p); $part2 = substr($line, $p); $part2 = str_replace('wheel', 'tire', $part2); $line = $part1.$part2; } echo '<pre>',print_r($lines, true),'</pre>'; /* RESULTS ********************************************** Array ( [0] => The cat jumped over the tire. [1] => My four wheels are cool. [2] => My car has a wheel and a cat on another tire. ) */
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
Corrected version $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $sql = "SELECT id, dogname, sire, dam FROM dogtable"; $dogs = $sires = $dams = array(); $res = $db->query($sql); while (list($id, $nm, $s, $d) = $res->fetch_row()) { $dogs[$id] = [$s,$d,$nm]; } function getAncestors($id, &$dogs, &$ancests, $dist) { if ($id==0) return; $ancests[$id] = $dist; if (isset($dogs[$id]) ) { getAncestors($dogs[$id][0], $dogs, $ancests, $dist+1); getAncestors($dogs[$id][1], $dogs, $ancests, $dist+1); } } $dogid = 1; getAncestors($dogs[$dogid][0], $dogs, $sires, 1); getAncestors($dogs[$dogid][1], $dogs, $dams, 1); ksort($sires); ksort($dams); $common = array_intersect_key($sires,$dams); echo "<pre>"; echo "| ID | NAME | SIRE | DAM |\n"; echo "| | | DIST | DIST |\n"; echo "|-----|--------------------|------|------|\n"; foreach ($common as $id => $dist) { printf("|%4d | %-18s | %4d | %4d |\n", $id, $dogs[$id][2], $sires[$id], $dams[$id]); } | ID | NAME | SIRE | DAM | | | | DIST | DIST | |-----|--------------------|------|------| | 8 | dog I | 3 | 2 | | 16 | dog Q | 4 | 3 | | 17 | dog R | 4 | 3 |- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
After this line $query = "SELECT * FROM callable WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%' AND channel LIKE '%$channel%' AND duration"; what does this echo $query; give?
- 11 replies
-
Is it feasible for you to load the csv data into a table then join that table to you fewMillionRows table. That way you only need a single SELECT query
-
Sorry, I copied your code in my last post. The format definition should be in quotes, as in my original post (#4) DATE_FORMAT(invoicedate,'%d-%m-%y'). And don't give them all the same alias (" as date") as you cannot then access them with $row['date']
-
Calculating Inbreeding on a 10 Generation Pedigree
Barand replied to Triple_Deuce's topic in PHP Coding Help
PS - apologies for the bisexual dog in the data, but you get the idea- 40 replies
-
- inbreeding
- pedigree
-
(and 2 more)
Tagged with:
-
Does the array $biglist come from a database table? Are your values indexcol1, indexcol2 etc from the objects in the biglist array?