PHP - Simple Search To List Youtube Results Help!
I am wanting to write a script that will allow a user to search youtube videos!
What I have so far is not working yet, but I know it can be done! I found this code and it works and its not a million api files to get one thing working! Code: [Select] <?php # YouTube Video Collector - YouTube.class.php ##################################################### # # # YouTube Video Collector 2010 # # # # Author: CMBSystems (Chris Bearcroft) # # Copyright: CMBSystems 2010, All Rights Reserved # # Last Modded: 29-09-2010, 1:26 AM (GMT) # # # ##################################################### class YouTube { public function getURL($Search){ if(!empty($Search)){ $Search=split("\n",$Search); for($i=0;$i<count($Search);$i++){ $SearchURL=urlencode($Search[$i]); $SearchURL="http://www.youtube.com/results?search_category=10&search_type=videos&search_query={$SearchURL}"; preg_match('/\/watch\?v=(.*?)\"/',file_get_contents($SearchURL),$URL); if(strpos($URL[1],'&')){$URL=split('&',$URL[1]);$URL=$URL[0];}else{$URL=$URL[1];} $array[]="http://www.youtube.com/watch?v={$URL}"; } return $array; } } public function printForm($Search){ $Search=htmlspecialchars(stripslashes($Search)); return "<form method=\"get\" action=\"\">\n <table>\n <tr>\n". " <td><textarea cols=\"60\" rows=\"15\" name=\"search_query\">{$Search}</textarea></td>\n". " </tr>\n <tr>\n <td align=\"right\"><input type=\"submit\" value=\"Search YouTube\" /></td>\n". " </tr>\n </table>\n</form>\n"; } } ?> Code: [Select] <?php # YouTube Video Collector - YouTube.php ##################################################### # # # YouTube Video Collector 2010 # # # # Author: CMBSystems (Chris Bearcroft) # # Copyright: CMBSystems 2010, All Rights Reserved # # Last Modded: 29-09-2010, 1:26 AM (GMT) # # # ##################################################### # Require the YouTube class require 'YouTube.class.php'; # Set the PHP vars $Form = YouTube::printForm($_GET['search_query']); $Result = YouTube::getURL($_GET['search_query']); print <<<YTVSC <!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> <title>YouTube Collector</title> </head> <body> {$Form} YTVSC; print_r($Result); print <<<YTVSC </body> </html> YTVSC; ?> It allows me to have a feed link on my site to get the data http://claritydreams.com/youtube/YouTube.php?YT_Search=Staind I can push that ?YT_Search as a search from with in my client but I want to convert the file in to xml to read the data back into the client. Similar TutorialsI would like assistance in displaying a company name in my web search results.
Below is my code:
<html> <head></head> <body> <?php if (!isset($_POST['q'])) { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" /> </form> <?php } else { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search Results</h2> <?php try { // create object // $swish = new Swish('/usr/local/apache/htdocs/swish/index.swish-e'); $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from command-line $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); ?> Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'. <?php // iterate over result set // print details for each match while($r = $result->nextResult()) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (sco <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?><br /> <?php //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $country = substr($filenames[1],1,3); echo 'Country name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year; //$filenames = explode(".", $r->swishdocpath); $wvbnumber = substr($filenames[1],1,12); echo 'WVB Number: '.$wvbnumber; ?> </p> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html>As you can see I am able now display the WVB number, country name and year. But my question to anyone is how would I display the company name that it corresponds to? The names of the company are located in a .csv file called active_colist.csv and it is under the /var/www/html directory. This is what my /var/www/html directory looks like: [root@zeus wvbadmin]# cd /var/www/html [root@zeus html]# ls -l total 2140 -rw-r--r--. 1 root root 2110323 May 14 23:39 active_colist.csv -rw-r--r--. 1 root root 6678 Apr 30 13:25 favicon.ico -rw-r--r--. 1 root root 17256 May 5 16:02 h1 -rw-r--r--. 1 root root 113 Apr 29 16:45 hello.php -rw-r--r--. 1 root root 19 Apr 24 23:53 info.php drwxr-xr-x. 2 root root 12288 May 12 15:30 pdf2 lrwxrwxrwx. 1 root root 20 May 5 15:46 pdf3 -> /home/wvbadmin/pdf3/ -rw-r--r--. 1 root root 1227 May 6 16:33 pdfsearch2.php -rw-r--r--. 1 root root 1204 May 6 15:13 pdfsearch3.php -rw-r--r--. 1 root root 1625 May 19 23:27 pdfsearch.php -rw-r--r--. 1 root root 1838 Apr 30 13:10 search.php -rw-r--r--. 1 root root 10077 May 12 11:38 wvb-logo-slogen.png What is in the .csv file is the first 12 characters that correspond to the company name. What PHP code would I use to grab the first 12 characters of search results match them up with what is in the .csv file and display the proper company name? This is what is inside of the .csv file: WVB_NUMBER,PRIMARY_SHORT_COMPANY_NAME,CURR_ISO_CNTRY_OF_INCORP "AIA000030001","THE NATIONAL BANK OF ANGUILLA","AIA" "AIA000030003","ANGUILLA ELECTRICITY COMPANY","AIA" "AIA000030005","KMT-HANSA","AIA" "ALB000040001","BURSE E TIRANES","ALB" "ANT000020000","RORENTO","ANT" "ANT000030001","INTRUM JUSTITIA","SWE" "ANT000030002","ORTHOFIX INTERNATIONAL","ANT" "ANT000030004","HAL TRUST","ANT" "ARE000030001","MASHREQBANK","ARE" "ARE000030002","COMMERCIAL BANK OF DUBAI","ARE" Any assistance would be greatly appreciated. im a complete novice. im using one of the tutorials on here to make a simple search form. the bit of script that i think outputs the results is $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['placing']},   {$row['racedate']},   {$row['horseid']}<br /><br />"; $i++; how do i make these results appear in a table, and how would i make it so there was a link on the date that clicked would show all the races on that day? sorry i advance as this is probably the most dumb of questions! 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. 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. 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) 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 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 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 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! 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! 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> 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. Just finished a search script. However, when type two keywords it will return duplicate entries: Code: [Select] elseif(isset($_GET['search'])){ $search=$_POST['search']; $search=str_replace(" ", ".", $search); header("Location: ./index.php?q=".$search); } elseif(isset($_GET['q'])){ $search=$_GET['q']; $keywords=explode(".",$search); $sql10000="SELECT product_id FROM $tbl_name2 WHERE keyword LIKE '%" . implode("%' OR keyword LIKE '%",$keywords) . "%'"; $result10000=mysql_query($sql10000); if(mysql_num_rows($result10000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); while($row15000=mysql_fetch_array($result15000)){ extract($row15000); $content.=$product_name; } } } } I have 3 products: Test2 - microphone Test3 - audio, microphone Test123 - audio When you search "audio" you get: Test3, Test123 When you search "microphone" you get: Test2, Test3 When you search "audio microphone" you get: Test2, Test3, Test3, Test123 with Test3 being a duplicate. Is there anyway to correct this? I tried SELECT DISTINCT * FROM, but there's no difference in the results returned, from what I have now. 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? Complete beginner here so just really looking for pointers on where to start. Been doing a bit of bug fixing on one of our sites because the past 3 programmers we've hired have disappeared on us. The big issue I'm looking to solve is the load time of a search. Our website (Love-Rugs) is taking about 6 or 7 seconds to perform a blank search (basically a quick browse) whereas out other site (Little-Persia) takes about a second. It wouldn't be so bad if it was just the initial search but going from one page (only 10 products listed per page) to the next takes the same amount of time. There seems to be an awful lot of queries (around 130-150) on the searches - however - when using some of the search options e.g. type and fabric to refine the search the queries actually stay high but the time to process the results is reduced significantly. I don't really understand why if the queries are still high the search time is much lower unless it's to do with the number of results returned. However this does not explain why Little-Persia (which has far more products on it) takes less time as there would obviously be more results. I realize that without code this isn't easy to answer so I'm just looking to see if someone can point me in the right direction to look at just now. 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...
|