PHP - Highlighting Background Behind Search Term In Results
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. 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 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/>"; } ?> 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>'; } 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 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); 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. 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. 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'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 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. 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 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 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 hello. i have a search box that will display some results. I also have a drop down list with values "1" and "2". the values for each results are stored into database in a "req" field. Code: [Select] <select name="req" id="req"> <option value="1">yes</option> <option value="2">no</option> </select> $sql = 'SELECT * FROM topic WHERE (Title LIKE '."'%$search1%') AND req='1' what am i missing. thanks 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. Hello. I am having a hard time building my own search results page for my mysql database. Basically I am trying to search for game categories from the fldCategory field in the table, and display 15 results at a time in an HTML table with the Image of the games (fldIconMedium), and the titles of the games (fldTitle) placed in to the table. Also, at the bottom of the table would have a number bar that you can click on numbers to go to the next set of search results in the same page. The number bar would have Previous and Next button. For the code I am using, I had help from another expert. I thank him, but here is the code I have so far. =========================== =========================== <?php $cat=1; $nor=15; $a=1; if(isset($_GET['cat'])) { } else { $_GET['cat']=1; } echo $_GET['cat']; $con=mysql_connect("host","nusername","password") or die ("error"); $db=mysql_select_db("database",$con) or die("Database not found!"); $result=mysql_query("SELECT * FROM games") or die ("query error"); echo "<table border='1'><tr><th>ImageIcon</th><th>Title</th></tr>"; $r=mysql_num_rows($result); echo $r."<br/>"; $p=ceil($r/$nor); //echo $p; while($rows=mysql_fetch_array($result)) { if($a>($_GET['cat']-1)*$nor) { echo "<tr><td>".$rows['fldIconMedium']."</td><td>".$rows['fldTitle']."</td></tr>"; } $a=$a+1; } echo "</table>"; for($i=1;$i<=$p;$i++) { if($i==$_GET['cat']) { echo $i; } else { echo "<a href='gameslist.php?cat=".$i."'>".$i."</a>"; } } ?> =========================== =========================== To see this code in action, heres the link http://netroxy.com/gameslist.php?cat=skills. > Not working well. I am expecting the games search results page to look like this: http://netroxy.com/51274581336/search.htm So basically its: - viewing how many games found for game category, ex: Skills. Or Action, Mind, etc.. - the URL containing 'gameslist.php?cat=' with the given ID category at the end should search for that given category and display at least 15 games per results, along the number bar bellow, which counts how many are found from that category, which automatically increases or decreases the number bar bellow depending how many games from that specific category was found. I also forgot to mention that I did not add the Previous and Next button, which i dont know how - As for the 15 results per page, its basically 15 images (fldIconMedium) of different games of the same category, with their Titles (fldTitle) underneath them and both image and title should have the LINK to that specific game by retrieving the links from the 'fldLink' column where all the links of the games are found. Thanks all! |