Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'search'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 10 results

  1. Hello all, I am busy with a complete user management script and have the following questions: Is it good practice to combine the "view users" and "search users" scripts in the same PHP file? How do I amend the "SELECT COUNT(user_id) FROM users" query for pagination purposes to accommodate the search functionality? In its current form it continues to displays ALL the pagination links after a search query. Is there a more efficient way to formulate the following search query: "SELECT u.user_id, u.username, u.type, c.country, u.email, u.status, DATE_FORMAT($date_created, '%Y-%m-%d %H:%i:%s') AS dc FROM users AS u INNER JOIN countries AS c USING (country_id) WHERE lang_id = {$_SESSION['lid']} AND u.username LIKE '%" . $terms[0] . "%' OR u.type LIKE '%" . $terms[0] . "%' OR c.country LIKE '%" . $terms[0] . "%' OR u.email LIKE '%" . $terms[0] . "%' OR u.status LIKE '%" . $terms[0] . "%' OR date_created LIKE '%" . $terms[0] . "%' ORDER BY $order_by LIMIT $start, $display" I have searched online but could not find any workable solutions. Any help will as always be much appreciated.
  2. I have built a forum for my own website thanks to the forum example in this book in chapter 17. Now I want the capability to search through posts and show the results of the search. I modified the search.php script included in the course files. I tested it and it doesn't work properly, the $_GET['terms'] doesn't get set when I type in search terms and click search. I tested it by echoing out 'hello' after the isset($_GET['terms']) . I don't know why it isn't set though, in the address bar it is written search.php?terms=test&submit=Submit <?php # Script 17.8 - search.php // This page displays and handles a search form. // Include the HTML header: // Show the search form: echo '<form action="search.php" method="get" accept-charset="utf-8"> <p><em>Search </em>: <input name="terms" type="text" size="30" maxlength="60" '; // Check for existing value: if (isset($_GET['terms'])) { echo 'value="' . htmlspecialchars($_GET['terms']) . '" '; } // Complete the form: echo '/><input name="submit" type="submit" value="' . $words['submit'] . '" /></p></form>'; if (isset($_GET['terms'])) { // Handle the form. echo 'hello'; // Clean the terms: $terms = mysqli_real_escape_string($dbc, htmlentities(strip_tags($_GET['terms']))); // Run the query... $q = "SELECT message FROM posts WHERE MATCH (message) AGAINST ('test' IN BOOLEAN MODE)"; $r = mysqli_query($dbc, $q); if (mysqli_num_rows($r) > 0) { $row = mysqli_fetch_array($r, MYSQLI_ASSOC); echo '<h2>Search Results</h2>'; echo '<p>' . $row['message'] . '</p>'; } else { echo '<p>No results found.</p>'; } } ?>
  3. The problem I have is that I am returning a subset of data from the User table to a view. Using TbGridView I should be able to type in a search term and this data should be filtered by my search term however the data is not filtered. The same data is simply retuned. The filtering is not working. I have an action in my User controller to show a list of users that have previously logged in. The action is public function actionLoginhistory() { $model=new User('searchlogin'); $model->unsetAttributes(); // clear any default values if(isset($_GET['User'])) { $model->attributes=$_GET['User']; } $this->render('loginlist', array( 'model'=>$model, )); } This returns the correct data set to my view. The problem is that when I try to filter the data by typing in a search term in the Trading Name column or Email column the same data set is returned. The view code is: $this->widget('bootstrap.widgets.TbGridView', array( 'type' => 'striped bordered condensed', 'dataProvider' => $model->searchlogin(), 'filter'=>$model, 'ajaxUpdate'=>false, 'enablePagination'=>true, 'summaryText'=>'Displaying {start}-{end} of {count} results.', 'template' => "{summary}{items}{pager}", 'htmlOptions'=>array('style' => 'width:500px;margin-left: 130px;',), 'columns' => array( array('name' => 'real_name', 'header'=> 'Trading Name','htmlOptions'=>array('width'=>'50%'), 'type'=>'raw', 'value' =>'CHtml::link($data->real_name, array("contractors/viewalldocuments","id"=>$data->username))', ), array('name' => 'email', 'header' => 'Email','htmlOptions'=>array('width'=>'30%')), array('name' => 'last_login', 'header' => 'Last Login', 'filter'=>false, 'htmlOptions'=>array('width'=>'20%'), 'value' => 'date("d-m-Y", strtotime($data->last_login))'), )) The data set returned is from the User model - the code for this is: public function searchlogin() { $criteria=new CDbCriteria; $criteria->compare('real_name', $this->real_name); $criteria->condition = 'last_login IS NOT NULL AND user_type_id=4'; return new CActiveDataProvider('User', array( 'pagination' => array( 'pageSize' => 80, ), 'criteria'=>$criteria, )); } If I change my view code to use the standard search function then every user in the user table is returned and the data will filter down by search term. So if I change one line in the view to 'dataProvider' => $model->search(), Then every user is returned but the data will filter by search term. The standard search function in the model this refers to in the User Model is public function search() { $criteria=new CDbCriteria; $criteria->compare('real_name',$this->real_name,true); $criteria->compare('username',$this->username,true); $criteria->compare('email',$this->email,true); $criteria->compare('last_login',$this->last_login,true); return new CActiveDataProvider($this, array( 'pagination' => array( 'pageSize' => 80, ), 'criteria'=>$criteria, )); } This should be really straight forward and simple. You should be able to have multiple search functions in a Model - I have been looking at this for days and I just cannot resolve the problem. I would appreciate any help. When I type in the search term the code generates what I would expect the url to be
  4. Version 0.5 Loading a Single Model The following two examples work together. The second calls the first. I believe the purpose is to retrieve a record from a table. And I believe each occurrence of $id represents the primary key value of the particular record we want. My question is, how do these functions know which table to search in? page 136: public function loadModel($id) { $model = Page::model()->findByPk($id); if ($model===null) { throw new CHttpException(404, 'The requested page does not exist.'); } Page 139: public function actionView($id){ $this->render('view',array( 'model'=>$this->loadModel($id), )); }
  5. Hi there everybody. I've only recently started experimenting with the Yii framework and must say that I'm loving it. I have however run into a slight dilemma which I just can't seem to figure out. I must admit that my javascript (jQuery) knowledge probably isn't up to scratch but I would prefer to make that part of my Yii learning experience. The problem: I want to include a search function in my header. This search function should behave exactly the same as a normal autocomplete dropdown textbox and the values of autocomplete options should be retrieved from two or more MYSQL database attributes (In this case I want to have a table for products and this one autocomplete field should enable me to search for product matches via the product_name, product_serial and product_color attributes). I have gotten a database search to work from http://www.yiiframework.com/extension/database-live-search/ . This however does a render_partial to a part of the page whereas I want possible results to be represented as a dropdown list. I would like to be able to click on one of the dropdown options and then go to this option specific page content after clicking a search button or perhaps if clicking on the specific option. To illustrate, I want to build a search box similar to that of Amazon.com (now by no means am I aiming to build such a complex underlying system, but this is just the idea of what I want to do.) http://www.amazon.com/ Now like I said I want to search through multiple attributes within my table. Ex. if I search for the string 'red', product_name, product_serial and product_color attributes will be scanned for all of the entries containing this string and if none are found the a sorry message will be displayed on the dropdown. BTW. I'm mainly using the Bootstrap extension for my UI if it might be of any additional help in building a typeahead or search form. Please if anybody can give me some assistance or point me to some sort of tutorial that will help me master this problem as it is really important to me to be able to do it exactly in the way described above! Thank you very much in advance. Kind regards, Hermann.
  6. I am looking for a script to add a search feature on a website. Can you help me find that script? Thank you.
  7. Hi i am using this code for searching by name and getting some errors. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Search Contacts</title> </head> <p><body> <h3>Search Contacts Details</h3> <p>You may search either by first or last name</p> <form method="post" action="search.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="Search"> </form> </body> </html> </p> <style type="text/css" media="screen"> ul li{ list-style-type:none; } </style> </form> <p><a href="?by=A">A</a> | <a href="?by=B">B</a> | <a href="?by=K">K</a></p> <?php //end of search form script if(isset($_GET['by'])){ $letter=$_GET['by']; //connect to the database require_once ('../mysqli_connect.php'); //-query the database table $sql="SELECT designer_id, first_name, last_name FROM designers WHERE first_name LIKE '%" . $letter . "%' OR last_name LIKE '%" . $letter ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-count results $numrows=mysql_num_rows($result); echo "<p>" .$numrows . " results found for " . $letter . "</p>"; //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $first_name =$row['first_name']; $last_name=$row['last_name']; $designer_id=$row['designer_id']; //-display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"search.php?id=$designer_id\">" .$first_name . " " . $last_name . "</a></li>\n"; echo "</ul>"; } } ?> errors: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 65 results found for A Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\search.php on line 71 can anyone help me plz?
  8. hi.... i followed the ecommerce chapter of your book and want to know if we want to add a search form in the page and perform fulltext searcher what modifications we have to do in the code ? please help
  9. Hello, Could someone help me with a regular expression in MySQL? If I test the following pattern in PHP: \b(\')?((eau){1}|(eaux){1})\b the results are fine since I get a match for but no match for Yet if I try the very same pattern in the database, using phpMyAdmin, I get no results at all although all the above examples are in the database. Could someone explain why this is happening, and what I need to do in MySQL? In case you wonder why I'm not using a FULLTEXT search, I plan to use regular expressions for words that are 1, 2 or 3 characters long, and a FULLTEXT search for longer words or expressions. With thanks for your help,
  10. Hi all, I'm am wondering if anyone can give me any pointers in the right direction for my current issue. I have three search fields on a page, 'keyword', 'county' and 'supplier_type' with a submit button below. The keyword field is a text box and the other two fields are drop down menus which take the data from the mysql database. When searching users have the option to enter nothing, one field, two fields or three fields. Following this I have determined that there are 8 possible ways that users can search: 1). keyword only 2). county only 3). supplier_type only 4). keyword and county only 5). Keyword and supplier_type only 6). County and supplier_type only 7). All fields- Keyword, county and supplier_type 8). no data entered by user The code below displays the form on the page <h1>Search</h1> <form action="suppliersresults.php" method="post"> <fieldset> <p><b>Supplier Name Keyword Search:</b> <input type="text" name="keyword" size="20" maxlength="40" value="<?php if (isset($trimmed['keyword'])) {echo $trimmed['keyword'];} else {echo 'keyword';} ?>" /></p> <p><b>Supplier Location:</b></p> <select name="county" id="county" class="formtext"> <?php echo"<option value='all' selected='selected'>all</option>"; require_once('includes/config.inc.php'); $cq = "SELECT county FROM county_table ORDER BY county ASC"; $cr = @mysqli_query($dbc, $cq); if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['county'] . '">' . $ca['county'] . '</option>'; } mysqli_free_result($cr);//free up resources } else { echo '</select>We apologise there seems to be a problem with this data'; } ?> </select> <p><b>Supplier Type:</b></p> <select name="supplier_type_id" id="supplier_type_id" class="formtext"> <?php //the below code is for when the user selects all supplier types. Commenting out until get it to work first. //echo"<option value='all' selected='selected'>All</option>"; echo"<option value='all' selected='selected'>all</option>"; require_once('includes/config.inc.php'); $cq = "SELECT supplier_type_id, supplier_type_name FROM supplier_type ORDER BY supplier_type_name ASC"; $cr = @mysqli_query($dbc, $cq); if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['supplier_type_id'] . '">' . $ca['supplier_type_name'] . '</option>'; } mysqli_free_result($cr);//free up resources } else { echo '</select>We apologise there seems to be a problem with this data'; } ?> </select> </fieldset> <div align="center"><input type="submit" name="submit" value="Search" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> I have tested this and it correctly send the data through to suppliersresults.php but my problem is with the searching mechanism. Perhaps this is the wrong way of thinking but I have created if statements but they are not returning the correct data in all occasions. //set variables $county = $_POST['county']; $supplier_type_id = $_POST['supplier_type_id']; $keyword = $_POST['keyword']; ///////////////////////////////////////////////// //if the user doesnt' enter anything in any field on the search page except for a keyword - 1 if (isset ($_POST['supplier_type_id']) == 'all' && ($_POST['county']) == 'all' && ($_POST['keyword']) <> 'keyword') //search for a supplier name keyword search $q = "SELECT * FROM supplier_details WHERE supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user doesnt' enter anything in any field on the search page except for a county - 2 if (isset($_POST['supplier_type_id']) == 'all' && ($_POST['keyword']) == 'keyword' && ($_POST['county']) <> 'all') //search for a supplier name search $q = "SELECT * FROM supplier_details WHERE county='$county' ORDER BY registration_date ASC"; //if the user doesnt' enter anything in any field on the search page except for a supplier type - 3 if (isset ($_POST['keyword']) == 'keyword' && ($_POST['county']) == 'all' && ($_POST['supplier_type_id']) <> 'all') $q = "SELECT * FROM supplier_details WHERE supplier_type_id='$supplier_type_id' ORDER BY registration_date ASC "; //if the user enters a keyword and county AND NOT a supplier_type_id - 4 if (isset ($_POST['supplier_type_id']) == 'all' && ($_POST['county']) <> 'all' && ($_POST['keyword']) <> 'keyword') $q = "SELECT * FROM supplier_details WHERE county='$county' AND supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user enters a supplier_type_id AND a keyword AND NOT a county - 5 if (isset ($_POST['county']) == 'all' AND ($_POST['keyword']) <> 'keyword' AND ($_POST['supplier_type_id']) <> 'all' ) $q = "SELECT * FROM supplier_details WHERE supplier_type_id='$supplier_type_id' AND supplier_name LIKE '$keyword%' ORDER BY registration_date ASC"; //if the user enters a county AND a supplier_type_id AND NOT a keyword - 6 if(isset ($_POST['keyword']) == 'keyword' && ($_POST['supplier_type_id']) <> 'all' && ($_POST['county']) <> 'all') $q = "SELECT * FROM supplier_details where supplier_type_id='$supplier_type_id' AND county='$county' ORDER BY registration_date ASC"; //if the user enters a county AND a supplier_type_id AND a keyword - 7 if (isset($_POST['supplier_type_id']) <> 'all' && ($_POST['county']) <> 'all' && ($_POST['keyword']) <> 'keyword') $q = "SELECT * FROM supplier_details WHERE supplier_name LIKE '$keyword%' AND supplier_type_id='$supplier_type_id' AND county='$county' ORDER BY registration_date ASC"; //if the user doesn't enter anything - 8 if (isset($_POST['supplier_type_id']) == 'all' && ($_POST['county']) == 'all' && ($_POST['keyword']) == 'keyword') $q = "SELECT * FROM supplier_details ORDER BY registration_date ASC"; Could anyone give me some guidance on where I am going wrong? Many thanks!
×
×
  • Create New...