PHP - Search Problem In Array
Similar TutorialsHi guys I have an php array like below // array $array_odds = array( "1.10" => "1/10", "1.11" => "1/9", "1.12" => "1/8", "1.14" => "1/7" ); // using the array echo $array_odds ['1.11']; // will echo in 1/9 As we can see in the array there is no 1.13, Is there a way I can pass it 1.13, and it gets me the closest fraction so if I passed it 1.13 it would return the fraction 1 lower which is 1.12 > 1/8 Thanks guys I have an array I would like to search that is being built from a data base as follows $result = mysql_query("SELECT id_one, id_two FROM accounts LIMIT 60"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf("ID_ONE: %s ID_TWO: %s", $row[0], $row[1]); echo "<br>"; } What I would like to do is after the array is created echo out a certain row from that array. Soi if the array looks like this key id_one id_two 1 458 444 2 468 455 3 467 466 I can search the array for 468 and it would return 455 Thanks I will be posting back if I find any new information my self. Whats the most efficient way of searching within a multi dimensional array? My Array = Array ( => Array ( => Item 1 [title] => Item 1 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) [1] => Array ( => Item 2 [title] => Item 2 [1] => 2012-03-21 [eventDate] => 2012-03-21 [2] => 21 [eventDay] => 21 ) ) String to find = '21' If (MY ARRAY contains STRING TO FIND) {} Clearly in this case there are several '21' (s) so if I only wanted to search the [eventDay] keys...would there be a fast effective and efficient manner? Thoughts and help gratefully received. Will hi, also i need to make a new array which includes all regex matches or strstr matches (it doesn't need to be regex) from the old array. now i have it like this: $array=array('cathouse','doghouse','mousehouse'); preg_match_all("@\,([a-zA-Z0-9\|]+dog[a-zA-Z0-9\|]+)\,@i",',|'.implode("|,|",$array).'|,',$matches); print_r($matches[1]); but is there a faster way to do this? (i tryed with loops but it's all slower) i also have all this in another loop. because it must match more words/strings then only "dog". EDITED. i have this code <?php $rulepages = array(); $rulepages[] = array("name" => "1111213", "page" => "fasdd21.php", "id" => "1"); $rulepages[] = array("name" => "41231245152", "page" => "fasd.php", "id" => "2"); ?> <table width="100%"> <tr> <td width="15%"> <?php sort($rulepages); foreach($rulepages AS $rulepage){ echo "<a href=\"?id=".$rulepage["id"]."\">".$rulepage["name"]."</a>"; echo "<br />"; } ?> </td> <td width="80%"> <?php $id = $_GET["id"]; // ?? ?> </td> </tr> </table> what do i do to search the array where the id equals the get ? thanks Hello I am facing a problem which i can not handle. I appreciate for any help. My Database is: Code: [Select] CREATE TABLE IF NOT EXISTS `shops` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `options` text, `user_name` varchar(250) NOT NULL , PRIMARY KEY (`id`), UNIQUE KEY `user_name` (`user_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='user data stored' AUTO_INCREMENT=1 ; And some sample data as below: Code: [Select] INSERT INTO `users` (`id`, `options`, `user_name`) VALUES (1, 'apple-orange-grape-bmw-toyota-fig-', 'user1'), (4, 'apple-tomato-pc-notebook-yellow-', 'user2'), (5, 'blue-green-orange-cdrom-', 'user3'), (6, 'orange-yellow-blue-pink-bread-', 'user4'); How can i display how many apples or green or any item selected by user? So far i tried in_array, array_count_values but seems no one is working. Regards Hello, I have an array, and I want to search the array for a particular 'word' and return how many times that 'word' is in the array. I tried using the search_array, but that just seems to find the first 'word' and return it. What I want it this: Code: [Select] $array = array(0-blue, 1-yellow, 2-red, 3-blue, 4-blue, 5-blue, 6-yellow); Lets say I want to see how many times the word 'blue' is in the array: $counter = 4; How would I achieve this? Thanks I'm somewhat new to OOP PHP, and I'm still learning, but basically I want searchcolumns() to set which MySQL columns that it'll search inside but I don't know where to go from what I've already coded. Here's the basic input to be sent to my classes file: $getusers = new database; $getusers->search($_GET['search']); $getusers->searchcolumns('username','account','email'); And to put it simple, I need my $where variable to output this: $where .= "(username LIKE '%$search%' OR account LIKE '%$search%' OR email LIKE '%$search%')"; Except replacing the already set columns with the ones that I assigned in the searchcolumns() array, and then adding an OR string if there's more than 1 column set. Here's the code as I have it at the moment, for obvious reasons, it doesn't work how I want it to: // Search columns function searchcolumns($columns) { $this->column = explode(", ", $columns); } // Search results function search($search) { $search = ($_POST['search']); if (isset($_GET['search']) && strlen($_POST['search']) > 1) { $searchresult = explode(" ", $search); $where = "WHERE"; foreach ($searchresult as $key => $search) { $where .= "($this->column LIKE '%$search%')"; if ($key != (sizeof($searchresult) - 1)) $where .= " AND "; } $this->where = $where; } } Sorry if this has been somewhat confusing to explain, but hopefully someone understands what I'm trying to achieve. Hi! I need a little bit coding help here. I have a table: Numbers, Active Under numbers can be 10000, 10001, 10002, 10003, 10004, 10005 and active can be 1 or 0, depends on is this row active or not. Now, i need to check, is there any numbers lost, i mean, (for example) in table i have numbers 10002, 10000 and 10005 Can somebody make script, what finds those lost numbers, in this case those a 10001, 10003 and 10004. All the best: Mart In the following code: echo $text[2] returns the word at that index but echo $key returns a blank. Can someone explain why is array-search not working in this indexed array? It does work when I test it with a key => value type array. <?php $myfile = fopen("test.txt", "r") or die("Unable to open file!"); while(!feof($myfile)) { $text[] = fgets($myfile); } fclose($myfile); $word = $_POST['word']; $key = array_search($word, $text); echo $key ?> I have successfully used the Yahoo local search API and received results in XML format. I am trying to use PHPs Simple XML to parse the data into an array so I can loop through and print specific elements. I cannot get to specific elements and I have read several threads online. Below is some code and below that is the XML. I am trying to get to the elements like title, address, etc. Code: [Select] $url = 'http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=<my yahoo api key>&category=Casinos&query=blackjack&zip=95035&radius=20&results=10'; $xml = file_get_contents($url); $phpobject = simplexml_load_string($xml); foreach($phpobject->attributes() as $name=>$attr) { $res[$name]=$attr; } Code: [Select] <ResultSet xsi:schemaLocation="urn:yahoo:lcl http://local.yahooapis.com/LocalSearchService/V3/LocalSearchResponse.xsd" totalResultsAvailable="48" totalResultsReturned="10" firstResultPosition="1"> − <ResultSetMapUrl> http://maps.yahoo.com/broadband/?q1=Milpitas%2C+CA+95035&tt=poker&tp=1 </ResultSetMapUrl> − <Result id="34179399"> <Title>Bay Area Poker Chip</Title> <Address>1274 Piper Dr</Address> <City>Milpitas</City> <State>CA</State> <Phone>(408) 263-8611</Phone> <Latitude>37.412359</Latitude> <Longitude>-121.891794</Longitude> − <Rating> <AverageRating>5</AverageRating> <TotalRatings>1</TotalRatings> <TotalReviews>1</TotalReviews> <LastReviewDate>1198993183</LastReviewDate> − <LastReviewIntro> I bought 100% real clay chips from here and obsolutely love it. I had a poker game that night and needed chips and a table. They had everything in stock and saved me time to look around. Great products and great service and I highly recommend this place to anybody </LastReviewIntro> </Rating> <Distance>1.33</Distance> − <Url> http://local.yahoo.com/info-34179399-bay-area-poker-chip-milpitas </Url> − <ClickUrl> http://local.yahoo.com/info-34179399-bay-area-poker-chip-milpitas </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1274+Piper+Dr+Milpitas+CA&gid1=34179399 </MapUrl> <BusinessUrl>http://bayareapokerchip.com/</BusinessUrl> <BusinessClickUrl>http://bayareapokerchip.com/</BusinessClickUrl> − <Categories> <Category id="96928631">Graphic Design</Category> </Categories> </Result> − <Result id="44540748"> <Title>Bay Area Poker Chip</Title> <Address>519 Montague Expy</Address> <City>Milpitas</City> <State>CA</State> <Phone>(408) 263-8611</Phone> <Latitude>37.409925</Latitude> <Longitude>-121.89489</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>1.48</Distance> − <Url> http://local.yahoo.com/info-44540748-bay-area-poker-chip-milpitas </Url> − <ClickUrl> http://local.yahoo.com/info-44540748-bay-area-poker-chip-milpitas </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=519+Montague+Expy+Milpitas+CA&gid1=44540748 </MapUrl> <BusinessUrl>http://www.bayareapokerchip.com/</BusinessUrl> <BusinessClickUrl>http://www.bayareapokerchip.com/</BusinessClickUrl> − <Categories> <Category id="96925976">Sporting Goods</Category> <Category id="96935378">Games</Category> </Categories> </Result> − <Result id="67710717"> <Title>Poker Da Vinci</Title> <Address>51 E Campbell Ave</Address> <City>Campbell</City> <State>CA</State> <Phone>(408) 866-4446</Phone> <Latitude>37.287157</Latitude> <Longitude>-121.94942</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>10.40</Distance> − <Url> http://local.yahoo.com/info-67710717-poker-da-vinci-campbell </Url> − <ClickUrl> http://local.yahoo.com/info-67710717-poker-da-vinci-campbell </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=51+E+Campbell+Ave+Campbell+CA&gid1=67710717 </MapUrl> <Categories/> </Result> − <Result id="21599986"> <Title>Bay 101 Banquet Facilities</Title> <Address>1801 Bering Dr</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 451-8888</Phone> <Latitude>37.373044</Latitude> <Longitude>-121.912125</Longitude> − <Rating> <AverageRating>4</AverageRating> <TotalRatings>2</TotalRatings> <TotalReviews>2</TotalReviews> <LastReviewDate>1200040214</LastReviewDate> − <LastReviewIntro> If youre looking for high limit action Bay 101 is the place to go in San Jose. You can regularly find limit games up to $80-$160 in their spacious high ceiling room. </LastReviewIntro> </Rating> <Distance>4.13</Distance> − <Url> http://local.yahoo.com/info-21599986-bay-101-banquet-facilities-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21599986-bay-101-banquet-facilities-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1801+Bering+Dr+San+Jose+CA&gid1=21599986 </MapUrl> <BusinessUrl>http://bay101.com/</BusinessUrl> <BusinessClickUrl>http://bay101.com/</BusinessClickUrl> − <Categories> <Category id="96929273">Casinos</Category> </Categories> </Result> − <Result id="21401964"> <Title>Thwart Poker Incorporated</Title> <Address>525 Lincoln Ave</Address> <City>Palo Alto</City> <State>CA</State> <Phone>(650) 329-9627</Phone> <Latitude>37.444049</Latitude> <Longitude>-122.151513</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>14.09</Distance> − <Url> http://local.yahoo.com/info-21401964-thwart-poker-incorporated-palo-alto </Url> − <ClickUrl> http://local.yahoo.com/info-21401964-thwart-poker-incorporated-palo-alto </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=525+Lincoln+Ave+Palo+Alto+CA&gid1=21401964 </MapUrl> − <Categories> <Category id="96926908">Internet Access Providers</Category> <Category id="96932773">Computer Business Solutions</Category> </Categories> </Result> − <Result id="21574436"> <Title>Blinky's Can't Say Lounge</Title> <Address>1031 Monroe St</Address> <City>Santa Clara</City> <State>CA</State> <Phone>(408) 985-7201</Phone> <Latitude>37.348893</Latitude> <Longitude>-121.94816</Longitude> − <Rating> <AverageRating>5</AverageRating> <TotalRatings>3</TotalRatings> <TotalReviews>3</TotalReviews> <LastReviewDate>1228667811</LastReviewDate> − <LastReviewIntro> Good drinks good prices good people. Who could ask for more..... </LastReviewIntro> </Rating> <Distance>6.39</Distance> − <Url> http://local.yahoo.com/info-21574436-blinky-s-can-t-say-lounge-santa-clara </Url> − <ClickUrl> http://local.yahoo.com/info-21574436-blinky-s-can-t-say-lounge-santa-clara </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1031+Monroe+St+Santa+Clara+CA&gid1=21574436 </MapUrl> − <Categories> <Category id="96926057">All Bars, Pubs, & Clubs</Category> <Category id="96926063">Bars & Pubs</Category> </Categories> </Result> − <Result id="21619987"> <Title>Barbara of Pauline's Cake Decorating Supplies</Title> <Address>1093 Malone Rd</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 978-9740</Phone> <Latitude>37.293702</Latitude> <Longitude>-121.889876</Longitude> − <Rating> <AverageRating>4.5</AverageRating> <TotalRatings>8</TotalRatings> <TotalReviews>8</TotalReviews> <LastReviewDate>1268173462</LastReviewDate> − <LastReviewIntro> I love this store. No matter what it is i am looking for weather it is some thing i remember from my child hood or some thing i saw in a magazine and i need it i know i can find it there. Yes they are a little rough around the edges but that is only because they are trying to get it across to you what will work and what will not. This is an old school store with people who know their stuff and are only trying to help you get the best end result possible. I am 46 years old and i took my class from Barbara when i first came out of high school and believe me she will not try to up sale you or tell you some thing is going to work if it will not. Go in expecting to be overwhelmed by stock and know you are going to get the best prices in town. Take the time to get to know the employees and the store and you will always go back to Paulines. I travel all the way from Livermore to get stuff i know i can only find there. Thanks for all your many years of being in business </LastReviewIntro> </Rating> <Distance>9.52</Distance> − <Url> http://local.yahoo.com/info-21619987-barbara-of-pauline-s-cake-decorating-supplies-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21619987-barbara-of-pauline-s-cake-decorating-supplies-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1093+Malone+Rd+San+Jose+CA&gid1=21619987 </MapUrl> − <Categories> <Category id="96928859">Wedding Supplies & Services</Category> </Categories> </Result> − <Result id="21602089"> <Title>Carey David Incorporated</Title> <Address>1624 Remuda Ln</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 453-7843</Phone> <Latitude>37.372385</Latitude> <Longitude>-121.908305</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>4.13</Distance> − <Url> http://local.yahoo.com/info-21602089-carey-david-incorporated-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-21602089-carey-david-incorporated-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=1624+Remuda+Ln+San+Jose+CA&gid1=21602089 </MapUrl> <BusinessUrl>http://dc-enterprises.com/</BusinessUrl> <BusinessClickUrl>http://dc-enterprises.com/</BusinessClickUrl> − <Categories> <Category id="96928508">Clothing Wholesalers</Category> <Category id="96928509">Clothing Manufacturers</Category> <Category id="96931030">Apparel Manufacturing</Category> </Categories> </Result> − <Result id="30246475"> <Title>Royal Casino Parties</Title> <Address>943 Berryessa Rd, #6</Address> <City>San Jose</City> <State>CA</State> <Phone>(408) 213-0904</Phone> <Latitude>37.363563</Latitude> <Longitude>-121.886341</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>4.71</Distance> − <Url> http://local.yahoo.com/info-30246475-royal-casino-parties-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-30246475-royal-casino-parties-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=943+Berryessa+Rd%2C+%236+San+Jose+CA&gid1=30246475 </MapUrl> <BusinessUrl>http://www.royalcasinoparties.com/</BusinessUrl> <BusinessClickUrl>http://www.royalcasinoparties.com/</BusinessClickUrl> − <Categories> <Category id="96925812">Entertainment Production</Category> <Category id="96930362">Gambling</Category> </Categories> </Result> − <Result id="25247620"> <Title>Bay Casino Gaming, Casino Party Rentals</Title> <Address/> <City>San Jose</City> <State>CA</State> <Phone>(408) 747-1977</Phone> <Latitude>37.338475</Latitude> <Longitude>-121.885794</Longitude> − <Rating> <AverageRating>NaN</AverageRating> <TotalRatings>0</TotalRatings> <TotalReviews>0</TotalReviews> <LastReviewDate/> <LastReviewIntro/> </Rating> <Distance>6.44</Distance> − <Url> http://local.yahoo.com/info-25247620-bay-casino-gaming-casino-party-rentals-san-jose </Url> − <ClickUrl> http://local.yahoo.com/info-25247620-bay-casino-gaming-casino-party-rentals-san-jose </ClickUrl> − <MapUrl> http://maps.yahoo.com/maps_result?q1=+San+Jose+CA&gid1=25247620 </MapUrl> <BusinessUrl>http://www.baycasinogaming.com/</BusinessUrl> <BusinessClickUrl>http://www.baycasinogaming.com/</BusinessClickUrl> − <Categories> <Category id="96925812">Entertainment Production</Category> <Category id="96925814">Party Rentals</Category> </Categories> </Result> </ResultSet> I'm just wondering if there is a function like array_key_exists that could take an array as the search parameter and check that all keys exist. It would be easy enough to code if I need to but I was hoping it would already exist. All wanted to use it for is a really quick form check to make sure that all the expected values were POSTed before I actually start filtering and validating individual fields. Thanks in advance for any recommendations Hi, I have a multidimensional array where each array has a parent id node to create a hierarchical tree. $hierarchy[] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); $hierarchy[] = array('id' => 2, 'parent_id' => 0, 'name' = 'root2'); $hierarchy[] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); $hierarchy[] = array('id' => 4, 'parent_id' => 1, 'name' = 'root1-2'); $hierarchy[] = array('id' => 5, 'parent_id' => 3, 'name' = 'root1-1-1'); $hierarchy[] = array('id' => 6, 'parent_id' => 2, 'name' = 'root2-1'); I'm trying to come up with a recursive key/value search routine that will return all ancestor arrays of the found item without knowing the depth of the tree. All nodes with 0 for the parent_id are root level nodes. Basically I want to search for something like "where key = name and value = xxx" and have it return all ancestors of that node. So if I wanted to search for "key = name and value = root1-1", it should return and array like: array[0] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); //parent node first array[1] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); //first child after parent if I was to search for "key = name and value = root1-1-1", it should return: array[0] = array('id' => 1, 'parent_id' => 0, 'name' = 'root1'); //parent node first array[1] = array('id' => 3, 'parent_id' => 1, 'name' = 'root1-1'); //first child after parent array[2] = array('id' => 5, 'parent_id' => 3, 'name' = 'root1-1-1'); //first grandchild So the main problem comes in the iteration and keeping track of parents. If I just want the array with the answer I can get that node, but I can't get it with all of the ancestors attached. How would you go about this? Any good ideas out there? Thanks! Hi, Can I know how to resolve this problem? Notice: Undefined variable: x in C:\wamp\www\i-document\search.php on line 39 Notice: Undefined variable: construct in C:\wamp\www\i-document\search.php on line 41 1 results found! Thankz. <html> <body> <form id="form1" method="GET" action="search.php"> <table width="446" height="135" border="1" align="center"> <tr> <td height="31" colspan="2" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2">Search :</span></td> </tr> <tr> <td width="374" height="96" align="center" valign="middle" bgcolor="#990000"><span class="style1 style2"> <label> <div align="left">Keyword : <input name="search" type="text" id="search" size="40" /> </div> </label> </span> <td width="56" align="center" valign="middle" bgcolor="#990000"> <div align="left"> <input type = "submit" name="submit" value="search" /> </div></td> </tr> </table> </form> </body> </html> [b][u]search.php[/u][/b] <html> <title>Search</title> </head> <body><br /><br /> <div class="MySearch"></div><br /> <?php //Get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You didn't submit a keyword."; else { if (strlen($search)<=1) echo "Search term too short"; else { echo "You searched for <b>$search</b><hr size='1'>"; //connect to database mysql_connect("localhost","root",""); mysql_select_db("idoc"); //explode search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each); { //Construct Query $x++; if ($x==1) $construct .= "file_name LIKE '%$search_each%'"; else $construct .= " OR file_name LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM document 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 ($runrows = mysql_fetch_assoc($run)) { //Get data $ref = $runrows['file_ref']; $filename = $runrows['file_name']; $owner = $runrows['owner']; $url = $runrows['url']; echo " <table> <tr> <td> $ref </td> <td> $filename </td> <td> $owner </td> <td><a href='$url'>$url</a></td> </tr> </table> "; } } } } ?> I have a number of records of the html sections of a series of Google Earth placemarks that I managed to extract from the raw kml file. The purpose of the exersize was to then use the simplehtmldom.php api to extract the DATA from the raw html code. Some of the process is going well... and some is NOT. I have found that if I modify the raw html code by entering ID attributes into the html code the simplehtmldom api has an easy time identifying the desired data, and the data can be far 'cleaner' by entering an id attribute as 'close' to the data as possible. But doing a php text search and replace often requires finding a 'unique' identifyable portion of the html code and THEN placing the 'id' attribute in a nearby html tag because the desired data is nested inside a non-unique tag. As in I can identify a SPECIFIC <td> tag section where the data i desire is located but the data is nested inside a <font> tag inside the <td> cluster. Hence my problem... If I do a search in the following code... Code: [Select] <td><b><font size="+2" color="#FF0000">Neighborhood:</font> <font size="+2" color="#0000FF">City of Sidney</font></b></td> I can locate the 'Neighborhood:' string because it is unique in the whole html code. Then by some charcter counting I am desiring to put my 'id' attribute in the NEXT font tag because it surrounds the desired data the 'City of Sidney'... as in... Code: [Select] <td><b><font size="+2" color="#FF0000">Neighborhood:</font> <font id="neighborhood" size="+2" color="#0000FF">City of Sidney</font></b></td> With this modification the desired data is easily found and cleanly produced. But the html code while all operating correctly in a web page is not all identicle from a 'whitespace' point of view AND thus my problem. If I search the following code... Code: [Select] <td> <b><font size="+2" color="#FF0000">Neighboorhood:</font> <font size="+2" color="#0000FF">Greenacre</font></b> </td> While being identical as far as html is concerned if I search this code for the 'Neighboorhood:' identifier I find it... but then attempting to place the id tag into the NEXT font tag is being problematic. What i seem to need is a function that once the 'Neighboorhood:' string position is identied and noted in the whole of the html code, to FIND and modify the NEXT occurance of a font tag no matter what whitespace (or special charachters) may be occuring. Any suggestions?? eatc7402 Good morning, Its about this website www.deltaboatcenter.nl Boats page! I wanna search tough the boats we are selling with a seach menu, the menu is there (see website) but is got 2 scrips (below) the first one i use now the boats preview nicely on the website and work good but cant search with the boat menu for boat brands. the second one does search trough boat brands but doenst come up with boats at all.. Code: [Select] <?php include('dbclass/db.php'); include('define.php'); //////////include('pagination.class.php'); include('include/ps_pagination.php'); include_once('classes/easyphpthumbnail.class.php'); $thumb = new easyphpthumbnail; $thumb -> Thumbheight = 140; $thumb -> Thumbwidth = 200; $thumb -> Thumblocation = 'thumb/'; $thumb -> Thumbprefix = 'thumb_'; $thumb -> Thumbsaveas = 'png'; if($lang == 'eng') { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } elseif($lang == 'dutch') { $header = "header_dutch.php"; $footer = "footer_dutch.php"; $where = 'language_id=2'; $language =2; } elseif($lang == 'german') { $header = "header_german.php"; $footer = "footer_german.php"; $where = 'language_id=3'; $language =3; } else { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } //select query $obj = new Database; $obj ->select('english_boats','',$where); $query= "select * from english_boats where language_id=$language"; $pager = new PS_Pagination($obj->getConnection(),$query,5,3); $rs = $pager->paginate(); /////////var_dump($rs); ///////exit; $sel= "select * from english_boats"; /// $q=mysql_query($sel) or die mysql_error(); //generate thumbnail // include('boat_function.php'); ?> <!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> <script type='text/javascript' src='jspop/jquery.js'></script> <script type='text/javascript' src='jspop/jquery.simplemodal.js'></script> <script type='text/javascript' src='jspop/osx.js'></script> <script src="prototype.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Delta Boat company boat listing</title> <link href="boatstyle/boatstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <script> function dosubmit( ) { new Ajax.Updater( 'result', 'search_boat.php', { method: 'post', parameters: $('myform').serialize() } ); $('myform').reset(); } //get_call function get_call( ) { if(document.calform.name.value=="") { //inlineMsg('name','please enter the name',20); alert('Please enter the name'); document.calform.name.focus(); return false; } var phone = /-\d{7}/ ; if(!phone.test(document.calform.tel_number.value)) { alert('Please enter the telephone number'); document.calform.tel_number.focus(); return false; } var aemail= /^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$/; if(!aemail.test(document.calform.email.value)) { alert('Please enter the valid email address'); document.calform.email.focus(); return false; } new Ajax.Updater( 'get_result', 'make_home_appointment.php', { method: 'post', parameters: $('calform').serialize() } ); $('calform').reset(); } </script> <div class="container"> <?php include($header); ?> <div class="clear"></div> <div class="line"></div> <div class="searchPanel"> <div class="searchTop"></div> <div class="clear"></div> <div class="searchMid"> <div class="searchTitle">Search</div> <div class="searchForm"> <!--javascript:get(document.getElementById('myform'));--> <form id="myform"> <input type="hidden" name="language" value="<?php echo $language;?>" /> <table class ="textboxAlign" width="100%" border="0"> <tr> <td width="38%" class="searchItem">Brand:</td> <td width="62%" class="searchItem"><div class="textboxAlign"> <select name="brand" id="brand" style="width:140px"> <option value="any">any</option> <?php while($r_b =mysql_fetch_array($q)){ ?> <option value="<?php echo $r_b['boat_brand'];?>"><?php echo $r_b['boat_brand'];?></option> <?php }?> <!-- <option value="brand B">Company B</option> <option value="brand C">Company C</option> <option value="brand D">Company D</option>--> </select> </div></td> </tr> <tr> <td nowrap="nowrap" class="searchItem">Year From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="year_from" id="year_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> To: <input type="text" name="year_to" id="year_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> </div> </td> </tr> <tr> <td class="searchItem">Price From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="price_from" id="price_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> To: <input type="text" name="price_to" id="price_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''"/> </div></td></tr> <tr> <td class="searchItem" valign="top">Features:</td> <td nowrap="nowrap" class="searchItem"><input type="checkbox" name="heating" id="heating" value="588" /> Heating System</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="generator" id="generator" value="661" /> Generator</td> </tr> <tr> <td> </td> <td class="searchItem" align="left"> <input type="checkbox" name="bow" id="bow_thruster" value="297" /> Bow Thruster</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="stern" id="stern_thruster" value="964" /> Stern Thruster</td> </tr> <tr> <td colspan="2" align="center"> <input type="button" onclick="dosubmit()" value="Search"> <!-- <input type="button" name="button" class="button" value="Search" onclick="javascript:get(this.parentNode);" />--> </td> </tr> </table> </form> </div> </div> <div class="searchBase"></div> <div class="clear"></div> </div> <div id="result"> <div class="thumbnailsDisplayArea"> <?php if(!isset($_GET['page']) || ($_GET['page']==1)) { $i=1; } else { $i=(($_GET['page']-1)*10)+1 ; } if(mysql_num_rows($rs)>0) { while($row_fetch=mysql_fetch_assoc($rs)) {?> <?PHP $i++; ?> <div class="listPanel"> <div class="listTop"></div> <div class="listMid"> <a href="boat_detail.php?id=<?php echo $row_fetch ['boat_id'];?> & common_id=<?php echo $row_fetch['common_id']; ?>"><div class="itemName" align="left"><?php echo $row_fetch['boat_title'];?> </div></a> <div class="itemPrice"><?php echo $row_fetch['price_currency'];?> <?php echo $row_fetch['boat_price'];?></div> <div class="clear"></div> <div class="itemDescription" align="left"> <a href="boat_detail.php?id=<?php echo $row_fetch['boat_id'];?>&common_id=<?php echo $row_fetch['common_id']; ?>"><?php echo $row_fetch['boat_summary'];?></a> <div class="moreLink"><!--<a href="boat_detail.php?id=<?php //echo $value['boat_id'];?> & common_id=<?php //echo $com_id?>">more...</a>--></div> <div class="clear"></div> </div> <div class="ItemThumbnail"> <a href="boat_detail.php?id=<?php echo $row_fetch ['boat_id'];?>&common_id=<?php echo $row_fetch['common_id'];?>"> <?php ///////exit; $where=sprintf("common_id=%d",$row_fetch['common_id']); $obj ->select('boat_images','',$where); $array = $obj ->get(''); if(count($array)>0){ $imagename=$array[0]["boat_image"]; $thumb_name="thumb/thumb_$imagename"; $thumb_name=str_replace("jpg","png",$thumb_name); if(!file_exists($thumb_name)) { $thumb -> Createthumb("admin/uploads/$imagename","file"); } ?><?php } ?> <img src="<?php echo $thumb_name; ?>" border=0 /> </a><br /> </div> </div> <div class="listBase"></div> </div> <div class="clear"></div> <?php }}else { echo 'NO image found';}?> <div class="paging2"> <?php if(mysql_num_rows($rs)>0){ echo $pager->renderFullNav(); }?> <div class="clear"></div> </div></div> <div class="verticalSpacer"></div> <div class="clear"></div> <div class="line"></div> <div class="footer"> <?php include($footer);?></div> <?php include('language.php');?> <div class="clear"></div> </div> </div> </body> </html> Code: [Select] <?php include('dbclass/db.php'); include('define.php'); if($lang == 'eng') { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } elseif($lang == 'dutch') { $header = "header_dutch.php"; $footer = "footer_dutch.php"; $where = 'language_id=2'; $language =2; } elseif($lang == 'german') { $header = "header_german.php"; $footer = "footer_german.php"; $where = 'language_id=3'; $language =3; } else { $header = "header_eng.php"; $footer = "footer_eng.php"; $where = 'language_id=1'; $language =1; } //select query $obj = new Database; $obj ->select('english_boats','',$where); $array = $obj ->get(''); //get brands $s = "select distinct boat_brand from english_boats"; $q = mysql_query($s) or die(mysql_error()); //generate thumbnail ?> <!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> <script type="text/javascript" language="javascript"> var http_request = false; function makeRequest(url, parameters) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('GET', url + parameters, true); http_request.send(null); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { //alert(http_request.responseText); result = http_request.responseText; document.getElementById('myspan').innerHTML = result; } else { alert('There was a problem with the request.'); } } } function get(obj) { var getstr = "?"; for (i=0; i<obj.childNodes.length; i++) { if (obj.childNodes[i].tagName == "INPUT") { if (obj.childNodes[i].type == "text") { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } if (obj.childNodes[i].type == "hidden") { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } if (obj.childNodes[i].type == "checkbox") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } else { getstr += obj.childNodes[i].name + "=&"; } } if (obj.childNodes[i].type == "radio") { if (obj.childNodes[i].checked) { getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&"; } } } if (obj.childNodes[i].tagName == "SELECT") { var sel = obj.childNodes[i]; getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&"; } } document.getElementById('myspan').innerHTML = '<img src="images/wait30trans.gif" alt="loading" />' + 'Loading'; //setTimeout('alert(\'Surprise!\')', 5000); makeRequest('search_boat.php', getstr); } </script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Delta Boat company about us</title> <link href="boatstyle/boatstyle.css" rel="stylesheet" type="text/css" /> </head> <body class="background"> <div class="container"> <?php include($header); ?> <div class="clear"></div> <div class="line"></div> <div class="searchPanel"> <div class="searchTop"></div> <div class="clear"></div> <div class="searchMid"> <div class="searchTitle">Search</div> <div class="searchForm"> <!--javascript:get(document.getElementById('myform'));--> <form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform"> <!--<form action="" name="form">--> <table class ="textboxAlign" width="100%" border="0"> <tr> <td width="38%" class="searchItem">Brand:</td> <td width="62%" class="searchItem"><div class="textboxAlign"> <select name="brand" id="brand" style="width:140px"> <option value="any">any</option> <?php while($r_b =mysql_fetch_array($q)){ ?> <option value="<?php echo $r_b['boat_brand'];?>"><?php echo $r_b['boat_brand'];?></option> <?php }?> <!-- <option value="brand B">Company B</option> <option value="brand C">Company C</option> <option value="brand D">Company D</option>--> </select> </div></td> </tr> <tr> <td nowrap="nowrap" class="searchItem">Year From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="year_from" id="year_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> To: <input type="text" name="year_to" id="year_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> </div> </td> </tr> <tr> <td class="searchItem">Price From:</td> <td class="searchItem"><div class="textboxAlign"> <input type="text" name="price_from" id="price_from" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> To: <input type="text" name="price_to" id="price_to" value="any" size="5" onfocus="if(this.value == this.defaultValue) this.value = ''" /> </div></td></tr> <tr> <td class="searchItem" valign="top">Features:</td> <td nowrap="nowrap" class="searchItem"><input type="checkbox" name="heating" id="heating" value="588" /> Heating Sysytem</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="generator" id="generator" value="661" /> Generator</td> </tr> <tr> <td> </td> <td class="searchItem" align="left"> <input type="checkbox" name="bow" id="bow_thruster" value="297" /> Bow Thruster</td> </tr> <tr> <td> </td> <td class="searchItem"> <input type="checkbox" name="stern" id="stern_thruster" value="964" /> Stern Thruster</td> </tr> <tr> <td colspan="2" align="center"> <input type="button" name="button" class="button" value="Submit" onclick="javascript:get(this.parentNode);" /> </td> </tr> </table> </form> </div> </div> <div class="searchBase"></div> <div class="clear"></div> </div> <div id="myspan"> <div class="thumbnailsDisplayArea"> <?php if(count($array)) { while(list($k,$value) = each($array)) { $com_id = $value['common_id']; $im_where = 'common_id='.$com_id; $obj ->select('boat_images','',$im_where); $im_array = $obj ->get(''); $filename = $im_array[0]['boat_image']; ?> <div class="listPanel"> <div class="listTop"></div> <div class="listMid"> <a href="boat_detail.php?id=<?php echo $value['boat_id'];?> & common_id=<?php echo $com_id?>"><div class="itemName" align="left"><?php echo $value['boat_title'];?> </div></a> <div class="itemPrice"><?php echo $value['price_currency'];?> <?php echo $value['boat_price'];?></div> <div class="clear"></div> <div class="itemDescription" align="left"> <a href="boat_detail.php?id=<?php echo $value['boat_id'];?>&common_id=<?php echo $com_id?>"><?php echo $value['boat_summary'];?></a> <div class="moreLink"><!--<a href="boat_detail.php?id=<?php //echo $value['boat_id'];?> & common_id=<?php //echo $com_id?>">more...</a>--></div> <div class="clear"></div> </div> <div class="ItemThumbnail"><a href="boat_detail.php?id=<?php echo $value['boat_id'];?>&common_id=<?php echo $com_id?>"><?php //createThumbnail($filename);?><img src="admin/uploads/<?php echo $im_array[0]['boat_image'];?>" width="200px" height="140px" border="0" /></a></div> </div> <div class="listBase"></div> </div> <?php }}?> <div class="clear"></div> </div> </div> <div class="verticalSpacer"></div> <div class="clear"></div> <div class="line"></div> <div class="footer"> <?php include($footer);?></div> <?php include('language.php');?> <div class="clear"></div> </div> </body> </html> The strange thing is both scripts work but not good. the first one wont seach trou the boat list. and the second one does but doesent show the boats in the first place.. Does some one has any idea what i'm doing wrong? Kind regarts Hey guys im just starting to use Prepared Statements in php and i am trying to build a search but i have come across a problem. Hope someone can help or point me to more information on how to resolves this. Ok here is the code below:: public function search($string) { if(strlen($string) > 40) { return "Woow too many words, please shorten your search."; } if(empty($string)) { return "I'm a search, you type things in and I find. Please enter something and try again!"; } if(strlen($string) <= 3) { return "Come on dude, you expect me to find summin with that? Type some more tags in!"; } $x=0; // Teh string could be multiple searches so explode:: $string = explode(" ", $string); foreach($string as $search) { $x++; if($x == 1) { @$sql .= "(blog_tags LIKE '%$search%')"; } else { @$sql .= " OR (blog_tags LIKE '%$search%')"; } } $sql = "SELECT blog_tags FROM subarc_blog WHERE $sql LIMIT 40"; // TODO:: Count how many search results found:: $stmt = $this->conn->prepare($sql); $stmt->execute(); $stmt->bind_result($search); Ok by using the bind_result() i need to know how many result are being returned to add them to a variable is this correct ? if so how can i tell how many results have been returned ? hope this makes sense Hello , i need some help on this line. Line: $compose_a = mysql_query("SELECT * FROM users WHERE username LIKE '%". realEscape($sendto) ."%' LIMIT 1") or die(mysql_error()); From the code : <?php if(isset($_GET['usercp']) && $_GET['send'] == 'true') { if($_POST['sendtitle'] == "") { echo "You need to have a message title."; } else { if($_POST['sendto'] == "") { echo "You must enter the username of the user you wish to send a message to."; } else { if($_POST['sendtext'] == "") { echo "You have not entered anything to send"; } else { $sendto = str_replace('_', ' ' , $_POST['sendto']); $compose_a = mysql_query("SELECT * FROM users WHERE username LIKE '%". realEscape($sendto) ."%' LIMIT 1") or die(mysql_error()); if(mysql_num_rows($compose_a) >= 1) { While($compose_b = mysql_fetch_array($compose_a)) { $sendto = $compose_b['id']; } mysql_query("INSERT INTO `notifications` (ipaddress, senderid, recieverid, sent, title, text) VALUES ('". $_SERVER['REMOTE_ADDR'] ."', '". $_SESSION['id'] ."', '" . $sendto . "', NOW(), '". htmlspecialchars($_POST['sendtitle']) ."', '". htmlspecialchars($_POST['sendtext']) ."')") or die(mysql_error()); echo "Message has been sent."; } else { echo "The username you entered does not Exist"; } } } } } ?> The $sendto is a username. i want to make it so if a user puts a Uppercase letter or a lowercase letter or a space where a '_' should be. it still matchs whats in the database. if you find a better way of doing this please post it Looking for some technical assistance on a property search query im having some problems with on WP. Using the Agentpress theme I have put together a client site that is fully functional, however the client has asked that the search is altered is altered slightly and i'm having trouble working out how to do it. I'm not a database / PHP person - I have managed so far, but this is beyond my understanding. I have 2 separate search query issues. The first is that my client wants the bedrooms to be searchable with the following options: 1 or more 2 or more 3 or more 4 or more The second is that they want the availability of the property to only give 2 options: Availabile properties only Include Let Agreed Here is the site: test.taylorslettings.co.uk The property data and field names I have are being automatically created by their system and provides the information in the dropdowns as you see it in the search box on the site. The theme (Agentpress) dictates the search and how it works at present. I have no idea how to alter the search so it shows presents the results to meet the clients needs. We are at the very end stages of going live, so any urgent help would be gratefully appreciated. Thanks very much. |