PHP - How To Fetch Google Search Results In Php ??
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 Similar TutorialsI am using html5 and all the pages have h2 headings as titles. They all show up in google search results fine. The only thing that doesn't show up fine are some of the descriptions under each heading. Some meta descriptions show up fine under the correct heading title, while rest shows ALL the heading tags AS description under each search result.
For eg.
Cars
www.mywebsite.com/category?id=5&name=cars Ok, so I have a bit of code but it's not working as it should, would one of you guys have a look at it and let me know where I'm going wrong? Basically I need to be able to input several words or terms into the text area, each on a separate line and have the results displayed something like: hello: 23,000.000 hello world: 19,000,000 world: 278,000,000 I also see that the script is not searching the words / terms inside quotes (EG. "hello world") TIA Code: [Select] <html> <body> <?php function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)') { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/'); $result = curl_exec ($ch); curl_close ($ch); return $result; } $s = $_GET['s']; if (isset($s)) { echo "<p><i>Search for $s</i></p>"; $s = urlencode($s); $data = my_fetch("http://www.google.com/search?hl=en&q=" . $s . "&btnG=Google+Search"); $data = strip_tags($data); $find = 'Results 1 - 10 of about '; $find2 = ' for'; $data = strstr($data, $find); $pos = strpos($data, $find2); $search_number=substr($data,strlen($find), $pos-strlen($find)); echo "Total Results: $search_number"; } else { ?> <form name="form1" id="form1" method="get" action=""> <div align="left"> <p> <textarea name="s" type="text" id="s" rows="8" style="width:60%" /></textarea><br /> <input type="submit" name="Submit" value="Results" /></p> Put "" around the string: <input type="checkbox" checked name="apos" value="true" /><br /> </div> </form> <p> <?php } ?> </p> </body> </html> I have this code and Im using a while to fetch all the data where users comments are but i want to change it to fetch only 25 rows at a time and each time it refreshes it fetch's 25 more different rows. Code: [Select] <?php include "../../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $username = mysql_real_escape_string($_GET['username']); //If friend is set, then query for it, otherwise return all of the friends comments. $friend = (isset($_GET['friend'])) ? ' AND b.friend = \'' . mysql_real_escape_string($_GET['friend']) . '\' ' : NULL; $sql = "SELECT a.username,a.comment,a.timestamp,a.title,a.picture,a.pic_status,a.pic_url,b.id,c.avatar,c.atimestamp,c.onlinestatus FROM (user_comments as a JOIN accounts as c USING(username))JOIN `user_friends_list` as b ON (b.friend = a.username)WHERE (b.username = '$username' $friend AND b.status = 1) ORDER BY a.id DESC"; $result = mysql_query($sql); $user_xml = "<?xml version=\"1.0\"?>\n"; //$user_xml .= "<root>\n"; if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $user_xml .= "<comment>\n"; $user_xml .= "<image>" . $row['avatar'] . "</image>\n"; $user_xml .= "<name>" . $row['username'] . "</name>\n"; $user_xml .= "<text>\n"; $user_xml .= "<![CDATA[ ". $row['comment'] ."]]>\n"; $user_xml .= "</text>\n"; $user_xml .= "<time>" . $row['timestamp'] . "</time>\n"; $user_xml .= "<title>" . $row['title'] . "</title>\n"; $user_xml .= "<picture>" . $row['picture'] . "</picture>\n"; $user_xml .= "<status>" . $row['pic_status'] . "</status>\n"; $user_xml .= "<url>" . $row['pic_url'] . "</url>\n"; $user_xml .= "<ntimestamp>" . $row['atimestamp'] . "</ntimestamp>\n"; $user_xml .= "<online>" . $row['onlinestatus'] . "</online>\n"; $user_xml .= "</comment>\n"; } } //$user_xml .= "</root>\n"; echo $user_xml; ?> So i think i can do something like this but im not to sure. just add a if statement Code: [Select] while ($row = mysql_fetch_assoc($result)) { $user_xml .= "<comment>\n"; $user_xml .= "<image>" . $row['avatar'] . "</image>\n"; $user_xml .= "<name>" . $row['username'] . "</name>\n"; $user_xml .= "<text>\n"; $user_xml .= "<![CDATA[ ". $row['comment'] ."]]>\n"; $user_xml .= "</text>\n"; $user_xml .= "<time>" . $row['timestamp'] . "</time>\n"; $user_xml .= "<title>" . $row['title'] . "</title>\n"; $user_xml .= "<picture>" . $row['picture'] . "</picture>\n"; $user_xml .= "<status>" . $row['pic_status'] . "</status>\n"; $user_xml .= "<url>" . $row['pic_url'] . "</url>\n"; $user_xml .= "<ntimestamp>" . $row['atimestamp'] . "</ntimestamp>\n"; $user_xml .= "<online>" . $row['onlinestatus'] . "</online>\n"; $user_xml .= "</comment>\n"; } I only wnat to read 25 comments at a time and when i click a button to read more then it reads 25 more rows but it dose not read the data unless requested... can any one help me? Hi, I've used this code before, but have had to make some modifications and am now getting a mysql fetch array error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tesolcla/public_html/test/results10k201010.php on line 134 If anyone can help, it would be much appreciated. Code: [Select] <?php $dbcnx = @mysql_connect('localhost', 'MYUSERNAME', 'MYPASSWORD'); //$dbcnx = @mysql_connect('localhost', 'root', 'mysql'); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('MYDATABASE')) { //if (!@mysql_select_db('rac')) { exit('<p>Unable to locate the results ' . 'database at this time.</p>'); } $asc_on = '<img src="images/results_sorting/Asc.gif" border="0" />'; $asc_off= '<img src="images/results_sorting/AscOff.gif" border="0" />'; $desc_on = '<img src="images/results_sorting/Desc.gif" border="0" />'; $desc_off= '<img src="images/results_sorting/DescOff.gif" border="0" />'; $sortfield = isset($_GET['sort']) ? $_GET['sort'] : '4'; $sorttype = isset($_GET['type']) ? $_GET['type'] : '1'; for($i=1; $i<5; $i++) { if($i==$sortfield) { if ($sorttype==1) $srt[$i] = $asc_on.'<a href="?sort='.$i.'&type=2">'.$desc_off.'</a>'; else $srt[$i] = '<a href="?sort='.$i.'&type=1">'.$asc_off.'</a>'.$desc_on; } else { $srt[$i] = '<a href="?sort='.$i.'&type=1">'.$asc_off.'</a><a href="?sort='.$i.'&type=2">'.$desc_off.'</a>'; } } $fields = array("firstname", "lastname", "time", "position"); $sorts = array("ASC", "DESC"); $field = $fields[$sortfield-1]; $sort = $sorts[$sorttype-1]; $field = $field=="" ? $fields[4] : $field; $sort = $sort=="" ? $sorts[0] : $sort; $sql = mysql_query("SELECT firstname, lastname, time, position FROM 10k_results ORDER BY $field $sort"); echo "<table border='1' align='center' bordercolor='#000000' CELLPADDING=5 cellspacing='0' STYLE='font-size:13px'>"; echo "<tr bgcolor='#008000' STYLE='color:white'> <td>*</td><td><H3>First name $srt[1]</h3></td> <td><H3>Lastname $srt[2]</H3></td> <td><H3>Time $srt[3]</H3></td> <td><H3>Position $srt[4]</H3></td></tr>"; // keeps getting the next row until there are no more to get $row_counter = 1; //create row counter with default value 0 // Print out the contents of each row into a table while ($row = mysql_fetch_array($sql)) { // Print out the contents of each row into a table echo "<tr>\n"; echo "</td><td>"; echo $row_counter++; echo "</td>"; echo "<td>{$row['firstname']}</td>\n"; echo "<td>{$row['lastname']}</td>\n"; echo "<td>{$row['time']}</td>\n"; echo "<td>{$row['position']}</td>\n"; echo "</tr>\n"; } echo "</table>"; ?> I require a page to be added to my website. This page will facilitate a refined search via Google, Bing and Yahoo search engine simultaneously , show the top 5 of each engine. Is this possible using php ? Thank's 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 I am trying to work out how to work out rank on google results. I so far have the results of the first page however can not work out how to get to the next page. <?php function google_search_api($args, $referer = 'google.php', $endpoint = 'web'){ $url = "http://ajax.googleapis.com/ajax/services/search/".$endpoint; if ( !array_key_exists('v', $args) ) $args['v'] = '1.0'; $url .= '?'.http_build_query($args, '', '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // note that the referer *must* be set curl_setopt($ch, CURLOPT_REFERER, $referer); $body = curl_exec($ch); curl_close($ch); //decode and return the response return json_decode($body); } $rez = google_search_api(array( 'q' => 'test', )); print_r($rez); ?> Now I working off the http://code.google.com/intl/en/apis/ajaxsearch/documentation/reference.html#_class_GSearch What I am trying to do is build is http://www.further.co.uk/tools/search-position-check/ I am almost there with doing it with bing results function bingrank($keyword,$domain){ $rank = '0'; $urls = array(); for($i=0;$i<10;$i++){ $rn=$i=='0'?'':$i; $query = "http://www.bing.co.uk/search?q=".urlencode($keyword)."&first=".$rn."1"; $result_page = file_get_contents($query); preg_match_all('/class="sb_tlst"><h3><a href="(.*?)"/',$result_page,$matches); foreach($matches[1] AS $url){ $urlst = str_replace('www.', "", preg_replace('(^http://|/$)','',$url)); $urlsz = explode("/", $urlst); $urls[] = $urlsz[0]; if ($urlsz[0] == $domain){ return $i+1; } } } return 'N/F'; } Any advice or help would be great. 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. 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 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); I got this code made for me to put on my google search code. <?php $click_value = '0.001'; //Amount in dollars that each click is worth function increment_clicks() { //Get current click count if(file_exists('click_count.txt')) $clicks = file_get_contents('click_count.txt'); else $clicks = 0; //Add current click to count $clicks++; //Save new value to file $file = fopen('click_count.txt', 'w'); fwrite($file, $clicks); fclose($file); } function get_click_amount() { global $click_value; //Get current click count if(file_exists('click_count.txt')) $clicks = file_get_contents('click_count.txt'); else $clicks = 0; //Return value of all clicks based on $click_value, formatted to 2 decimal places return number_format($clicks * $click_value, 3); } if (isset($_POST['search'])) { //Search button was clicked, increment count increment_clicks(); } $click_amount = get_click_amount(); ?> <html> <head> </head> <body> <center> <p id="click_amount">$<?php echo $click_amount; ?></p> <form action="" method="POST"> <input type="text" name="search" value="" /> <input type="submit" value="Search" /> </form> </center> </body> </html> Now i do not know how to put it in my google code if you put it on a page by itself it works. I do not know if i can list my google code here so if anyone can help i will pm them m google code. THANKS I am developing a portion of a site for a client. He has an 800 page pdf document that he would like the software to search based on client input. When the user searches, he would like it to display a Google-esque search results page that would display a title (Probably the chapter in which the result was found), then an excerpt from the text surrounding the matching keyword(s). When the user clicks the link, he would like it to take them to the page where the match was found. A big drawback is that this document will be changing fairly regularly and will need to be updated. Initially I thought I could store the pdf in a database as text/html with each page being a record in the table, but with frequent changes, I fear this would be a nightmare to manage. My only other thought is to store the file as one big entry in a table and search the entire entry, which I have done some searching and have come up with some options, but when you click it loads the entire db entry. This would create issues with an 800 page document. 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! 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 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 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. |