-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
You can read? I already told you. Do not use SELECT *. The table has an id field that is not in the list of fields to insert, therefore by using * you are trying to insert at least one more field than the number of fields specified.
-
DON'T use "SELECT * ", it will include the id field. Always specify the fields you want to select.
-
mysql> SELECT * FROM attachments; +--------+--------+ | field1 | field2 | +--------+--------+ | 1 | abc | | 2 | def | +--------+--------+ What you are effectively attempting to do is mysql> INSERT INTO attachments (field1, field2) VALUES (1, 'xyz'); ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY' It will only auto_increment if you don't try to provide a value mysql> INSERT INTO attachments (field2) VALUES ('xyz'); Query OK, 1 row affected (0.00 sec) mysql> select * from attachments; +--------+--------+ | field1 | field2 | +--------+--------+ | 1 | abc | | 2 | def | | 3 | xyz | +--------+--------+
-
You cannot have two rows with the same primary key which is what you are attempting to do.
-
In addition you could add a "required" attribute to the input fields in the form which will improve the user interface in those browsers that support it.
-
You haven't told it which columns to match on when doing the joins so you will get every row in each table joined with every row in the other tables (a cartesian join) so if you have x students, y groups and z instructors your query will return x * y * z rows
-
In answer to your question in the title SELECT i.name as i_name , g.group_id , g.code , s.student_id , s.name as st_name , s.username as st_uname , s.password as st_pwd FROM student s INNER JOIN stud_group g USING (group_id) INNER JOIN instructor i USING (instructor_id) ORDER BY i_name, group_id hint : avoid "group" as a table or column name - it's a reserved word
-
((x)n%) would be ($x * $n /100)
-
Add in some multiplication operators and divisions by 100
-
At present you are setting the click function in the "ready" function after the page loads. At this point your form doesn't yet exist so the function is applied to a non-existent object. When you later create the form you now have a new object with no click function. So you need to set the click function after creating the form. In your ajax function where you write the form content, add the code to create the click function.
-
You have to set events (like onclick) for the form objects after creating those form objects
-
Have you tried searching this forum for the word "quiz"
-
$comp = array( 'aaa' => 'bbb', 'ccc' => 'ddd', 'eee' => 'fff', 'bbb' => 'ggg', 'hhh' => 'kkk', 'mmm' => 'nnn', 'ppp' => 'qqq', 'rrr' => 'sss', 'ttt' => 'ccc' ); $search = 'kkk,ccc,bbb'; tester($comp, $search); function tester ($comp, $search) { ksort($comp); $asrch = explode(',', $search); // convert to array foreach ($comp as $k=>$v) { if (in_array($k, $asrch) || in_array($v, $asrch)) { echo "<strong>$k => $v</strong><br>"; } else { echo "$k => $v<br>"; } } }
-
Quick question. How can I increment a unique username variable?
Barand replied to helloworld001's topic in PHP Coding Help
You could run a query to count the jonsmiths SELECT COUNT(*) as count FROM user WHERE username LIKE 'johnsmith%' Append the returned count to the username, so first gets johnsmith, second gets johnsmith1 etc In addition, add a UNIQUE constraint to the username column. In the event two johnsmiths register simultaneously you will then get an error, in which case repeat the process. -
pseudocode get input for each array element if matches input print bold else print plain end if end for
-
Could be because galI_id in the ORDER BY is ambiguous and I put the WHERE after ORDER (Ooops!) Try SELECT gallery.gal_id , gname , img_id , img_name FROM gallery INNER JOIN images ON images.gal_id=gallery.gal_id WHERE gallery.user_id = $whatever ORDER BY gallery.gal_id DESC LIMIT $eu,$limit
-
Put a check in there $ch = curl_init('https://btc-e.com/api/3/depth/ltc_btc'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); $result = curl_exec($ch); if (!$result) { exit("cURL failed"); } $array = json_decode($result, 1); $asks = $array['ltc_btc']['asks']; sort($asks); echo '<pre>', print_r($asks, true), '</pre>';
-
Have you added a new line 16 and forgotten the ; at the end of the line?
-
$data = '{"ltc_btc":{"asks":[[0.00757,109.7613],[0.00758,83.72171025]],"bids":[[0.00754,0.782],[0.00753,283.68702632],[0.00752,608.06368173],[0.00751,1058.66307725],[0.0075,692.06028608]]}}'; $arr = json_decode($data, 1); $asks = $arr['ltc_btc']['asks']; sort($asks); echo '<pre>',print_r($asks, true),'</pre>'; result Array ( [0] => Array ( [0] => 0.00757 [1] => 109.7613 ) [1] => Array ( [0] => 0.00758 [1] => 83.72171025 ) )
-
It was working when it left the shop EG mysql> SELECT * FROM test_time; +------------+ | time | +------------+ | 1424476800 | | 1424480400 | | 1424484000 | | 1424487600 | | 1424491200 | | 1424494800 | | 1424498400 | | 1424502000 | | 1424505600 | | 1424509200 | | 1424512800 | | 1424516400 | | 1424520000 | | 1424523600 | | 1424527200 | | 1424530800 | | 1424534400 | | 1424538000 | | 1424541600 | | 1424545200 | | 1424548800 | | 1424552400 | | 1424556000 | | 1424559600 | +------------+ mysql> SELECT -> time -> , FROM_UNIXTIME(time) -> FROM test_time -> WHERE HOUR(NOW()) = HOUR(FROM_UNIXTIME(time)); +------------+---------------------+ | time | FROM_UNIXTIME(time) | +------------+---------------------+ | 1424556000 | 2015-02-21 22:00:00 | +------------+---------------------+
-
Seems easier to select those where the current hour matches the hour they signed up SELECT ... WHERE HOUR(NOW()) = HOUR(FROM_UNIXTIME(opt_time))
-
In which case you would use $asks = $array['ltc_btc']['asks'];
-
And even if they were, they would be arrays and not string values. I find if difficult to see how you came up with that code after requinix gave you the working solution