-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Help with designing my mysql tables before coding in PHP
Barand replied to bambinou1980's topic in MySQL Help
Yes, you are using a relational database. Do not delete products. Instead add a "deleted" flag so they are removed from sale but descriptions are still available for historical data. Not only OK but essential, as the price is also dependent on customer type. Reseller - wouln't that just be another type of customer? From your brief description, I have identified the following tables (model attached) -
How do I insert survey results into the database?
Barand replied to sonnieboy's topic in PHP Coding Help
You get them from the data posted from the form foreach ($_POST['answer'] as $qid => $choiceid) { -
How do I insert survey results into the database?
Barand replied to sonnieboy's topic in PHP Coding Help
The comments fields would also require an array index, like the answer e.g. <textarea name="comment[$row['qID']]"></textarea> So foreach ($_POST['answer'] as $qid => $choiceid) { $comment = $_POST['comment'][$id]; // get the associated comment // insert feedbackid, qid, choiceid and comment into feedback_answer } You are saving customer name etc in the customer_feedback record. The related answers have the same feedback id. (see diagram ^^) -
How do I insert survey results into the database?
Barand replied to sonnieboy's topic in PHP Coding Help
That's a lot of information that you are duplicating for every answer. Split off the answer data into a separate table +-------------------+ | customer_feedback | +-------------------+ | ID (PK) |---------+ | WorkOrderID | | | CustomerName | | +------------------+ | Org | | | feedback_answers | | Division | | +------------------+ | surveydate | +----<| feedback_id(PK) | | IPAddress | | qID (PK) | +-------------------+ | ChoiceID | | comments | +------------------+ and name = "answer[$row['qID']]" -
How do I insert survey results into the database?
Barand replied to sonnieboy's topic in PHP Coding Help
This has to fairly general as we have no idea about the table you want to inrt into. First, your radio button names need to be something like "answer[$row['qID']]" Then when you process the form foreach ($_POST['answer'] as $id => $choice) { // insert id and choice into your answer table } -
It's time to rtfm http://uk1.php.net/manual/en/function.array-unique.php
-
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