PHP - Search, Sql Order By Priority Of The Searched Term ?
i want to sort the available words by the "searched word"...is there any way ?
Code: [Select] <?php $query = "SELECT * FROM ce_cour_chap WHERE nom LIKE'%$find%' ORDER BY nom"; $result = mysql_query($query); while($search = mysql_fetch_array( $result )) { echo $search['nom']." - ".$search["chid"]."<br/>"; } ?> Similar TutorialsHere's the query: Code: [Select] $sql = mysql_query("SELECT * FROM resources WHERE gameCat = '' ORDER BY systemCat,order_id"); I want something to happen when the systemCat changes in the results. Like this: Code: [Select] if($row['systemCat'] CHANGES){ echo '<div id="seperator"></div>'; } Any ideas? Thank you! I would like to know how to do search terms. For example, someone key in the terms in the text field, and click search, thn it will show the data. I've got a search page that spits out results that match the term that was input. Within the results, I want to add a span with a yellow background behind just the search term. I'll show my code, then say my problem Code: [Select] <?php $search = (term in $_GET variable that was searched for); // while loop that goes through all results, $result is the text that the searched term was found in $new_result = str_ireplace($search, "<span style='background:yellow'>$search</span>", $result); echo $new_result; // end while loop ?> my problem is that if somebody searches for the word "bob", then if the term "Bob" was found, when it outputs the $new_result, it shows as "bob" with the yellow background. Searching for "Bob" would give the correct results("Bob" with a yellow background), but basically when the output is given, the case of each letter is displayed as it was typed in the search field. I want to let user to choose the checked box, so they will type in the words in the box, and select the radio button to limit their search. How should I approach it? $search_words = mysql_real_escape_string($_POST['search_words']); $query = "SELECT name,login_id,password,email FROM User WHERE name LIKE '".$search_words."%' ORDER BY name ASC"; // my query to display the necessary fields $result = mysql_query($query, $conn);//get results $result2 = mysql_query($query, $conn);//get results $resultCheck = mysql_result($result2,0,0); ?> <p align="center" class="passwordsummary_header"> User's Password Summary <table width="302" border="1" align="center"> <tr> <td width="229"> <form method="post" action="search.php" id="searchform"> <div align="center" class="label"> <p>Search: <input name="search_words" type="text" id="search_words" size="30" maxlength="20" /> <input type="submit" name="GO" id="GO" value="Go" /> </p> <p> <input type = "radio" name = "namesearch" id = "namesearch" value = "AM" <?php if($name == 'namesearch') {echo "checked";}?> > name search</input> <input name = "loginidsearch" type = "radio" id = "loginidsearch" value = "loginidsearch" <?php if($login_id == 'loginidsearch') {echo 'checked';}?>>loginid search<br /> <input type = "radio" id = "emailsearch" name = "emailsearch" value = "emailsearch" <?php if($email == 'emailsearch') {echo 'checked';}?>> email search </input> </div> </form> </td> </tr> </table> </p> <?php if ($search_words != "" && $resultCheck != "") { echo "<table width='650' border='1' align='center' cellspacing='1'> <tr><tr> <td class='passwordsummary_label'>No</td> <td class='passwordsummary_label'>Name</td> <td class='passwordsummary_label'>Login ID</td> <td class='passwordsummary_label'>Password</td> <td class='passwordsummary_label'>Email</td> </tr>"; $i = 1; while ($row = mysql_fetch_row($result)) //use loop to get the results { $name = $row['0']; $login_id = $row['1']; $password = $row['2']; $email = $row['3']; ?> <td class="passwordsummary_info"><?php echo $i;?></td> <td class="passwordsummary_info"><?php echo $name;?></td> <td class="passwordsummary_info"><?php echo $login_id;?></td> <td class="passwordsummary_info"><?php echo $password;?></td> <td class="passwordsummary_info"><?php echo $email;?></td> </tr> <?php $i++; } echo "</table>"; } else { echo '<p class="results">No search results</p>'; } Hi guys, I have this SQL query which I use in my PHP search script Code: [Select] $query_for_result=mysql_query("SELECT * FROM customer WHERE c_name like '%".$query."%' OR c_telephone like '%".$query."%' OR c_address like '%".$query."%'"); It works fine, the only problem is now my database is bigger I would like to be able do SORT or ORDER BY id so that my search results are in order from asc to desc. Is this possible? if so can you help me. Thanks I'm not sure where to exactly begin with this query, but here's the objectives:
Column A values: 3, 5, 7, 9, 21
Column B value: 2
Column User: $id
Perform an if on each separate column A while ran in a batch process to speed up the query
Hi, I have the admin module, there i would like to save the searched results, how to save my searched rows , how to do it, Help appreciated, thank you Hey, I have a search feature that searches for words in my database. I am currently storing all searches that users make in a table called `search`. I need to list the top 10 words that are searched for the most, excluding common words like "the, and, or, etc". Because the searches users make are stored into a table, it should be fairly easy. Could anyone give an example of how to do this? Here's how my sql table looks: table name: search columns: id (autoincrement) phrase date resultsfound ip Hi all, I'm brand new to php / mysql and I'm trying to modify this script which currently runs a search on two fields "product_number" and "product_name". I also want the search to consider a third field "product_type". When I remove either product_name or product number from the following part of the code, it removes that field from being considered in the search: Code: [Select] $search_map = array($orderby, 'product_number','product_name',); So shouldn't I be able to just add the third field's name to this array and have it be considered too? I'm a complete beginner so I'm hoping this is a simple fix and I just dont get it. Here's the rest of what I think is the relevant code: Code: [Select] function load_all_products() { global $AppUI; global $sorted_item_list; global $additional_pfilter; load_type_list(); $orderby = 'product_id'; $search_map = array($orderby, 'product_number','product_name',); $where = $AppUI->getState( 'QuoteIdxWhere' ) ? $AppUI->getState( 'QuoteIdxWhere' ) : '*'; $not =" "; $op = " OR"; $check = substr(trim($where),0,4); if(stristr($check,"NOT")){ $op ="AND"; $not = " NOT "; $where = substr(trim($where),4); $where = trim($where); } // assemble the sql statement $q = new DBQuery; $q->addTable('products'); $q->addJoin('companies', 'com', 'products.product_company_id = com.company_id'); $q->addJoin('users', 'u', 'products.product_owner = u.user_id'); $q->addQuery('products.*, com.company_name, u.user_username'); $where_filter = " "; foreach($search_map as $search_name) $where_filter .=" $op $search_name $not REGEXP '$where'"; $where_filter = substr($where_filter, 5); // echo $where_filter; if($where != "*") $q->addWhere("($where_filter)"); $q->addOrder('product_id'); $sql = $q->prepare(); $q->clear(); $sql_list = db_exec( $sql ); if ($sql_list) $rn = db_num_rows( $sql_list ); else { echo db_error(); $rn = 0; } $product_list = array(); foreach ($sql_list as $item) { $product_list[ $item[ 'product_id' ] ] = $item; } // sort the list global $sort_state; if ( !isset( $sort_state ) ) $sort_state = getProductSortState(); if ( isset( $sort_state[ 'sort_item1' ] ) ) { if ( isset( $sort_state[ 'sort_item2' ] ) ) { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval( $sort_state['sort_order1'] ) , $sort_state[ 'sort_item2' ], intval( $sort_state['sort_order2'] ) ); } else { $sorted_item_list = array_csort2( $product_list, $sort_state['sort_item1'], intval($sort_state['sort_order1']) ); } } else $sorted_item_list = array_csort2( $product_list, 'product_id' ); } Thanks! Is 'password' a protected/resevred term in either PHP or HTML? Is this code valid... Quote <li> <label for="password"> <em><img src="images/required.png" alt="required" /></em> Password: </label> <input id="password" name="password" class="text" type="password" /> </li> TomTees Hey guys im looking to do a drop down menu which is pretty basic however, in this drop down menu it uses an array of 4 values eg Orange, Apples, Bananas, Strawberry's. For this menu if a user has previously chosen an Orange which is stored on the db then then when the drop down menu is loaded it should move Orange to the top of the list, the same applies for the other values. How could I do this? I know how to do the select statement and place the values in an array. from there I dont know quite how to approach it. () Thank you. I'm sure this is possible, but I'm not having any luck. Code: [Select] $array = array("11:23", "12:46", "13:34", "14:34", "14:85"); if (in_array('12', $array)) { echo "yes"; } else { echo "no"; }} Is PHP used to create this type is feature? I already have a MYSQL table set up, how difficult is it to create this sort of feature? On this image, where it says 'filter your results' if a user clicks 'Detached Houses' then only detached houses will be displayed. if a user clicks 'Semi-detached' then only semi detached houses will be shown. Whats the technical term for this type of feature, and can you point me towards any tutorials etc, would really appreciate it. thank you! i am storing my menu in the database, i want to be able to output it by priority, heres so far what i have. I have no idea were to start. Database dump: -- -- Table structure for table `menu` -- CREATE TABLE IF NOT EXISTS `menu` ( `menu_access_lvl` int(2) NOT NULL, `priority` int(11) NOT NULL, `name` varchar(200) NOT NULL, `comment` text NOT NULL, `location` text NOT NULL, `creator_id` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `menu` -- INSERT INTO `menu` (`menu_access_lvl`, `priority`, `name`, `comment`, `location`, `creator_id`) VALUES (0, 1, 'Home Page', 'Home page', 'index.php', 'admin'), (0, 3, 'Contact', 'Contact', 'index.php?PG=contact', 'admin'), (0, 2, 'Events & Meetings', 'Events & Meetings', 'index.php?PG=events', 'admin'), (0, 4, 'About', 'About', 'index.php?PG=about', 'admin'), (2, 5, 'Admin', 'Admin', 'index.php?PG=admin', 'admin'); And here is the php code displaying it //gets the role of the user if set, otherwise role = 0 if(isset($_SESSION['SESS_MEMBER_ID']))$lvl = $_SESSION['SESS_ROLE']; else $lvl = 0; // this loads the menu buttons that correspond to the users role $menuqry="SELECT * FROM menu WHERE menu_access_lvl<='$lvl'"; $menuresult=mysql_query($menuqry); while($row = mysql_fetch_array($menuresult)){ echo "<li class=\"menuitem\"><a href=\"".$row['location']."\">".$row['name']."</a></li>"; } What this currently displays: Home Contact Events & meetings About I want it to be according to priority in the menu like: Home Events & meetings Contact About I have a list of x,y coordinates. (drill positions) I have Three Primary x,y co-ords. (station positions) I want to assign drill positions to stations based on how close they are and the priority of the station(1, 2 or 3). I also want the option of making all stations have a priority or 1 so they divide equally.(for drill positions that are close to two stations) I have absolutely no idea how to tackle this. Is there a formula anyone is aware of? Can anyone even attempt to show me how to tackle this. I am 100% lost. If I have three files such as the following, and put session_start() in each, the session cookie will be domain: "mydomain.com" and path "/". As such, the session will be shared between all three files.
http://mydomain.com/index.php http://mydomain.com/folder1/index.php http://mydomain.com/folder1/folder2/index.phpIf I want the cookie to be unique to each file, then it seems I have several options. I could use session_name() to give the cookie a unique name for each file. I could use session_set_cookie_params() to set a unique path for each (/, /folder1, /folder1/folder2), however, the index files in the children directories will also be sent the root directories session cookie, right? Will this cause problems? Should both approaches be implemented? Or is there another approach? Thanks Hey all, I am in a situation where database management system needs to be up and running very quickly, which would store records of addresses possibly from all the properties in a particular US state. But it would only be 1 US state, not all. These records need to be updated and retrieved for particular campaigns. The programming solution (e.g. PHP) would need to be able to import csv files generated from excel and match the records in the database in order to know which fields to update. It seems like a lot of work to do this from scratch using PHP in the short-term, given time limitations. Hence, I was considering using Microsoft Access as a front end in the interim and then when time is available writing a web-based PHP/MySql application using HTML, CSS, and JavaScript front end to allow users to easily perform data entry. Does anyone think this is a smart course of action? Ideally a web PHP app would be more robust, but considering it needs to be done from scratch, it would be time consuming. There's no right or wrong answer for this. I'm just looking for opinions. Thanks for any response.
Hi everyone. I'm very new into self learning programming. Presently I'm trying to develop a simple basic Robot that would only Place a Market Order every seconds and it will cancel the Order every followed seconds. Using the following library: It would place Trade Order at a ( Price = ex.com api * Binance api Aggregate Trades Price) I have already wrote the api to call for xe.com exchange rate with php <?php $auth = base64_encode("username:password"); $context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ] ]); $homepage = file_get_contents("https://xecdapi.xe.com/v1/convert_from?to=NGN&amount=1.195", false, $context ); $json = json_decode($homepage, TRUE); foreach ($json as $k=>$to){ echo $k; // etc }; ?> And also for the Binance Aggregate Price in JavaScript
<script> var burl = "https://api3.binance.com"; var query = '/api/v3/aggTrades'; query += '?symbol=BTCUSDT'; var url = burl + query; var ourRequest = new XMLHttpRequest(); ourRequest.open('GET',url,true); ourRequest.onload = function(){ console.log(ourRequest.responseText); } ourRequest.send(); </script>
My problem is how to handle these two api responds and also the functions to use them to place a trade and cancel it. Currently, I am trying to make my URL shortener script able to track UTM variables from Google Analytics. I also want to provide my own (campaign/keyword/source/etc...) variables. I am trying to sift through $_GET, pick out "approved" key/value pairs and set each key with the condition that UTM variables take higher precedence (I only want to store one value in the database). My code is currently: Code: [Select] //Parse $_GET and only get the key/pairs that we need and store them in global $url_params for use through out the script function set_url_params($allowed=NULL) { // $allowed is arg to add new values in future dev global $url_params; $allowed = array( 'l', // Redirect key (e.g http://example.com?l=a1dFd7) 'utm_campaign', 'campaign', 'utm_source' , 'source', 'utm_medium', 'medium', 'utm_term', 'term', 'keyword', 'kw', ); $approved = array_intersect_key($_GET, array_flip($allowed)); foreach($approved as $key => $value) { strip_tags(urldecode(trim($value))); $url_params[$key] = $value; } //Assign variables to global $url_params variable so other functions can use them. //NOTE: Google Analytics UTM parameters take precedence over script values. $url_params['l'] = isset($approved['l']) ? $approved['l'] : NULL ; $url_params['campaign'] = isset($approved['utm_campaign']) ? $approved['utm_campaign'] : $approved['campaign']; $url_params['source'] = isset($approved['utm_source']) ? $approved['utm_source'] : $approved['source']; $url_params['medium'] = isset($approved['utm_medium']) ? $approved['utm_medium'] : $approved['medium']; $url_params['term'] = isset($approved['utm_term']) ? $approved['utm_term'] : $approved['term']; $url_params['keyword'] = isset($approved['keyword']) ? $approved['keyword'] : $approved['kw']; // Just in case $url_params doesn't have a 'keyword' set, we will use 'term' instead. $url_params['keyword'] = isset($url_params['keyword']) ? $url_params['keyword'] : $url_params['term']; } I basically want to find a cleaner way of doing this without all the isset()'s. I also get NOTICE errors (running in E_ALL) for undefined variables that I would like to unset so I don't get those errors. Any help would be appreciated. Thanks. I've got. |