I have a custom field called code on Accounts module and I want to enable it on the Global Search such that its searches without wildcards entered in the search bar.
So suppose I have some records with values like "88990","23477" and "12347".
If some one uses global search and enters 347 it should return me the account with code 23477 and 12347.
I dont want to enter %347 yo the the results.
How can I achieve this?
I have code on
custom/Extension/modules/Account/Ext/Vardefs/sugarfield_code_c.php
$dictionary['Account']['fields']['code_c']['inline_edit']='1';
$dictionary['Account']['fields']['code_c']['labelValue']='test code';
$dictionary['Account']['fields']['code_c']['unified_search']=true;
and on custom/modules/Accounts/SearchFields.php I have
$searchFields['Accounts'] = array(
'code_c' =>
array(
'query_type' => 'default'
)
);
SuiteCRM Version: 7.10.4
Solution is NOT upgrade safe.
Navigate to include/SearchForm/SearchForm2.php and look for the following inside the generateSearchWhere() function:
$where .= $this->seed->db->concat($concat_table, $concat_fields) . " LIKE " . $this->seed->db->quoted($field_value . $like_char);
$where .= ' OR ' . $this->seed->db->concat($concat_table, array_reverse($concat_fields)) . " LIKE " . $this->seed->db->quoted($field_value . $like_char);
I changed this line to concatenate the $like_char variable before $field_value:
$where .= $this->seed->db->concat($concat_table, $concat_fields) . " LIKE " . $this->seed->db->quoted($like_char . $field_value . $like_char);
$where .= ' OR ' . $this->seed->db->concat($concat_table, array_reverse($concat_fields)) . " LIKE " . $this->seed->db->quoted($like_char . $field_value . $like_char);
Related
I already searched for my answer, but all of the solutions do not fit to my problem. I want to build a forum, where first of, all questions are requested from my MySQL database. Then I want to find out the date of the latest entry for each question, so I created this:
while ($array = mysqli_fetch_assoc($res_page)) {
$get_latest_date = "select * from forum"
. " where id = "
. $array["id"]
. ' order by date DESC'
. ' limit 1';
$latest_date = mysqli_query($con, $get_latest_date);
$date = mysqli_fetch_row($latest_date);
echo '<div class="forum_preview">'
. '<a href=#" class="forum_preview_question">'
. $array["question_short"]
. '</a>'
. '<p class="forum_preview_date">'
. $date["date"]
. '</p>'
. '<p class="forum_preview_comments">'
. $number_of_questions
. '</p>'
. '</div>';
}
My problem is, that showing the latest date is not working, because I cannot get the result out of my mysqli_query.
Can anybody show me where my mistake is or does anybody have another idea?
I think what you are looking for is mysqli_fetch_assoc, mysqli_fetch_row returns an array, mysqli_fetch_assoc returns an associative array so you can get data by keys.
$latest_date = mysqli_query($con, $get_latest_date);
$date = mysqli_fetch_assoc($latest_date);
echo $date["date"];
I tried to use mysqli in for my forum database. this is the code I used:
<meta charset="utf-8">
<?php
include("config.php");
$limits = "6";
$forum_id = "2";
$db = new mysqli($INFO['sql_host'], $INFO['sql_user'], $INFO['sql_pass'], $INFO['sql_database']);
$topics = $db->query("
SELECT
`topics`.`start_date`,
`topics`.`title`,
`topics`.`starter_name`,
`topics`.`posts`,
`topics`.`title_seo`,
`topics`.`tid`,
`posts`.`post`
FROM
`" . $INFO['sql_tbl_prefix'] . "topics` as `topic`,
`" . $INFO['sql_tbl_prefix'] . "posts` as `post`
WHERE
`topics`.`approved` = 1 AND
`topics`.`forum_id`= " . $forum_id . " AND
`posts`.`topic_id` = `topic`.`tid` AND
`posts`.`new_topic` = 1
ORDER BY
`topics`.`start_date`
DESC LIMIT 5");
echo '<ul id="news">';
while ($topic = $topics->fetch_object()) {
$url = $INFO['board_url'] . '/index.php?/topic/' . $topic->tid . '-' . $topic->title_seo . '/';
$topic->post = strip_tags(str_replace(array('[', ']'), array('<', '>'), $topic->post));
$topic->start_date = date("Y.m.d H:i", $topic->start_date);
echo '
<div class="news">
<div class="newsp"><div class="pteksts">' . $topic->title . '</div></div>
<center><img src="img/news.png"></center>
<div class="teksts" style="padding-bottom: 5px;">' . $topic->post . '</div>
</div>
';
}
echo '</ul>';
?>
and errors i received:
Fatal error: Call to a member function fetch_object() on a non-object in /home/public_html/scripts/news.php on line 35
You give aliases for your tables as topic and post, but then you use the aliases topics and posts. You need to change the table qualifiers to use the same spelling as your table alias.
Wrong, because alias topic is not the same as table qualifier topics:
SELECT
`topics`.`start_date`, . . .
FROM
`" . $INFO['sql_tbl_prefix'] . "topics` as `topic`,
. . .
Right, after changing the table qualifier to match the alias name:
SELECT
`topic`.`start_date`, . . .
FROM
`" . $INFO['sql_tbl_prefix'] . "topics` as `topic`,
. . .
Right as well, but alias is unnecessary if it's the same as the base table name:
SELECT
`topics`.`start_date`, . . .
FROM
`" . $INFO['sql_tbl_prefix'] . "topics` as `topics`,
. . .
But more to the point, you should always check the return value from $db->query(), because it returns false if there's an error. You can't call any method on a false because that's not an object.
If that happens, report the error but do not try to fetch from the result. It won't work.
$topics = $db->query(...);
if ($topics === false) {
die($db->error);
}
// now we can be sure it's safe to call methods on $topics
while ($topic = $topics->fetch_object()) {
. . .
Re your comment that the output is blank:
I just tested this script and it mostly works, so I can't guess what's going wrong. I suggest you read your http server's error log, which is where many PHP notices and errors are output.
I do see the following notice:
Notice: A non well formed numeric value encountered in /Users/billkarwin/workspace/SQL/22159646.php on line 51
The line is this:
$topic->start_date = date("Y.m.d H:i", $topic->start_date);
The problem is that PHP's date() function takes an integer timestamp, not a date string.
You might want to format the date in SQL, using MySQL DATE_FORMAT() function instead.
There is nothing wrong with my code, but I just cant help but wonder, should I wrap the $key with mysql_real_escape_string? This is just part of my Database function which is mainly used to pull data out of the database with table name and $where as arguments to the function. $where is to be an associative array with keys being column name, and values being the data.
This is what processes the $where array. Before this I have $sql = 'select * from ' . $table;
if(!empty($where)){
$where_count = count($where);
$sql .= ' WHERE ';
foreach($where as $key => $value){
$split_key = explode(' ', $key);
if(count($split_key) > 1){
$sql .= $key[0] . ' ' . $key[1] . ' "' . mysql_real_escape_string($value) . '" ';
} else {
$sql .= $key . ' = "' . mysql_real_escape_string($value) . '" ';
}
}
}
Filter ANY INPUT from the user that is going to be placed in your query. No doubt!
So if the keys are supplied by the user, YES and if they are generated in a safe manner, NO.
Take a look at SQL Injection to understand why filtering must be done.
I am not sure what is being asked here, but I can see one error:
$sql .= $key[0] . ' ' . $key[1] . ' "' . mysql_real_escape_string($value) . '" ';
should be
$sql .= $split_key[0] . ' ' . $split_key[1] . ' "' . mysql_real_escape_string($value) . '" ';
If you really want to quote field names, use backticks.
See http://dev.mysql.com/doc/refman/5.6/en/identifiers.html
The following statement creates a table named a`b that contains a
column named c"d:
CREATE TABLE `a``b` (`c"d` INT);
I have indexed a site using Nutch and now I am searching the index using the Zend Lucene library.
I've actually pulled the Zend libraries into Codeigniter but it is all Zend doing the work.
I can display the title, score and url fine but I can't find the name of the field to display the content from the page.
So far I have the following code
$index = new Zend_Search_Lucene('C:\nutch\nutch-0.9\my-search\index');
$query = $this->input->post('searchQuery');
$hits = $index->find($query);
echo "<p>Index contains " . $index->count() . " documents.</p>";
echo "<p>Search for '" . $query . "' returned " . count($hits) . " hits</p>";
foreach ($hits as $hit)
{
echo "<h4>" . $hit->title . "</h4>";
echo "<p><b>Score:</b> " . sprintf('%.2f', $hit->score) . "</p>";
echo "<p><b>Url:</b> " ."<a href='" . $hit->url . "'>" . $hit->url. "</a></p>";
}
Can anyone help out with the name of the field to display the content or a content summary?
Thanks
I don't know the nutch index format, but whenever I need to check a lucene index I use Luke - Lucene Index Toolbox
It allows you to open an index directory, browse fields and run queries. Very helpful if you're using an unfamiliar index.
I am able to generate the activation_key in the following code. But I can't manage to insert it into the table. Blank value gets inserted into the table.
What am I doing wrong? (using PEAR text password and other extensions)
$activation_key = Text_Password::createFromLogin($data['email'], 'rot13');
$sql = "INSERT INTO auth (firstname, lastname,gender,dob,mobileno,landlineno,addressline1,addressline2,addressline3,country,state,city,pincode,email,username,password,question,answer,activation_key)
VALUES ('" . $db->escapeSimple($data['firstname']) . "','"
. $db->escapeSimple($data['lastname'])."','"
. $db->escapeSimple($data['gender'])."','"
. $db->escapeSimple($data['dob'])."','"
. $db->escapeSimple($data['mobileno'])."','"
. $db->escapeSimple($data['landlineno'])."','"
. $db->escapeSimple($data['address1'])."','"
. $db->escapeSimple($data['address2'])."','"
. $db->escapeSimple($data['address3'])."','"
. $db->escapeSimple($data['country'])."','"
. $db->escapeSimple($data['state'])."','"
. $db->escapeSimple($data['city'])."','"
. $db->escapeSimple($data['pin'])."','"
. $db->escapeSimple($data['email'])."','"
. $db->escapeSimple($data['username'])."','"
. md5($db->escapeSimple($data['pwd']))."','"
. $db->escapeSimple($data['question'])."','"
. $db->escapeSimple($data['answer']). "', '"
. $db->escapeSimple($data['activiation_key'])."')";
$db->query($sql);
$data['$activiation_key'] doesn't actually appear to hold $activation_key
plus if you really cut and paste then $activiation_key is spelt wrongly