[Solved] Very complicated SQL query

You can do aggregation with coalesce() : select event_id, coalesce(max(case when state=”FAILED” then ‘FAILED’ end), max(case when state=”COMPLETED” then ‘COMPLETED’ end), ‘PENDING’ ) from table t group by event_id; solved Very complicated SQL query

[Solved] i have stored array in database as a string how can retrieve that array?

use JSON_ENCODE first before saving the array to DB ,then use JSON_DECODE if you want to get again the contents $arr = array( “item_number1” => “1”, “payment_date” => “04:21:34 Dec 06, 2014 PST”, “payment_status” => “Completed”, “first_name” => “sdfsd”, “last_name” => “parsdfsdandekar”, “quantity1” => “1” ); echo json_encode($arr); Result after JSON_ENCODE (Array to JSON String): … Read more

[Solved] show sql results in php with tables [closed]

In your __construct seem you don’t call the proper function sequence for format (htlm) the row. I think you should change you __construct someway for call beginChildren, current, endChildern properly function __construct($it) { beginChildren(); parent::__construct($it, self::LEAVES_ONLY); current(); endChildren(); } solved show sql results in php with tables [closed]

[Solved] mysql – I dont understand what this means, can anyone explain each line of the script to me? [closed]

It creates a new table “students” in the database if it doesn’t exist already. Each row from ” student_id” to “Reg_date” represent one column in the table. NOT NULL next to a column means you can’t leave it empty when you insert data. “student_id” is a primary key, and is automatically incremented for each entry … Read more

[Solved] Is my SQL syntax really wrong? [closed]

Try adding white spaces between your query words and make sure you escape the input: $id = mysql_real_escape_string($id); $str = mysql_real_escape_string($str); $name = mysql_real_escape_string($name); $r=mysql_query(“INSERT INTO varta (id,data,name) VALUES (‘$id’,’$str’,’$name’);”); Or better yet – take a look at MySQLi or PDO and use prepared statements. solved Is my SQL syntax really wrong? [closed]

[Solved] php need working code as example of password hashing

Follow the examples provided in PHP the Right Way under password hashing: require ‘password.php’; $passwordHash = password_hash(‘secret-password’, PASSWORD_DEFAULT); if (password_verify(‘bad-password’, $passwordHash)) { // Correct Password } else { // Wrong password } DO NOT under any circumstances “invent” your own algorithm. These are notoriously tricky to get right and unless you have a background in … Read more

[Solved] get data from DB as range using php

For example… DROP TABLE IF EXISTS my_table; CREATE TABLE my_table (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,date DATE NOT NULL ,price INT NOT NULL ); INSERT INTO my_table VALUES (1 ,’2014-01-01′, 10), (2 ,’2014-01-02′, 10), (3 ,’2014-01-03′, 10), (4 ,’2014-01-04′, 10), (5 ,’2014-01-05′, 20), (6 ,’2014-01-06′, 20), (7 ,’2014-01-07′, 10), (8 ,’2014-01-08′, 10); SELECT … Read more

[Solved] JavaScript MySQL injection prevention [closed]

For a start, JavaScript is code that a user can actually edit using DOM tools (like inspect element) and should never be used as a mechanism to security with Databases. You should firstly start to research about prepare statements in PDO if you’re using un-trusted user input; the bind paramtter in the PDO interface automatically … Read more

[Solved] Unable to query two tables in mysql [closed]

You can make something like this: $postID = 1;//Post id we want to get from the database $getPost = $connection->query(“SELECT * FROM posts WHERE post_id=’$postID'”);//Get the post by the id $post = $getPost->fetch_assoc();//Fetch the result to an array $getUser = $connection->query(“SELECT username FROM users WHERE user_id=”.$post[‘id’]);//Get the username by using the id we got from … Read more