-
Posts
24,609 -
Joined
-
Last visited
-
Days Won
832
Everything posted by Barand
-
this will give you a count of the attempts and the minutes since the last attempt $sql = "SELECT COUNT(*) , TIMESTAMPDIFF(MINUTE, MAX(LATimeStamp), NOW()) FROM LoginAttempts WHERE LASalesID = '$ID' AND LACleared = 'no' "; $rs = $con->query($sql); if ($rs->num_rows > 0) { list($count, $mins_elapsed) = $rs->fetch_row(); }
-
this will give the number of minutes since their last attempt (where the datetime is their last attempt) SELECT TIMESTAMPDIFF(MINUTE, '2015-07-28 11:25:08', NOW());
-
how to sort <a> tags inside an array based on their text?
Barand replied to sabeti05's topic in PHP Coding Help
use a custom sort function with usort() $var = array('<a href="3">a</a>', '<a href="1">b</a>', '<a href="2">c</a>'); usort($var, 'mysort'); foreach($var as $value){ echo $value, '<br>'; } function mysort($a, $b) { return strcmp(strip_tags($a),strip_tags($b)); } -
Try outputting $con->error instead of $conn->error and see if that gives a message
-
try SELECT name, client.cid FROM client LEFT JOIN ( SELECT cid FROM distribution GROUP BY cid HAVING COUNT(*) >= 10 ) as sub ON client.cid = sub.cid WHERE sub.cid IS NULL
-
Who is legally responsible for XSS vulnerabilities?
Barand replied to NotionCommotion's topic in PHP Coding Help
If a burglar breaks into my house, don't send him to prison; send the guy who originally built the house. -
Use LEFT JOIN instead of INNER JOIN
-
JOIN twice and give them different aliases SELECT u1.name as driver, u2.name as handler FROM drive_routes dr INNER JOIN users u1 ON u1.id = dr.driver INNER JOIN users u2 ON u2.id = dr.handledby
-
Your array $sets = array( array(1,1,1,1), array(2,2,2,2), array(3,3,3,3), array(4,4,4,4) ); I think this is a classic case of "if you want to go there I wouldn't start from here". Rearrange the array so you have $sets = array( array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4) ); This code will do that for you: function rearrange($sets) { $new = array(); foreach ($sets as $r => $row) { foreach ($row as $c => $val) { $new[$c][$r] = $val; } } return $new; } $sets = rearrange($sets); Then you can use a recursive function to take each array in turn and combines with the others function combys($sets, &$results, $x) { $ks = count($sets); $tmp = array_shift($sets); foreach ($tmp as $t) { if ($ks==1) { $results[] = $x.$t; } else combys($sets, $results, $x.$t); } } $results = array(); combys($sets, $results, ''); // call the function to generate the combinations $str = join(' ', $results); echo '<pre>' . wordwrap($str, 80) . '</pre>'; // output results Or you can use a series of nested foreach loops after rearranging the array foreach ($sets[0] as $v0) { foreach ($sets[1] as $v1) { foreach ($sets[2] as $v2) { foreach ($sets[3] as $v3) { $results[] = $v0.$v1.$v2.$v3; } } } } Results: 1111 1112 1113 1114 1121 1122 1123 1124 1131 1132 1133 1134 1141 1142 1143 1144 1211 1212 1213 1214 1221 1222 1223 1224 1231 1232 1233 1234 1241 1242 1243 1244 1311 1312 1313 1314 1321 1322 1323 1324 1331 1332 1333 1334 1341 1342 1343 1344 1411 1412 1413 1414 1421 1422 1423 1424 1431 1432 1433 1434 1441 1442 1443 1444 2111 2112 2113 2114 2121 2122 2123 2124 2131 2132 2133 2134 2141 2142 2143 2144 2211 2212 2213 2214 2221 2222 2223 2224 2231 2232 2233 2234 2241 2242 2243 2244 2311 2312 2313 2314 2321 2322 2323 2324 2331 2332 2333 2334 2341 2342 2343 2344 2411 2412 2413 2414 2421 2422 2423 2424 2431 2432 2433 2434 2441 2442 2443 2444 3111 3112 3113 3114 3121 3122 3123 3124 3131 3132 3133 3134 3141 3142 3143 3144 3211 3212 3213 3214 3221 3222 3223 3224 3231 3232 3233 3234 3241 3242 3243 3244 3311 3312 3313 3314 3321 3322 3323 3324 3331 3332 3333 3334 3341 3342 3343 3344 3411 3412 3413 3414 3421 3422 3423 3424 3431 3432 3433 3434 3441 3442 3443 3444 4111 4112 4113 4114 4121 4122 4123 4124 4131 4132 4133 4134 4141 4142 4143 4144 4211 4212 4213 4214 4221 4222 4223 4224 4231 4232 4233 4234 4241 4242 4243 4244 4311 4312 4313 4314 4321 4322 4323 4324 4331 4332 4333 4334 4341 4342 4343 4344 4411 4412 4413 4414 4421 4422 4423 4424 4431 4432 4433 4434 4441 4442 4443 4444
-
JSON Error Occurred in registration- PHP
Barand replied to james_martin_187's topic in PHP Coding Help
Erm, there should be no SET keyword in the first syntax version INSERT INTO tablename (col1, col2) VALUES (val1, val2) -
try changing $sql = mysqli_query($connection,"INSERT INTO plus_signup (name, userid, user_level, password, email) VALUES ('$name', '$userid', '$user_level', '$pass2', '$email'"); $result = mysqli_query($connection,$sql) or die (mysql_error()); to $sql = "INSERT INTO plus_signup (name, userid, user_level, password, email) VALUES ('$name', '$userid', '$user_level', '$pass2', '$email'"; $result = mysqli_query($connection,$sql) or die (mysql_error());
-
Strange, it should be "jailtime" giving that error. You have "jailzeit" in the table.
-
None that I am aware of.
-
You shouldn't be updating the restaurant id in the update. Your query sets all the records for the restaurant to each cuisine id in turn, so you then up with them all equal to the last one in the loop. Easiest way is to delete the restaurant_cuisine records for the resturant then insert records for each cuisine.
-
or instead of the DATE_ADD() function you can just use ... AND EntryDate < '$StartDate' + INTERVAL 6 WEEK
-
You need to query your facility table LEFT JOINED to the user_facility table SELECT f.facility_name , uf.user_id FROM facility f LEFT JOIN user_facilty uf ON f.facily_id = uf.facility_id AND uf.user_id = $userID; This will give results like +---------------+---------------+ | facilty_name | user_id | +---------------+---------------+ | air_con | NULL | | wi-fi | 1 | | smoking area | NULL | | bar | 1 | +---------------+---------------+ Loop through the results outputting the facility name and checkbox. Check those boxes where restaurant_id is not null air_con [ ] wi-fi [X] smoking area [ ] bar [X]
-
your radio button has no value
-
A couple of corrections required to the above: INNER JOIN rrheeler h ON r.sid = MOD((h.sid + $r),10) + 1"; should be INNER JOIN rrheeler h ON r.sid = MOD((h.sid + $r),$numRounds) + 1"; and the "time" column in result table should be DECIMAL(8,2)
-
There would appear to 10 printable and 7 non-printable characters in that string
-
Try doing var_dump($housedddy); to see if its size and content are as expected
-
I have rewritten the two functions so that you now pass an array of opening times for the restaurant to daysandtimes() function. function daysandtimes(&$times) { $out = ''; $days = [1=>'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; foreach ($days as $dno => $dname) { $hours = array_merge($times[$dno], array('','','','')); // ensure > 4 array elements $menu1 = timeOptions($hours[0]); $menu2 = timeOptions($hours[1]); $menu3 = timeOptions($hours[2]); $menu4 = timeOptions($hours[3]); $out .= <<<OUT <tr> <td>$dname</td> <td><select name='openclose[$dno][1]'>$menu1</select></td> <td><select name='openclose[$dno][2]'>$menu2</select></td> <td><select name='openclose[$dno][3]'>$menu3</select></td> <td><select name='openclose[$dno][4]'>$menu4</select></td> </tr> OUT; } return $out; } function timeOptions($current) { $selClosed = $current==-1 ? 'selected="selected"':''; $opts = "<option value=''> </option>\n <option $selClosed value='-1'>Closed</option>\n"; $dt1 = new DateTime('06:00'); $di = new DateInterval('PT30M'); $dp = new DatePeriod($dt1, $di, 42); foreach ($dp as $d) { $v = $d->format('H:i:00'); $t = $d->format('g:i a'); $sel = ($v==$current) ? 'selected="selected"':''; $opts .= "<option $sel value='$v'> $t</option>\n"; } return $opts; } To use it now, get the times from the database and store in an array, like this $rid = intval($_GET['rid']); // get the restaurant id $sql = "SELECT day , open_time , close_time FROM business_hours WHERE restaurant_id = $rid ORDER BY day, open_time"; // create array of time for each day $times = array(); $res = $db->query($sql); while (list($day, $ot, $ct) = $res->fetch_row()) { if ($ot=='00:00:00' && $ct=='00:00:00') { $times[$day][0] = -1; } else { $times[$day][] = $ot; $times[$day][] = $ct; } } Then pass the array to the function to output the menus <table> <?=daysandtimes($times)?> </table>
-
You need keep track of the previous score and maintain a count. EG $results = array( array ('name'=>'Peter', 'time'=>'00:20:30'), array ('name'=>'Paul', 'time'=>'00:22:12'), array ('name'=>'Ted', 'time'=>'00:21:42'), array ('name'=>'Ben', 'time'=>'00:23:04'), array ('name'=>'Tom', 'time'=>'00:21:42'), array ('name'=>'Hank', 'time'=>'00:24:36'), array ('name'=>'Fred', 'time'=>'00:21:42') ); // sort the results by time uasort($results, function($a, $b) { return strcmp($a['time'], $b['time']); }); // display results showing the ranking positions $prevtime = '00:00:00'; $count = 0; $pos = 0; foreach ($results as $rider) { ++$count; $pos = ($rider['time']==$prevtime) ? $pos : $count; $prevtime = $rider['time']; echo "$pos : {$rider['name']} ({$rider['time']})<br>"; } /* output ****************** 1 : Peter (00:20:30) 2 : Tom (00:21:42) 2 : Ted (00:21:42) 2 : Fred (00:21:42) 5 : Paul (00:22:12) 6 : Ben (00:23:04) 7 : Hank (00:24:36) */
-
OK no strategy then, so assuming there are always the same number of each, and given your data looks like this mysql> SELECT sid, roper FROM rrroper; +-----+--------+ | sid | roper | +-----+--------+ | 1 | Alice | | 2 | Bob | | 3 | Cindy | | 4 | Dave | | 5 | Emma | | 6 | Fred | | 7 | Gina | | 8 | Henry | | 9 | Imogen | | 10 | Jack | +-----+--------+ 10 rows in set (0.00 sec) mysql> SELECT sid, heeler FROM rrheeler; +-----+---------+ | sid | heeler | +-----+---------+ | 1 | Martin | | 2 | Nicola | | 3 | Oliver | | 4 | Paula | | 5 | Quentin | | 6 | Rosie | | 7 | Steve | | 8 | Tracey | | 9 | Uri | | 10 | Vanessa | +-----+---------+ 10 rows in set (0.00 sec) CREATE TABLE `result` ( `result_id` int(11) NOT NULL AUTO_INCREMENT, `round_no` int(11) NOT NULL, `roper_id` int(11) NOT NULL, `heeler_id` int(11) NOT NULL, `time` time DEFAULT NULL, PRIMARY KEY (`result_id`) ) this code will generate the rounds for you in a result table for you to record the times (assumes ropers and heelers both have id values 1..N) <?php include("db_inc.php"); // define HOST, USERNAME etc $db = new mysqli(HOST,USERNAME,PASSWORD,'roundrobin'); // // GENERATE THE result TABLE // PAIRING EACH ROPER WITH A // DIFFERENT HEELER FOR EACH ROUND // $res = $db->query("SELECT COUNT(*) FROM rrroper"); list($numRounds) = $res->fetch_row(); for ($r=1; $r<=$numRounds; $r++) { $sql = "INSERT INTO result (round_no, roper_id, heeler_id) SELECT $r as `round` , r.sid as roper , h.sid as heeler FROM rrroper r INNER JOIN rrheeler h ON r.sid = MOD((h.sid + $r),10) + 1"; $db->query($sql); } ?>
-
What is your strategy if you get entries from, say, 12 ropers and 15 heelers?
-
$stmt->bind_param('i', intval($_GET['id'])); You need to pass an actual variable (which has an address in memory) and not a function result $id = intval($_GET['id']); $stmt->bind_param('i',$id); Although the intval() is unnecessary with bound params $stmt->bind_param('i', $_GET['id']);