i write following code to copy values from one table to another table but $wpdb->get_results not returning anything.
function rating_convert() {
global $wpdb;
$likes = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'up_down_comment_vote_totals', ARRAY_N);
foreach ($likes as $like) {
$wpdb->query('UPDATE ' . $wpdb->prefix . 'comment_rating SET ck_rating_up = ' . $like['vote_count_up'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
$wpdb->query('UPDATE ' . $wpdb->prefix . 'comment_rating SET ck_rating_down = ' . $like['vote_count_down'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
}
}
i have tested every line with echo function.foreach line not running and i think $wpdb->get_results is wrong.
please help me.
Sorry for my bad english.
i solve this.
my table have 147,308 rows.
problem is table rows number.
i add LIMIT code for only get 1000 rows and remove every row after copy to another table.thanks.
function comment_rating() {
global $wpdb;
$likes = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'up_down_comment_vote_totals LIMIT 0, 1000', ARRAY_A);
foreach ($likes as $like) {
echo "id " . $like['comment_id'] . "<br>";
$wpdb->query('UPDATE ' . $wpdb->prefix . 'comment_rating SET ck_rating_up = ' . $like['vote_count_up'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
$wpdb->query('UPDATE ' . $wpdb->prefix . 'comment_rating SET ck_rating_down = ' . $like['vote_count_down'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
$wpdb->query('DELETE FROM ' . $wpdb->prefix . 'up_down_comment_vote_totals WHERE comment_id = ' . $like['comment_id']);
}
}
Related
ORDER BY is not working. I've tried ways I know but it won't order by, why?
returns : Call to a member function result_array() on boolean
public function getDetailbyClsandSection($class_id, $section_id, $exam_id) {
$query = $this->db->query("SELECT exam_schedules.*,subjects.name,subjects.type FROM exam_schedules,teacher_subjects,exams,class_sections,subjects WHERE exam_schedules.teacher_subject_id = teacher_subjects.id and exam_schedules.exam_id =exams.id and class_sections.id =teacher_subjects.class_section_id and teacher_subjects.subject_id=subjects.id and class_sections.class_id =" . $this->db->escape($class_id) . " and class_sections.section_id=" . $this->db->escape($section_id) . " and exam_id =" . $this->db->escape($exam_id) . " and exam_schedules.session_id=" . $this->db->escape($this->current_session));
return $query->result_array();
}
$query = $this->db->query("SELECT exam_schedules.*,subjects.name,subjects.type FROM exam_schedules,teacher_subjects,exams,class_sections,subjects WHERE exam_schedules.hide = 'N' and exam_schedules.teacher_subject_id = teacher_subjects.id and exam_schedules.exam_id =exams.id and class_sections.id =teacher_subjects.class_section_id and teacher_subjects.subject_id=subjects.id and class_sections.class_id =" . $this->db->escape($class_id) . " and class_sections.section_id=" . $this->db->escape($section_id) . " and exam_id =" . $this->db->escape($exam_id) . " and exam_schedules.session_id=" . $this->db->escape($this->current_session) . " ORDER BY exam_schedules.date_of_exam ASC");
I have made a database connection in php and FETCH parts like story and id.
the URL forms ok without '&' but fails when '&' is added in the URL.
Here is my php code with '&id=' added in the URL
$fullurl = /cms/page.php . '?chapter=' . $row['story'] . '&id=' . $row['id'];
Can someone put me right about the correct syntax...
The error is pretty obvious
$fullurl = /cms/page.php . '?chapter=' . $row['story'] . '&id=' . $row['id'];
should be changed so that all text is within the citation marks..
$fullurl = '/cms/page.php?chapter=' . $row['story'] . '&id=' . $row['id'];
Otherwise you will end up in an error.
Also please, consider using error_reporting(E_ALL); when debugging.
The part: /cms/page.php is not a string.... and thus is wrong. You could just change it to something like this:
<?php
// NOTICE THAT THE PART "/cms/page.php" IS NOW EMBEDDED IN QUOTES (STRING)
$fullurl = "/cms/page.php" . '?chapter=' . $row['story'] . '&id=' . $row['id'];
// OR EVEN COMPACT IT LIKES SO:
$fullurl = "/cms/page.php?chapter=" . $row['story'] . '&id=' . $row['id'];
poiz
it still didnt work but i found i dont need to fetch from NEWS_ARTICLES. In fact my variables are already fetched as you see below...
Here is my actual code.
$sql = "SELECT old,title,story,shortstory,author,origauthor,ip,timestamp,allowcomments,short,approved,viewcount,rating,archive date,neverarchive,archived,id,
" . NEWS_USERS . ".user AS authorname,
" . NEWS_USERS . ".avatar AS authoravatar,
commentcount AS comments
FROM " . NEWS_ARTICLES . " INNER JOIN " . NEWS_USERS . " ON " . NEWS_ARTICLES . ".author = " . NEWS_USERS . ".uid WHERE id IN (";
if($nocats == "1"){
$sql .= "SELECT id AS storyid FROM " . NEWS_ARTICLES . " WHERE id NOT IN (SELECT storyid FROM " . NEWS_GROUPCATS . " WHERE type = 'news') UNION ";
}
$sql .= "SELECT storyid FROM " . NEWS_GROUPCATS . " WHERE type = 'news' AND catid IN (SELECT catid FROM " . NEWS_GROUPCATS . " WHERE type = 'rss' AND storyid = ?) ) AND archived = '0' ORDER BY timestamp DESC LIMIT 0, $rssamount";
$newsstories = DataAccess::fetch($sql, $feedid);
foreach($newsstories AS $row){
if(FRIENDLY){
$fullurl = $newslocation . $prefix . $row['id'] . "-0-" . makefriendly($row[title]);
}else{
$fullurl = $newslocation . '?epic-code=' . $row['shortstory'] . '&id=' . $row['id'];
}
'&id' gives...
error on line 12 at column 85: EntityRef: expecting ';'
'id' gives...
[a link] http://www.example.com//stock-charts/share-charts.php?epic-code=ALTPid=3360
the & is missing ....
I have two scripts below. The first script only searches one Column for a user-typed keyword, then it will display the results as a list and make BOLD the characters the user typed. That script works great.
The second script is something I modified to search multiple columns. It searches just fine. The problem is that I cannot get the BOLD (or make STRONG) if the searched value came from the other columns. How do I determine if the searched value came for Column 1, Column 2, Column 3, etc...? If the searched value came from column "DESCRIP" then I want to make the letter bold in the listed value.
First Script:
<?php
require_once("../config.php");
$keyword = '%'.$_POST['keyword'].'%';
$rootval = $_POST['rval'];
$sql = "SELECT `ID`,`MUNTERS_PN`,`DESCRIP`, `IMG_PATH`, `MANUF`, `MANUF_PN` FROM `electrical_parts` WHERE `MUNTERS_PN` LIKE (:keyword) ORDER BY `MUNTERS_PN` ASC LIMIT 0, 5";
$query = $db_qms->prepare($sql);
$query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $rs) {
// put in bold the written text
$partnum = str_replace($_POST['keyword'], '<span style="font-weight:700;font-size:14px;">'.$_POST['keyword'].'</span>', $rs['MUNTERS_PN']);
// add new option
echo '<li class="set_part" data-val="' . $rs['ID'] . '"><img src="' . $rootval . '../parts/' . $rs['IMG_PATH'] . '" width="100px;" style="padding-right:15px;">'.$partnum.'<span style="font-style:italic;font-size:13px;padding-left:10px;">[' . $rs['MANUF'] . ': ' . $rs['MANUF_PN'] . '] <br/>' . $rs['DESCRIP'] . '</span></li>';
}
?>
Second Script:
<?php
require_once("../config.php");
$keyword = '%'.$_POST['keyword'].'%';
$rootval = $_POST['rval'];
$sql = "SELECT `ID`,`MUNTERS_PN`,`DESCRIP`, `IMG_PATH`, `MANUF`, `MANUF_PN` FROM `electrical_parts` WHERE (`MUNTERS_PN` LIKE (:keyword) OR `DESCRIP` LIKE (:keyword) OR `MANUF` LIKE (:keyword) OR `MANUF_PN` LIKE (:keyword) ) ORDER BY `MUNTERS_PN` ASC LIMIT 0, 5";
$query = $db_qms->prepare($sql);
$query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $rs) {
/******* INSERT CODE TO DETERMINE WHICH COLUMN WAS QUERIED ******/
// put in bold the written text
$partnum = str_replace($_POST['keyword'], '<span style="font-weight:700;font-size:14px;">'.$_POST['keyword'].'</span>', $rs['MUNTERS_PN']);
$manuf = str_replace($_POST['keyword'], '<span style="font-weight:700;font-size:14px;">'.$_POST['keyword'].'</span>', $rs['MANUF']);
$manuf_pn = str_replace($_POST['keyword'], '<span style="font-weight:700;font-size:14px;">'.$_POST['keyword'].'</span>', $rs['MANUF_PN']);
$descrip = str_replace($_POST['keyword'], '<span style="font-weight:700;font-size:14px;">'.$_POST['keyword'].'</span>', $rs['DESCRIP']);
// add new option
echo '<li class="set_part" data-val="' . $rs['ID'] . '"><img src="' . $rootval . '../parts/' . $rs['IMG_PATH'] . '" width="100px;" style="padding-right:15px;">'.$partnum.'<span style="font-style:italic;font-size:13px;padding-left:10px;">[' . $rs['MANUF'] . ': ' . $rs['MANUF_PN'] . '] <br/>' . $rs['DESCRIP'] . '</span></li>';
}
?>
Be careful, in the echo in the second script, you use $rs['MANUF'], $rs['MANUF_PN'] and $rs['DESCRIP'] instead of $manuf, $manuf_pn and $descrip.
That is why the replacements don't appear in the output.
So you should use :
echo '<li class="set_part" data-val="' . $rs['ID'] . '"><img src="' . $rootval . '../parts/' . $rs['IMG_PATH'] . '" width="100px;" style="padding-right:15px;">'.$partnum.'<span style="font-style:italic;font-size:13px;padding-left:10px;">[' . $rs['MANUF'] . ': ' . $manuf_pn . '] <br/>' . $descrip . '</span></li>';
I have a form that uses a PHP for loop after it is submitted. The loop updates individual rows in the database one after the next based on the form data submitted. However, I've noticed that the loop stops working if there are more than 31 rows that need to be updated. It will update everything perfectly for the first 31 loops but then will not work after the 31st loop?
UPDATE: I've done some testing and it seems that the loop never finishes. It just refreshes the page in the browser instead of printing the results. What is causing this?
Is there a MYSQL query setting somewhere that is causing this?
Here is my loop's code:
for($i=1;$i<=$total_results2;$i++)
{
$strSQL = 'UPDATE timesheets_items SET ';
$strSQL .= 'time_1 = "' . convert_time($_POST['item_' . $i . '_time_1']) . '"';
$strSQL .= ', time_2 = "' . convert_time($_POST['item_' . $i . '_time_2']) . '"';
$strSQL .= ', time_3 = "' . convert_time($_POST['item_' . $i . '_time_3']) . '"';
$strSQL .= ', time_4 = "' . convert_time($_POST['item_' . $i . '_time_4']) . '"';
$strSQL .= ', time_5 = "' . convert_time($_POST['item_' . $i . '_time_5']) . '"';
$strSQL .= ', time_6 = "' . convert_time($_POST['item_' . $i . '_time_6']) . '"';
$strSQL .= ', time_7 = "' . convert_time($_POST['item_' . $i . '_time_7']) . '"';
$strSQL .= ', time_8 = "' . convert_time($_POST['item_' . $i . '_time_8']) . '"';
$strSQL .= ', time_9 = "' . convert_time($_POST['item_' . $i . '_time_9']) . '"';
$strSQL .= ', time_10 = "' . convert_time($_POST['item_' . $i . '_time_10']) . '"';
$strSQL .= ', time_11 = "' . convert_time($_POST['item_' . $i . '_time_11']) . '"';
$strSQL .= ', time_12 = "' . convert_time($_POST['item_' . $i . '_time_12']) . '"';
$strSQL .= ', time_13 = "' . convert_time($_POST['item_' . $i . '_time_13']) . '"';
$strSQL .= ', time_14 = "' . convert_time($_POST['item_' . $i . '_time_14']) . '"';
$strSQL .= ', time_total = "' . convert_time($_POST['item_' . $i . '_time_total']) . '"';
$strSQL .= ', ot_1 = "' . convert_time($_POST['item_' . $i . '_ot_1']) . '"';
$strSQL .= ', ot_2 = "' . convert_time($_POST['item_' . $i . '_ot_2']) . '"';
$strSQL .= ', ot_3 = "' . convert_time($_POST['item_' . $i . '_ot_3']) . '"';
$strSQL .= ', ot_4 = "' . convert_time($_POST['item_' . $i . '_ot_4']) .'"';
$strSQL .= ', ot_5 = "' . convert_time($_POST['item_' . $i . '_ot_5']) . '"';
$strSQL .= ', ot_6 = "' . convert_time($_POST['item_' . $i . '_ot_6']) . '"';
$strSQL .= ', ot_7 = "' . convert_time($_POST['item_' . $i . '_ot_7']) . '"';
$strSQL .= ', ot_8 = "' . convert_time($_POST['item_' . $i . '_ot_8']) . '"';
$strSQL .= ', ot_9 = "' . convert_time($_POST['item_' . $i . '_ot_9']) . '"';
$strSQL .= ', ot_10 = "' . convert_time($_POST['item_' . $i . '_ot_10']) . '"';
$strSQL .= ', ot_11 = "' . convert_time($_POST['item_' . $i . '_ot_11']) . '"';
$strSQL .= ', ot_12 = "' . convert_time($_POST['item_' . $i . '_ot_12']) . '"';
$strSQL .= ', ot_13 = "' . convert_time($_POST['item_' . $i . '_ot_13']) . '"';
$strSQL .= ', ot_14 = "' . convert_time($_POST['item_' . $i . '_ot_14']) . '"';
$strSQL .= ', ot_total = "' . convert_time($_POST['item_' . $i . '_ot_total']) . '"';
$strSQL .= 'WHERE week_start = "' . $week_start . '" AND employee_id = "' . $id . '" AND project_number = "' . $_POST['item_' . $i . '_project_number'] .'" AND task = "' . $_POST['item_' . $i . '_task'] .'"';
mysql_query($strSQL);
}
I have now solved the issue ! The problem was caused by my version of PHP (5.3) and the amount of input variables allowed by PHP on a form.
The problem ended up not being MySQL related at all. The bug found was limiting how many form variables were taken in by PHP thus not allowing MySQL to ever get to see those variables when it came time to run the repeated queries loop.
To resolve the issue, I had to update to PHP (5.4 or greater) and then set the "max_input_vars" setting to 3000. (The default setting only allows 1000.)
I hope this helps anyone who ever comes across this same problem.
$query = "SELECT * FROM `status_info_private` WHERE `id`=$id ORDER BY `Status_Date` DESC LIMIT 100";
if ($query_run = mysql_query($query)) {
while ($rows = mysql_fetch_array($query_run)) {
echo '<font color="#009900" > ' . $rows['Name'] . ' ' . ' Says :' . '</font><br/>';
echo '<p align="justify> ' . $rows['Private_status'] . '<br/>';
echo '<p align="right">' . $rows['Status_Date'] . '<br/>';
$like = $rows['Like'];
$unlike = $rows['Unlike'];
}
}
I think everything is correct in the piece of code. But still I am unable to get the output under the column titled as "Private_status". The above code is producing everything correctly except the message under cols "Private_status". I have already checked the spelling of the col name & there is no error in that part.
So, Please tell me what exactly is missing ?
first close your <p> tags and then do a print_r to check what is in $rows
..
Also, start using PDO or mysqli
$query = "SELECT * FROM `status_info_private` WHERE `id`=$id ORDER BY `Status_Date` DESC LIMIT 100";
if ($query_run = mysql_query($query)) {
while ($rows = mysql_fetch_array($query_run)) {
echo '<a href="view_profile.php?id=' . $id . '" color="#009900" > ' . $rows['Name'] . ' ' . ' Says :' . '</a><br/>';
echo '<p align="justify"> ' . $rows['Private_status'] . '</p>';
echo '<p align="right">' . $rows['Status_Date'] . '</p>';
$like = $rows['Like'];
$unlike = $rows['Unlike'];
}
}