I'm starting in jquery, and I am trying to load the data from a php file to the jQuery.Gantt (http://taitems.github.io/jQuery.Gantt/). But the chart does load.
The script:
$(".gantt").gantt({
source: 'gantt_data_json.php',
navigate: "scroll",
scale: "weeks",
maxScale: "months",
minScale: "days",
itemsPerPage: 10,
....
});
The gantt_data_json.php:
require_once('libs/common.php');
$query ="SELECT * from gantt_table";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$gantt[] = array(
'name' =>$row['name'],
'desc' => $row['desc'],
'values' => array(
'to' => '/Date('.strtotime($row['to']).')/',
'from' => '/Date('.strtotime($row['from']).')/',
'desc' =>$row['desc2'],
'label' => $row['label'],
'customClass' => 'ganttRed'
)
);
}
echo json_encode($gantt);
Please could you help me to solve this issue?
Try this:
$query = "SELECT * from gantt_table";
$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
$gantt = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$data[] = array(
'name' => $row['name'],
'desc' => $row['desc'],
'values' => array(
array(
'from' => '/Date(' . $row['from'] . ')/',
'to' => '/Date(' . $row['to'] . ')/',
'desc' => $row['desc2'],
'label' => $row['label'],
'customClass' => 'ganttRed',
),
)
);
$gantt[] = $data;
}
echo json_encode($gantt);
its workfine
$json = Array();
while ($rs = mysqli_fetch_array($rsPedidos))
{
$data[] = array(
'name' => $rs['projeto'],
'desc' => $rs["site"],
$valor[] = array(
'from' => '/Date(' . strtotime($rs["data_inicio_ti"]) . '000)/',
'to' => '/Date(' . strtotime($rs["data_fim_ti"]) . '000)/',
'desc' => $rs["funcionario"].' / PO:'.$rs["numero_po"].' / R$:'.$rs["valor_po"],//12658580,//1320192000000 1497582000
'label' => $rs["servico"],
'customClass' => 'ganttRed',
),
'values' =>$valor,
);
$json = $data;
}
print json_encode($json);
Related
When I trying to update user data and let The Password Field empty it hashed again that means the password will change and you can't log in again
so is there any way to fix this problem ??
Code
$this->validate($request, [
'first_name'=> 'required|string',
'last_name' => 'required|string',
'email' => 'required|email|unique:users,email,'.Auth::id(),
'password' => 'sometimes|nullable|string|min:8,'.Auth::id(),
'avatar' => 'image|mimes:jpg,jpeg,gif,png,svg|max:2048,'.Auth::id(),
'gender' => 'required',
'country_id'=> 'required',
]);
$user = User::find(Auth::id());
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->email = $request->email;
$user->gender = $request->gender;
$user->country_id = $request->country_id;
$user->password = bcrypt(request('password'));
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/images/avatars/' . $filename ) );
$user->avatar = $filename;
}
$user->save();
return redirect()->back();
You need to check if there is a passoword in the request object first.
if($request->password){
$user->password = bcrypt(request('password'));
}
After editing it, it will be like this:
$this->validate($request, [
'first_name'=> 'required|string',
'last_name' => 'required|string',
'email' => 'required|email|unique:users,email,'.Auth::id(),
'password' => 'sometimes|nullable|string|min:8,'.Auth::id(),
'avatar' => 'image|mimes:jpg,jpeg,gif,png,svg|max:2048,'.Auth::id(),
'gender' => 'required',
'country_id'=> 'required',
]);
$user = User::find(Auth::id());
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->email = $request->email;
$user->gender = $request->gender;
$user->country_id = $request->country_id;
if($request->password){
$user->password = bcrypt(request('password'));
}
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/images/avatars/' . $filename ) );
$user->avatar = $filename;
}
$user->save();
return redirect()->back();
You can simply test on the password if it is present.
$this->validate($request, [
'first_name'=> 'required|string',
'last_name' => 'required|string',
'email' => 'required|email|unique:users,email,'.Auth::id(),
'password' => 'sometimes|nullable|string|min:8,'.Auth::id(),
'avatar' => 'image|mimes:jpg,jpeg,gif,png,svg|max:2048,'.Auth::id(),
'gender' => 'required',
'country_id'=> 'required',
]);
$user = User::find(Auth::id());
$user->first_name = $request->first_name;
$user->last_name = $request->last_name;
$user->email = $request->email;
$user->gender = $request->gender;
$user->country_id = $request->country_id;
if ($request->password) {
$user->password = bcrypt($request->password);
}
if($request->hasFile('avatar')){
$avatar = $request->file('avatar');
$filename = time() . '.' . $avatar->getClientOriginalExtension();
Image::make($avatar)->resize(300, 300)->save( public_path('/images/avatars/' . $filename ) );
$user->avatar = $filename;
}
$user->save();
return redirect()->back();
First you may change your validation rule to check if password is not empty when present:
'password' => 'sometimes|required|string|min:8',
Then bcrypt if it's not empty and present on the request vie $request->filled() method:
if ($request->filled('password'))
{
$user->password = bcrypt($request->password);
}
I'm trying to sort post by ID in ASC order, I'm able to do that when I use single query but when use array query I'm unbale to sort post by ID in ASC order my code looks like below
<?php
$ourCurrentPage = get_query_var('paged');
$newposts = new WP_Query(array(
'category_name' => 'stock-market-basics',
'orderby' => 'ID',
'order' => 'ASC',
'paged' => $ourCurrentPage
));
?>
<?php
if ($newposts->have_posts()):
while ($newposts->have_posts()):
$newposts->the_post();
?>
// Some display code and after closing code //
<?php endwhile; else : ?>
<p><?php esc_html_e( 'Sorry, no results matched your criteria.' ); ?</p>
<?php endif; ?>
<li><?php
echo paginate_links(array(
'total' => $newposts->max_num_pages
));
?></li>
WordPress query by category name
<?php $args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'author_name' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args ); ?>
// Custom query.
$query = new WP_Query( $args );
// Check that we have query results.
if ( $query->have_posts() ) {
// Start looping over the query results.
while ( $query->have_posts() ) {
$query->the_post();
// Contents of the queried post results go here.
}
}
Hope this works for you.
I am trying to get the last inserted in id MySQL but it doesn't return anything. Row is getting inserted in the database and also $wpdb->last_query gives the last inserted query also.
Here is my code
global $wpdb;
$table_name = $wpdb->prefix . "request_from";
$wpdb->insert($table_name,
array('pre' => $prefix,
'first_name' => $first_name,
'middle_name' => $middle_initial,
'last_name' => $last_name,
'badge_name' => $name_badge,
'title' => $title,
'company' => $company,
'direct_mail' => $direct_mail,
'twitter' => $twitter_handle,
'direct_phone' => $direct_phone,
'address' => $address,
'address2' => $address_2,
'city' => $city,
'state' => $state,
'province' => $province,
'zip' => $zip_code,
'country' => $country,
'cc' => $cc,
'cc_contact' => $second_contact,
'cc_mail' => $second_email,
'cc_phone' => $second_phone)
);
$x= $wpdb->last_query;
$id = $wpdb->insert_id
I have a column called id with auto increment value
id int(11) No None AUTO_INCREMENT
Follow wpdb reference in Codex for troubleshooting:
enable database error display via $wpdb->show_errors()
check what query is being formed and run via $wpdb->last_query
Please check code by print or dump variable,
global $wpdb;
$table_name = $wpdb->prefix . "request_from";
$wpdb->insert($table_name,
array('pre' => $prefix,
'first_name' => $first_name,
'middle_name' => $middle_initial,
'last_name' => $last_name,
'badge_name' => $name_badge,
'title' => $title,
'company' => $company,
'direct_mail' => $direct_mail,
'twitter' => $twitter_handle,
'direct_phone' => $direct_phone,
'address' => $address,
'address2' => $address_2,
'city' => $city,
'state' => $state,
'province' => $province,
'zip' => $zip_code,
'country' => $country,
'cc' => $cc,
'cc_contact' => $second_contact,
'cc_mail' => $second_email,
'cc_phone' => $second_phone)
);
$x= $wpdb->last_query;
$id = $wpdb->insert_id;
// Let's output the last autogenerated ID.
echo $wpdb->insert_id;
// This returns the same result
echo mysql_insert_id();
I´m trying to join 2 tables in opencart to make an sales report that specifies taxes (by class, there can be many tax%) for every order. I can only get the values from 1 table, but not 2.
How should I do this?
<?php $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order`, `" . DB_PREFIX . "order_total`");
$ordersr = array();
// Check if there are any rows returned from the query
if ($query->num_rows > 0) {
// Loop through the returned rows for processing
foreach ($query->rows as $result) {
$ordersr[] = array(
'order_id' => $result['order_id'],
'invoice_no' => $result['invoice_no'],
'total' => $result['total'],
'order_status_id' => $result['order_status_id'],
'date_added' => $result['date_added'],
'date_modified' => $result['date_modified'],
'firstname' => $result['firstname'],
'lastname' => $result['lastname'],
'payment_country' => $result['payment_country'],
'payment_method' => $result['payment_method'],
'payment_code' => $result['payment_code'],
'shipping_method' => $result['shipping_method'],
'shipping_code' => $result['shipping_code'],
'currency_code' => $result['currency_code'],
'currency_value' => $result['currency_value'],
'order_status_id' => $result['order_status_id'],
'date_payed' => $result['date_payed']
);
}
} ?>
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
SELECT and list children and parent
I received this answer from xception:
https://stackoverflow.com/a/12770593/445820
Unfortunately, GROUP_CONCAT isn't the solution for me and the other question is too extended, therefore I am re-asking this question.
I need an alternative to that query with subqueries. Since I'm not good enough with queries, this task is beyond my abilities too.
Help please.
Here is the code:
// Prepare query
$columns = "c.rule_id, c.rule_title, GROUP_CONCAT(r.rule_description ORDER BY r.rule_position ASC SEPARATOR '~sep~') AS rule_desc, ";
$columns .= "GROUP_CONCAT(r.parse_bbcode ORDER BY r.rule_position ASC SEPARATOR '~sep~') AS bbcode, ";
$columns .= "GROUP_CONCAT(r.parse_links ORDER BY r.rule_position ASC SEPARATOR '~sep~') AS links, ";
$columns .= "GROUP_CONCAT(r.parse_smilies ORDER BY r.rule_position ASC SEPARATOR '~sep~') AS smilies";
$sql_array = array(
'SELECT' => $columns,
'FROM' => array(RULES_TABLE => 'c'),
'LEFT_JOIN' => array(
array(
'FROM' => array(RULES_TABLE => 'r'),
'ON' => 'r.parent_id = c.rule_id',
),
),
'WHERE' => 'c.parent_id = 0 AND r.public = 1',
'GROUP_BY' => 'c.rule_id',
'ORDER_BY' => 'c.cat_position',
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$cat_count = 1;
$alpha_count = 'abcdefghijklmnopqrstuvwxyz';
while ($row = $db->sql_fetchrow($result))
{
$template->assign_block_vars('rules', array(
'RULE_CATEGORY' => $row['rule_title'],
'ROW_COUNT' => $cat_count,
));
$rules_ary = explode('~sep~', $row['rule_desc']);
$parse_bbcode = explode('~sep~', $row['bbcode']);
$parse_links = explode('~sep~', $row['links']);
$parse_smilies = explode('~sep~', $row['smilies']);
$counter = 0;
foreach ($rules_ary as $key => $rule)
{
$uid = $bitfield = $options = '';
generate_text_for_storage($rule, $uid, $bitfield, $options, $parse_bbcode[$key], $parse_links[$key], $parse_smilies[$key]);
$template->assign_block_vars('rules.rule', array(
'RULE_DESC' => generate_text_for_display($rule, $uid, $bitfield, $options),
'ALPHA_COUNT' => $alpha_count{$counter},
));
$counter++;
}
$cat_count++;
}
$db->sql_freeresult($result);
Some of the functions might be unknown to you. FYI this is phpBB related code.
Sorry for not adding the code in the first time.
// Prepare query
$columns = "c.rule_id, c.rule_title, r.rule_description AS rule_desc, ";
$columns .= "r.parse_bbcode AS bbcode, ";
$columns .= "r.parse_links AS links, ";
$columns .= "r.parse_smilies AS smilies";
$sql_array = array(
'SELECT' => $columns,
'FROM' => array(RULES_TABLE => 'c'),
'LEFT_JOIN' => array(
array(
'FROM' => array(RULES_TABLE => 'r'),
'ON' => 'r.parent_id = c.rule_id',
),
),
'WHERE' => 'c.parent_id = 0 AND r.public = 1',
'ORDER_BY' => 'c.cat_position',
);
$sql = $db->sql_build_query('SELECT', $sql_array);
$result = $db->sql_query($sql);
$cat_count = 0;
$alpha_count = 'abcdefghijklmnopqrstuvwxyz';
$prev_rule_id = 0;
$r_rule_titles = array();
$rule_id = null;
while ($row = $db->sql_fetchrow($result))
{
if( $rule_id != $row['rule_id'] ) {
$rule_id = $row['rule_id'];
$cat_count++;
$counter = 0;
$template->assign_block_vars('rules', array(
'RULE_CATEGORY' => $row['rule_title'],
'ROW_COUNT' => $cat_count,
));
}
$uid = $bitfield = $options = '';
generate_text_for_storage($row['rule_desc'], $uid, $bitfield, $options, $row['bbcode'], $row['links'], $row['smilies']);
$template->assign_block_vars('rules.rule', array(
'RULE_DESC' => generate_text_for_display($row['rule_desc'], $uid, $bitfield, $options),
'ALPHA_COUNT' => $alpha_count{$counter},
));
$counter++;
}
$db->sql_freeresult($result);