PHP - Search Help Display Results
I'm new to php and been trying to follow along with different tutorials to try and build my own site, i followed a tutorial on making a search feature
for the site and have it working perfectly, but i want to change the way how to search displays the results. I want to make it display them how there displayed on the index page. here is the index page how there displayed <div id="table"> <table> <tr class="top"> <th>Account</th> <th>Country</th> <th>Info</th> <th>Login</th> <th>Pass</th> <th>Price</th> <th>Buy</th> </tr> <?php $class = 'grey'; ?> <?php $items = getItems(); ?> <?php if(empty ($items)): ?> <h3>No Items Found</h3> <?php else: ?> <?php foreach($items as $item): ?> <?php $class = ($class == 'grey') ? 'grey2' : 'grey'; ?> <tr class="<?php echo $class; ?>"> <td><?php echo $item['item_account']; ?></td> <td><?php echo $item['item_country']; ?></td> <td><?php echo $item['item_info']; ?></td> <td><?php echo maskUser($item['item_login']); ?></td> <td><?php echo maskPass($item['item_pass']); ?></td> <td><?php echo $item['item_price']; ?> </td> <td><form method="post" action="https://sci.libertyreserve.com/"><input type="submit" name="buy" value="Buy" class="button" /></form></td> </tr> <?php endforeach; ?> <?php endif; ?> how the search is display if (strlen($search) <= 2) { echo 'Search keyword is too short.'; } else { echo "You searched for <b>$search</b><hr size='1'>"; $search_exploded = explode(" ", $search); foreach($search_exploded as $search_each) { $x++; if ($x == 1) $construct .= "item_account LIKE '%$search_each%'"; else $construct .= " OR item_account LIKE '%$search_each%'"; } $construct = "SELECT * FROM items WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum == 0) { echo 'No results found.'; } else { echo "$foundnum results found!</p>"; while ($numrows = mysql_fetch_assoc($run)) { $item_id = $numrows['item_id']; $itemAccount = $numrows['item_account']; $itemI = $numrows['item_info']; $itemLogin = $numrows['item_login']; $itemPass = $numrows['item_pass']; $itemPrice = $numrows['item_price']; echo " <b>$itemAccount</b><br /> $itemI <br /> " . maskUser($itemLogin) . '<br />' . maskPass($itemPass, 0) . '<br />'; } } } my question is im not sure how to edit the search code to display the results in the same format as the index page thanks Similar TutorialsHello everyone, Very new to coding - enjoying it but struggling! I think I'm trying to do something pretty common but I seem to have come up against a complete wall now and after hours/days searching the internet and reading books I'm completely stuck! I'm trying to write some code to search a MySQL database of products, then display the results. For some search results there will be lots of products so I want to display 10 products on the first page then allow visitors to go to the next page to see another 10, and so on - a type of pagination, as they should then be able to click back to see the last page etc. I've got to the point of being able to display the first 10 search results, but I can't figure out at all how to create some kind of page scrolling/pagination system. Please, does anybody have any ideas?? I've attached my code, I hope this is the correct way of doing things here. Many thanks for your time! The PHP search code... Code: [Select] <?php //opens connection to mysql server $dbc = mysql_connect('localhost'); if (!$dbc) { die('Not connected :' . mysql_error()); } echo "Connected to mysql database<br />"; //select database $db_selected = mysql_select_db("NAME_OF_DATABASE", $dbc); if (!$db_selected) { die ("Cannot connect :" . mysql_error()); } echo "Connected to database<br /><hr />"; echo "Here are your results"; $term = $_POST['term']; $category = $_POST['category']; $brand = $_POST['brand_name']; $sql = mysql_query("SELECT * FROM products where product_name like '%$term%' AND category_name like '%$category%' AND brand_name like '%$brand%' LIMIT 0, 10"); { while ($row = mysql_fetch_array($sql)){ echo "<table border='1' width='100%'> "; echo "<tr>"; echo "<td style='vertical-align:top' width='25%'>" . '<img src="', $row['image_url'], '" alt="', $row['product_name'], '" width="100" height="100" />' . "</td>"; echo "<td style='vertical-align:top' width='50%'>" . $row['product_name']; echo "<br />"; echo "<span style='font-size: 10px'>" . $row['description'] . "</span>" . "</td>"; echo "<td style='vertical-align:top' width='25%'>" . $row['price']; echo "<br />"; echo "<br />"; echo "<hr />"; echo "$row['merchant_name'] </td>"; echo "</tr>"; } echo "</table>"; } ?> I have a search page and everything works fine but I would like to add the latest 10 rows to the page so there is something to look at or click on before the user searches. The page is at: www.giantstridedives.com/locations. You can see that it's pretty boring. Hit submit and you'll see the entries so far (only 3 right now). I'd like to have the latest 10 display there by default but then when a user searches they are replaced by the search results. Make sense? Here's the code I'm using for the search: Code: [Select] <?php if (isset($_POST['submit'])) { require_once('dbconnection.php'); mysqli_select_db($conn, $dbname); $searchterm = $_POST['search']; $searchterm = strip_tags($searchterm); $searchterm = trim ($searchterm); $q ="SELECT * FROM locations WHERE loc_name LIKE '%" . $searchterm . "%' AND loc_approved != '0'"; $r = mysqli_query($conn, $q) or die(mysql_error($q)); $row = mysqli_fetch_assoc($r); $rowcount = mysqli_num_rows($r); } ?> <h1>Search for Scuba Dive Locations</h1> <form id="searchform" name="searchform" method="post" action="index.php"> <input type="text" name="search" id="search_bar" /> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <span style="color: #333;">Search for the name of the location, ie: Devils Den or USS Oriskany.</span><br /> <?php if (isset($_POST['submit'])) { if ($rowcount == 0) { echo "Sorry, but we can not find an entry to match your query: <strong>$searchterm</strong>"; } else { //this tells the table below to display since $totalRows_Products_res is not 0 ?> <table style="font-size: 14px;" border="0" width="650"> <tr> <td colspan="6"><p>You searched for <strong><?php echo $searchterm; ?></strong>. Results are displayed below.</p></td> </tr> <tr> <td><strong>Location Name</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Depth (ft)</strong></td> <td><strong>Fees</strong></td> <td><strong>Gear Rentals</strong></td> <td><strong>Map</strong></td> </tr> <?php do { ?> <tr> <td><a href="loc_details.php?loc_id=<?php echo $row ['loc_id']; ?>"> <?php echo $row ['loc_name']; ?> </a></td> <td><?php echo $row ['loc_city']; ?></td> <td><?php echo $row ['loc_state']; ?></td> <td><?php echo $row ['loc_depth']; ?></td> <td>$<?php echo $row ['loc_fee']; ?></td> <td><?php if($row['loc_gear'] == 1) { echo 'Yes'; } else { echo 'No'; } ?></td> <td><a href="http://maps.google.com/maps?q=<?php echo $row ['loc_lat'];?>,<?php echo $row ['loc_lon'];?>" target="_blank">View Map</a></td> </tr> <?php } while ($row = mysqli_fetch_assoc($r)); ?> </table> <?php mysqli_free_result($r); } // this closes out results else } ?> I figure I can use the below query to get the results. Code: [Select] select * from table WHERE id > ((SELECT MAX(id) from table) - 10);I'm just not sure how I can display them by default and then have them be replaced by the search results. Anyone have any ideas for me? As always I appreciate the help as I continue to learn this beast. Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks In the code below, I am trying to produce a google-like page where the user can type keywords and pages of search results are displayed. The main difficulty I am encountering is that when the browser changes pages, it forgets everything about current data. Perhaps I should include the display of pages inside the HTML form ? How can I fix this code ? Here is the contents of my searchpage.php file : <?php $keywords=''; $display_search_results=''; if(isset($_POST['search_submitted'])) { $keywords=$_POST['keywords']; $search_results=array(); $totalNbrOfItems=20; for($k=1;$k<=$totalNbrOfItems;$k++) { $search_results[$k]='Your keywords '$keyowrds.' have been found in item number '.$k; } $nbrOfItemsParPage = 5; $nbrOfPages = ceil($totalNbrOfItems / $nbrOfItemsParPage); // Compute current page $current_page = (isset($_GET['page']))?intval($_GET['page']):1; $display_pages=($nbrOfPages<2)?'<p>Page : ':'<p>Pages : '; for ($i = 1 ; $i <= $nbrOfPages ; $i++) { if ($i == $current_page) //No link to the current page { $display_pages=$display_pages.$i.' '; } else { $display_pages=$display_pages.'<a href="searchpage.php?'. 'page='.$i.'">'. $i . '</a> '; } } $display_pages=$display_pages.'</p>'; $display_items=''; $start=$nbrOfItemsPerPage*($current_page-1); for($k=1;$k<=$nbrOfItemsParPage;$k++) { $display_items=$display_items.($search_results[$start+$k]).'<br>'; } $display_search_results=$display_pages.$display_items; } echo '<form method="post" action="searchpage.php">'. ' Type your keywords here : <br><br>'. '<textarea cols="65" rows="1" '. 'id="keywords_id" name="keywords">'.$keywords.'</textarea>'. '<input type="submit" name="search_submitted" id="search_submitted_id" value="Search" /> '. '</fieldset>'. '</form>'; echo $display_search_results; ?> Hello, I'm developing a website that asks the user to submit a keyword for a search. The results should display matches for this keyword, but also show matches for related keywords (in order of relevenace!). I'm planning on building up a library of which search terms users use in the same sessions (e.g. if someone searches for "it jobs" and "php jobs", I'll know the terms are correlated), and I'll also measure the click-through rates of the items on the results list. I've been spending all weekend trying to map out the design for this but it's proving incredibly complicated and I think the solution is likely to be on the internet somewhere already?! Please could someone point me in the right direction if you've come accross this problem before? Thanks a million, Stu Hi, I have a problem if users search something which doesn't match the data in the table I'm selecting from. At the moment I'm trying this code: Code: [Select] <?php require_once('inc/global.inc.php'); # search.inc.php /* * This is the search content module. * This page is included by index.php. * This page expects to receive $_GET['terms']. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('../includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php?p=search'; // Pass along search terms? if (isset($_GET['terms'])) { $url .= '&terms=' . urlencode($_GET['terms']); } header ("Location: $url"); exit; } // End of defined() IF. // Print a caption: echo '<h2>Search Results</h2>'; // Display the search results if the form // has been submitted. if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { $terms = $_GET['terms']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server'); // Query the database. $query = "SELECT * FROM product WHERE title LIKE '%$terms%'"; // Fetch the results. //$row = mysqli_fetch_array($result); // Print the results: $result=mysqli_query($dbc,$query); if ($result == 0){ echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } while($row=mysqli_fetch_assoc($result)) { $output[] = '<ul>'; $output[] = '<li>'.$row['title'] .': £'.$row['price'].'<br /><img src="'.$row['img'].'" alt="'.$row['title'].'" /></li>'; $output[] = '</ul>'; } echo join('',$output); } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search this site.</p>'; } ?> But I'm getting this error: Object of class mysqli_result could not be converted to int So that little if statement here doesn't work: Code: [Select] if ($result == 0){ echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } Is there another way I can display no search matched results? Thank you for reading, Andrew. What I expect: - The function to loop output all of the rows which match the search results. The problems: - Only 1 row is matched. - Notice: Undefined index: id in G:\xampp\htdocs\xampp\dsa\search_func.php on line 57 - The image is not showing Line 57: Code: [Select] $id = $_REQUEST['id']; Entire Code: Code: [Select] <?php /* return the details of an employee parameter empno - employee number eg empHTML.php?empno=7521 This is very basic e.g no error checking */ function search($dbc, $id) { if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { $terms = $_GET['terms']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server'); $query = "SELECT * FROM stick, location, identification WHERE make LIKE '%$terms%' AND stick.sid = location.lid AND identification.stickID = stick.sid AND identification.stickID = $id"; $result=mysqli_query($dbc,$query); $num_rows = mysqli_num_rows($result); $output = Array(); $image = mysqli_fetch_object($result); if ($num_rows > 0){ if($result=mysqli_query($dbc,$query)){ $output[] = '<ul>'; $output[] = '<li> Type: '.$image->make .'<br />Size: '.$image->size .$image->type .'<br />Colour: '.$image->colour . '<br /> Street Missing in: ' .$image->street.'<br />Town missing in: '.$image->town .'<br />City missing in: '.$image->city.'</li>'; $output[] = '</ul>'; } return join('',$output); } else { echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search this site.</p>'; } } // connect $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // get the id from the URL $id = $_REQUEST['id']; print search($dbc, $id); print "<img src='getPhoto.php?id=$id'/>"; // close the database mysqli_close($dbc); hey guys, i have a search bar i am implementing into my navmenu but keeping getting errors returned and im not sure why This is the code in my navmenu to display the search bar Code: [Select] echo '<form action="search.php" method="post">Search: <input type="text" name="term" /> <input type="submit" name="submit" value="Search"/>'; Code: [Select] Here is the php file that query's the search $term = $_POST['term']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = mysqli_query("select * from ob_listings where subject like '%$term%' or description like '%$term%' "); while ($row = mysql_fetch_array($dbc, $query)){ echo 'Subject: '.$row['subject']; echo '<br/> Date: '.$row['date']; echo '<br/> Price: '.$row['price']; echo '<br/> City: '.$row['city']; echo '<br/><br/>'; } any help is much appreciated here are the errors being returned Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 16 (line 16 is the $query) Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 17 (line 17 is the while loop) I am trying to write a script that will allow me visitors to my site to search my database for items. I followed a tutorial that I had found and tweaked it to fit my needs. I am not getting any results it keeps telling that there was no search results found. Even though I have the items that I have been testing on in my database. I have two files the main search.php file and the search_func.php file Here is the search.php file Code: [Select] <form method='post' action='search.php'> <fieldset> <input type='text' name='search' id='search' value='type name here'/> <input type='submit' name='search_submit' id='search_submit' value='search'/> </fieldset> </form> <?php include('includes/search_func.php'); if(isset($_POST['search'])) { $keywords = mysql_real_escape_string(htmlentities(trim($_POST['search']))); $errors = array (); if (empty($keywords )){ $errors[] = 'Please enter a search term'; } else if (strlen($keywords ) < 3 ) { $errors[] = 'Search term must be more then three characters long'; } else if (search_results($keywords == false)) { $errors[] = 'Your search for ' .$keywords . ' showed no results'; } if (empty($errors)) { $results = search_results($keywords ); $results_num = count($results); $suffix = ($results_num != 1) ? 's' : ''; echo 'Your search for <strong>'. $keywords .'</strong> returned <strong>' .$results_num.'</strong> result'.$suffix.''; foreach($results as $result) { echo $result['first']; } } else { foreach($errors as $error){ echo $error; } } } ?> Here is the search_func.php file Code: [Select] <?php include('includes/config.php'); connect(); function search_results($keywords ) { $returned = array(); $where = ""; $keywords = preg_split('/[\s+]/', $keywords ); $total = count($keywords ); foreach($keywords as $key=>$keyword) { $where .= "`l_name` LIKE '%$keyword%'"; if($key != ($total - 1)){ $where .= "OR"; } } $results = "SELECT `l_name`,`f_name`,`image`,`item_return` FROM `ttmautos` WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0 ; if ($results_num === 0) { return false; } else { while($results_row = mysql_fetch_assoc($results)) { $returned_results[] = array( 'last' => $results_row['l_name'], 'first' => $results_row['f_name'], 'image' => $results_row['image'], 'item' => $results_row['item_return'] ); } return $returned_results; } } ?> If anyone could give me an idea of what I am doing wrong I would appreciate it. I have a page that I am using to search a database. Basically what I want to do is allow the end user to sort by column headings after the search results are returned. The sort code that I am using works fine on a "lesser complicated" page that does not involve $_GET variables. I am not sure however if I adapted it properly. Also, I am having problems adding the new $_GET variables to the URL string when the user chooses to sort the returned search results. Thank you in advance for any suggestions. My code is below: Code: [Select] <?php //////////////////// INITIATE SESSION //////////////////// if (!isset($_SESSION)) { session_start(); } //////////////////// ALLOW ACCESS ONLY TO ADMINISTRATORS //////////////////// if ($_SESSION['person_priveleges'] == 0) { header("location:index.php"); } //////////////////// CONNECT AND SELECT DATABASE //////////////////// require_once('connect.php'); mysql_select_db($database, $connect); //////////////////// GET STATES //////////////////// $state = mysql_query("SELECT state_abbreviation FROM state ORDER BY state_abbreviation ASC", $connect); $data_state = mysql_fetch_assoc($state); $rows_state = mysql_num_rows($state); //////////////////// GET USER SEARCH RESULTS //////////////////// if (array_key_exists('search', $_GET)) { $error = array(); if ((empty($_GET['last_name_search'])) && (empty($_GET['organization_search'])) && (empty($_GET['state_search'])) && (empty($_GET['payment_status']))) { $error['search'] = "Please enter at least one search parameter."; } else { $search = "SELECT * FROM person"; $where = false; if (isset($_GET['last_name_search']) && !empty($_GET['last_name_search'])) { $last_name_search = $_GET['last_name_search']; $search .= " WHERE person_last_name LIKE '%$last_name_search%'"; $where = true; } if (isset($_GET['organization_search']) && !empty($_GET['organization_search'])) { $organization_search = $_GET['organization_search']; if ($where) { $search .= ' AND '; } else { $search .= ' WHERE '; $where = true; } $search .= " person_organization LIKE '%$organization_search%'"; } if (isset($_GET['state_search']) && !empty($_GET['state_search'])) { $state_search = $_GET['state_search']; if ($where) { $search .= ' AND '; } else { $search .= ' WHERE '; $where = true; } $search .= " person_state LIKE '%$state_search%'"; } if (isset($_GET['payment_status']) && !empty($_GET['payment_status'])) { $payment_search = $_GET['payment_status']; if ($where) { $search .= ' AND '; } else { $search .= ' WHERE '; $where = true; } $search .= " person_paid LIKE '%$payment_search%'"; } if (isset($_GET['sort'])) { $sort = mysql_real_escape_string($_GET['sort']); if (strcasecmp($sort, "DESC") == 0) { $new_sort = "ASC"; } else { $new_sort = "DESC"; } } else { $sort = "ASC"; $new_sort = "DESC"; } if (isset($_GET['order'])) { $order = mysql_real_escape_string($_GET['order']); $search .= " AND person_priveleges = 0 ORDER BY $order"; if (strcasecmp($sort, "DESC") == 0) { $search .= " DESC"; } else { $search .= " ASC"; } } else { $search .= " AND person_priveleges = 0 ORDER BY person_last_name"; $query_search = mysql_query($search, $connect) or die(mysql_error()); $result_search = mysql_fetch_assoc($query_search); $number_search = mysql_num_rows($query_search); $count = 0; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>2011 IDUES Project Directors Meeting</title> <link href="layout.css" rel="stylesheet" type="text/css" /> </head> <body class="twoColFixLtHdr"> <br /> <!--container starts here--> <div id="container"> <?php include('header.php'); ?> <?php include('menu_admin.php'); ?> <?php include('sidebar_admin.php'); ?> <!--main content starts here--> <div id="mainContent"> <h2 class="page_title">REGISTRANT SEARCH</h2> <div align="center"><?php if (isset($error)) { echo '<div align="center"><span class="contact_us_error">'; foreach ($error as $alert) { echo "$alert<br />\n"; } echo '</div></span>'; } ?></div> <form id="search" name="search" method="get" action=""> <table width="60%" border="0" cellspacing="0" cellpadding="5"> <tr> <td class="black_font"><label>Search by Last Name:</label></td> <td class="black_font"><input type="text" name="last_name_search" id="last_name_search" /></td> </tr> <tr> <td class="black_font"><label>Search by Organization:</label></td> <td class="black_font"><input type="text" name="organization_search" id="organization_search" /></td> </tr> <tr> <td class="black_font"><label>Search by State:</label></td> <td class="black_font"><select name="state_search" id="state_search"> <option value="">Select State</option> <?php do { ?> <option value="<?php echo $data_state['state_abbreviation']?>" <?php if (isset($_POST['state']) && $_POST['state'] == $data_state['state_abbreviation']) { echo 'selected="selected"'; } echo $data_state['state_abbreviation']; ?>><?php echo $data_state['state_abbreviation']?></option> <?php } while ($data_state = mysql_fetch_assoc($state)); $rows = mysql_num_rows($state); if ($rows > 0) { mysql_data_seek($state, 0); $data_state = mysql_fetch_assoc($state); } ?> </select></td> </tr> <tr> <td valign="top" class="black_font">Search by Payment Status:</td> <td class="black_font"><p> <label> <input type="radio" name="payment_status" value="Yes" id="payment_status_0" /> Paid</label> <br /> <label> <input type="radio" name="payment_status" value="Pending" id="payment_status_1" /> Pending</label> <br /> <label> <input type="radio" name="payment_status" value="No" id="payment_status_2" /> Not Paid</label> <br /> </p></td> </tr> </table> <input type="submit" name="search" id="search" value="Search" /> </form> <br /> <?php if (array_key_exists('search', $_GET) && !$error) { ?> <?php if ($number_search == 0) { ?> <div align="center" class="contact_us_error">No results match your search</div> <span class="black_font"> <?php } else { ?> <strong>Total Search Results: <?php echo $number_search; ?></strong> <br /> </span> <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td bgcolor="#CCCCCC" class="black_font"> </td> <td bgcolor="#CCCCCC" class="black_font"><strong><a href="<?php echo $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."?order=person_last_name&sort=$new_sort"; ?>">Name</a></strong></td> <td bgcolor="#CCCCCC" class="black_font"><strong><a href="<?php echo $_SERVER['PHP_SELF']."?order=person_organization&sort=$new_sort"; ?>">Organization</a></strong></td> <td bgcolor="#CCCCCC" class="black_font"><strong><a href="<?php echo $_SERVER['PHP_SELF']."?order=person_state&sort=$new_sort"; ?>">State</a></strong></td> <td align="left" bgcolor="#CCCCCC" class="black_font"><strong><?php if ((isset($_GET['payment_status'])) && ($_GET['payment_status'] == 'Yes')) { ?> <a href="<?php echo $_SERVER['PHP_SELF']."?order=person_payment_method&sort=$new_sort"; ?>">Payment</a></strong></td> <?php } else { echo "Paid</strong></td>"; } ?> </tr> <tr> <?php do { ?> <?php $count++; ?> <?php $person_id = $result_search['person_id']; ?> <?php $first_name = $result_search['person_first_name']; ?> <?php $last_name = $result_search['person_last_name']; ?> <?php $organization = stripslashes($result_search['person_organization']); ?> <?php $state = $result_search['person_state']; ?> <?php $paid = $result_search['person_paid']; ?> <?php $payment_method = $result_search['person_payment_method']; ?> <td class="black_font"><?php echo $count; ?></td> <td class="black_font"><?php echo "<a href='registrant_info.php?id=$person_id'>$last_name, $first_name</a>"; ?></td> <td class="black_font"><?php echo stripslashes($organization); ?></td> <td class="black_font"><?php echo $state; ?></td> <td class="black_font"><?php if ($paid =='Yes') { echo $payment_method; } else { echo $paid; } ?></td> </tr> <?php } while ($result_search = mysql_fetch_assoc($query_search)); ?> </table> <span class="black_font"> <?php } ?> <?php } ?> </span><br /> <br /> <br /> <br /> <br /> <br /> </div> <!--main content ends here--> <!--clearing element should immediately follow #mainContent div to force the #container div to contain all child floats--> <br class="clearfloat" /> <?php include('footer.php'); ?> </div> <!--container ends here--> </body> </html> Hi guys, A beginner at php/mysql here... For a project I'm doing, I would like to display search results with an image, small description, then a 'read more' link. After googling this issue, I can't find much information on it, which surprised me. Someone did mention blobs for images... (whatever they are!) I'm wondering if anyone knows of any tutorials, or has any code to do this? Your help is much appreciated. Thanks. Hi, I have search form which works apart from 1 part, I have set the results limit to 10 per page with a next link if there are more than 10 results, however when the next link is clicked, i get the error 'you do not have a search parameter' which comes from this code: Code: [Select] if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } The next link is defined by the code below: Code: [Select] // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 >></a>"; } Can anyone see where I have gone wrong with this code without me sending the whole search form? Any help would be very much appreciated. Thanks Good Evening, I've been in a trial and error state for the past week trying to figure out how I can put on the pre-made pagination scripts I found on the web, but of no luck. I have just started programming like two weeks ago, and is still trying to understand logics and stuffs so I can get my desired output. So far, everything is doing well except for one - I am really having a hard time to incorporate pagination scripts with my code. To rank myself as a php programmer, I can say I am lower than one, and seemingly, what I want to achieve is an advanced code. Can anyone help me on what pagination code I should try to play with and incorporate with my code? Here's my code so far: <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["btnSearch"])) { $query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="view_client.php" method="post"> <table width="351" border="0"> <tr> <td width="137" align="left" valign="middle"> SEARCH RECORD: </td> <td width="144" align="center" valign="middle"> <input type="text" name="search" /> </td> <td width="56" align="left" valign="middle"> <input type="submit" name="btnSearch" value="Search" /> </td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="80" align="center" bgcolor="#E0E8F3">Territory</th> <th width="330" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 Asia. All rights reserved. </td> </table></td> </tr> </table> Thank you very much, and I am looking forward for your responses. Thanks! Okay, I'm wanting to do a search, but until return the info if it has a specific indicator in the chosen field. Let me show you: $query = doquery("SELECT * FROM `orgs` IF `type`='c' ORDER BY name", "orgs"); How do I do that "IF" bit? Obviously this doesn't work. Thanks! hi, I have a search page with a checkbox $departuk that returns the value "true" if checked. I want to return search results if this returns true and the flag 'Y' is available if ($departuk == "true"){ if ($data[$i]['departuk'] == 'Y'){ $result = $obj->result; } else{ echo "do some thing else"; } else{ echo"there was a problem"; } any pointers / advice is appreciated thanks Hi All, I have a pagination script that works correctly when a user clicks on a category heading, however when I am using it to try an display search results it does not take into account the set of records to display per page, it just shows all results. <?php echo '<h3>Search Results</h3><br />'; $query = "SELECT count(*) from merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%'"; $row=mysql_fetch_assoc(mysql_query($query)); $total_records = $row['count(*)']; $records_per_page = 5; $total_pages = ceil($total_records / $records_per_page); $page = intval($p); if ($page < 1 || $page > $total_pages) $page = 1; $offset = ($page - 1) * $records_per_page; $limit = " LIMIT $offset, $records_per_page"; $query = mysql_query("SELECT * FROM merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%' ORDER BY m_id DESC") ; echo mysql_error() ; while($row = mysql_fetch_assoc($query)){ $name = $row['name']; $short = $row['short']; $per = $row['percent']; $m_id = $row['m_id']; ?> <div id="cbbox"> <a href="viewm.php?m_id=<?php echo $m_id;?>"> <div class="cbname"> <?php echo $name;?> - Up to <?php echo $per ;?>% Cashback Available </div> <div class="cbimage"> <img src="pimage/<?php echo $name;?>.gif" height="50px" width="100px" /> </div> <div class="cbshort"> <?php echo $short;?> </div> </a> <div class="cbtweet"> <a href="http://twitter.com/home/?status=Get up to <?php echo $per;?> percent Cashback on purchase from <?php echo $name;?> http://goo.gl/PLkp"><img src="images/cbtweet.png" width="90" height="50" alt="Tweet This" /></a> </div></div> <br /><br /> <?php } if($total_records > 5) { for ($i = 1; $i <= $total_pages; $i++) { echo "<a title='page $i p=$i'>Page $i - </a>"; } } ?> </div> if I echo out $total_records it displays the correct amount (7 in the case I am looking at) Any ideas? I added a search form on my site but I cannot figure out how to add links to the search results.
The results are being posted as the item name and the item pages look like this used-product.php?Item=102
I am not understanding how I can have that url match up with my item name.
Here is my results.php code
In the header
<?php include_once('mysql_connect.php'); if (!isset($_POST['search'])) { header ("Location:index.php"); } $search_sql="SELECT * FROM new_equip WHERE itemname LIKE '% " .$_POST ['search'] . " %'"; $search_query=mysql_query($search_sql); if(mysql_num_rows($search_query)!=0) { $search_rs=mysql_fetch_assoc($search_query); } ?>and where the results are being displayed <?phpif (mysql_num_rows($search_query)!=0){ do {?> <p><a href="new-product.php?Item=<?php echo $eid; ?>"><?php echo $search_rs ['itemname']?></a></p> <?php } while ($search_rs=mysql_fetch_assoc($search_query)) ; } else { echo "No Results Found"; } ?>I have been on this and trying to figure out another issue I am having and I cannot figure out either of them. (The other is deleting a row from a table with the click of a link) Any help on this would be greatly appreciated it. I have looked and trial and error all day and I cannot seem to get it. Hi All,
I need to get a small function working for a site I need to build for a group of friends.
I was able to get a login page, and a way to add data to the data base.
Now I am stuck on the search and show results fuctionalities.
I have found tens of scripts on the internet, but most of them are outdated, or I cant get them to work, either it sends me back a blank page, does nothing or sends me to an error page
The GOAL
User Inputs text in a text box, clicks submit, the data in the text box is looked for in the second collumn of the DB, The information of the collumns 2 to 7 of the DB for the name search are displayed either on the same page or on a new page.
Is there any chance you could hel me with that, taken into account that I dont need the html part of the code, I only need help with the php part...
Thanks in advance to all the people reading this and the ones helping me...
Hello friends, Posting this thread after many months. Well I am making a small script in which on first page there will be a text box with button. What I want to have is, When we enter any keyword, like "yahoo" in textbox and click on submit button, on next page, there should be top 10 domain names from google search. One of the most important is it should have option to select pages from specific countries like from google.co.uk or google.com or google.jp, this should be on first page. I dont know how to fetch first 10 results domain names / URL and insert it in PHP variable and populate in table. Need help |