PHP - Count Records Similar To A Given Word?
How to COUNT the number of records (pulled from a db)which contains the word "APPROVED". This code doesn't work though.
$result1; $result2; $result3; $approvedApplicants = COUNT($result1=='Approved', $result2=='Approved', $result3=='Approved') echo ($approvedApplicants) Similar TutorialsMy script is finally working as intended, but I want to add some additional data results. I am trying to resolve how I can display a count of ONLY the records updated by my query: // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches In this query I count ALL records selection: // START :: Create query to be displayed as final results of original codes table. $result = mysql_query("SELECT * FROM orig_codes_1a") or die(mysql_error()); I want to display a count on this part of the query: ....concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2).... Hello everybody, I'm trying to write some code similar to Odesk.com or DMOZ.ORG. I need to count the number of listings in each category. Look here "http://ibatty.org/browse.php" to get a better idea of what I'm doing. That is the page I'm trying to add this function to. I've been having major issues with the COUNT function. Code: [Select] $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='billboards'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) { echo $row[COUNT(category)]; } As you can see this works, but I'm trying to add State, Area code and Zip functuality to search through the data more precisely. This has been giving me problems though and the way I currently have it setup . . . I'd have 25+ SELECT COUNT() querys going on 1 page. (I don't know if that is very good?) 5$ via paypal to whoever can help me solve this. If I did not explain what I needed very well, please ask questions for me to clarify. Thank you in advance I need help with a count query and displaying it. Right now have the following query $query = "SELECT COUNT(*) as num1 FROM spoiler WHERE id='$id"; $total_trophies = mysql_fetch_array(mysql_query($query)); $total_trophies = $total_trophies[num1]; So I have another query that pulls how many trophies there are. That way I can do the following ? echo $total_trophies; echo 'of'; echo $row[trophy_count]; ?> But the problem is sometimes in my database I could have mulitple entrys per trophy. For Trophy 1 I might have only one record so It counts it correctly for trophy 2 I could have 3 records so It counts each one of those records when I only one to count it once for that trophy Hi all, I am trying to use the Mysql COUNT function to count the number of records in a database where the manufacturer is the same and then generate a list of all manufacturers along with a number of associated records next to their name. I have got the script below to show the manufacturer in a fetch array but I can not get the number next to the manufacturer to work. A push in the right direction would be appreciated thanks. <?php include("cxn.php"); $query = "SELECT manufacturer FROM sales"; $result = mysqli_query($cxn,$query) or die(mysqli_error()); ?> <select name="manufacturer" id="manufacturer"> <option value="" selected="selected">Select a Manufacturer..</option>"; <?php while($row = mysqli_fetch_array($result)){ $query1 = "SELECT manufacturer COUNT(*) FROM sales WHERE manufacturer='$row[manufacturer]'"; // TRYING TO COUNT THE ROWS HERE $result1 = mysqli_query($cxn,$query1) or die (mysqli_error()); while($row1 = mysqli_fetch_array($result1)){ echo "<option value=\"202\">".$row['manufacturer'] ."[". $row1['COUNT(manufacturer)']."]</option>"; // SHOW NUMBER HERE } } ?> I've been trying to come up with a way to accurately count a word string which includes punctuation marks. I've got close but the white-space is causing a problem. I have used a couple of functions such as str_replace and explode and I can now get an accurate count for texts with most punctuation and 'normal' white space. BUT.. If I put in three extra spaces between words the count adds 1 to the total. $words2 = str_replace("-", "", $string); // strips a hypen $words3 = str_replace(' ', ' ', $words2); // strips double spaces $words = explode(' ', $words3); This is obviously NOT a script - rather a string of text being passed through three functions to cleanse it. But as you can see it will strip two white spaces when they occur but no more. So three, four, five etc. will be counted as extra words. What else could I try to give me an accurate count? I am very raw at php. thanks Richard I am writing a function to count the words that have been typed into a text box. I originally had it working when I first wrote it but it was counting all of the punctuation as a word so I I tried adding some code to eliminate that. Now it is not working. Could someone help me? Here is my code Code: [Select] function count_words($description){ $word_count = 0; $description = trim(preg_replace("/\s+/"," ",$description)); $word_array = explode(" ", $description); for($i=0; $i < count($word_array); $i++){ if (preg_match("[0-9A-Za-z]", $word_array[$i])) { $word_count++; } return $word_count; } } I'm using the code below to on echo certain words based on their index/key value, this works fine however, im trying to only do this in exploded quotes... the problem is, exploding quotes turns the portion into an array which cant be passed to str_word_count... how can i do the same thing only inside quotes. So that hello world "this is a test" would become: Code: [Select] Hello World This [0] => Is [1] => a [2] => Test [3] Im trying to always remove say the 4th word in quotations, or maybe the 3rd and 4th, whatever i want to omit i leave out from the echo, so echo $data[0].' '.$data[3].'; would output "This Test" omitting "Is A" Code: [Select] $data = 'hello world "this is a test"'; $data = str_word_count($data, 1); echo $data[1].' '.$data[2].' '.$data[0]; I am having trouble showing reports for a given date range. Currently if I specify something like 11/03/2010 to 11/05/2010 I get results for all years within that month and day such as I may get results for 11/03/2008 11/03/2009 11/03/2010 11/04/2008 11/04/2009 11/04/2010 11/05/2008 11/05/2009 11/05/2010. I am using the following code $result = mysql_query("SELECT * FROM report WHERE date>='$date_begin' and date<='$date_end' ORDER BY 'date'",$db); I use the following format in my date feild mm/dd/yyyy Hi guys, I need your help. I am trying to insert the rows in the mysql database as I input the values in the url bar which it would be like this: Code: [Select] www.mysite.com/testupdate.php?user=tester&pass=test&user1=tester&email=me@shitmail.com&ip=myisp However i have got a error which i don't know how to fix it. Error: Column count doesn't match value count at row 1 <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbusername'); define('DB_PASSWORD', 'mydbpassword'); define('DB_DATABASE', 'mydbname'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $adduser = clean($_GET['user1']); $email = clean($_GET['email']); $IP = clean($_GET['ip']); if($username == '') { $errmsg_arr[] = 'username is missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD is missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $sql = "INSERT INTO `members` (`username`,`email`,`IP`) VALUES ('$adduser','$email','$IP')"; if (!mysql_query($sql,$link)) { die('Error: ' . mysql_error()); } echo "The information have been updated."; } ?> Here's the name of the columns i have got in my database: Code: [Select] username IP I have input the correct columns names, so I can't correct the problem I am getting. Please can you help? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331562.0 Why am I getting this error when there are 3 Fields with 3 values? Column count doesn't match value count at row 1 Code: [Select] $sql5="INSERT INTO participants (participant_name, team_no, sport) VALUES ('".implode("','$_POST[team]'),('",$_POST['participant_name'])."','$_POST[team]','$sport')"; Anyone can help me? <?php $tbl_name="menu"; $kategorije = mysql_query("SELECT * FROM $tbl_name WHERE Left(menu_name, 1) BETWEEN 'A' AND 'M' ORDER BY menu_name ASC"); if (!$kategorije) { die("Database query failed: " . mysql_error()); } while ($row=mysql_fetch_array( $kategorije )) { echo "<div id=lista-header><h4>{$row["menu_name"]}</h4></div>"; $id_sub=$row['id_menu']; $podkategorije = mysql_query("SELECT * FROM submenu WHERE id_menu=$id_sub ORDER BY sub_name ASC", $connection); if (!$podkategorije) { die("Database query failed: " . mysql_error()); } echo "<ul class=\"pod\">"; while ($pod=mysql_fetch_array( $podkategorije )) { echo "<li><a href=index.php?=podkate?".$pod["id_sub"]." class=black>{$pod["sub_name"]}</a><hr size=1 align=left width=100px color=#cccccc></li>"; } echo "</ul>"; } ?> In this way, I get list with categories and hes subcategories. How to count how many subcategories have each categories, and count how many articles have each categories? Example (I wanna get this kind of look): Categories name (3) subcategoriesname (2) subcategoriesname (4) subcategoriesname (7) Categories name (5) subcategoriesname (1) subcategoriesname (14) subcategoriesname (9) subcategoriesname (2) subcategoriesname ( Categories name (2) subcategoriesname (28) subcategoriesname (17) Where the numbers represent how many categories and sub-items have articles im trying to run a query which will get posts from the database that have tags similar to the current ones. Unfortunatly the echoed result isnt displaying as it should. $query = $link->query("SELECT t.*, p.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) WHERE t.t_name = '".decode_url($_GET['t_name'])."' LIMIT 1") or die(print_link_error()); $row = $query->fetch(PDO::FETCH_ASSOC); $tag_query = $link->query("SELECT p_name FROM ".TBL_PREFIX."posts WHERE MATCH (p_tags) AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE) ")or die(print_link_error()); $result = $tag_query->fetch(); foreach($result as $key => $value) { echo 'Name = '.$result[$key]['p_name'].'<br />'; } i have done a dump of result and it shows: Code: [Select] $ => Array (2) ( ['p_name'] = String(12) "File Updates" ['0'] = String(12) "File Updates" ) but there should only be one item in this array(p_name). I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right. hi My first language is not english so i hope you bear it i am new to php am am making my shopping Cart as my web engineering course i have made everything i all want to know how to i show similar products when a user click on any product details it open new page and shows a detail of that page i want to show similar products list below to details so can any tell me how to do it plzz kindly see the pic in atttachment i have posted snap shop of my page i put similar product statically i want to show it dynamically from tha data base kindly answer please regards I'm pretty sure there isn't, but I was wondering if there was a php function that would return partial matches similar to MySQL's LIKE, I've been searching for a while and haven't found one. If not, is there a class or something that someone knows of that will accomplish a like of search or a string comparison? I want to be able to compare two variables and return one of three results - Exact Match, Partial Match, No Match. I suppose regex may do the trick but I'm a complete novice when it comes to regex and I have no idea where to even begin. Thanks for any suggestions. How can I check if an array contains two items that are the same? For example ("apples", "bananas", "oranges") returns false But ("apples", "bananas", "bananas") returns true Hello, I am looking for a push in the right direction. I would like to be able to view a website that is duplicated on many servers by specifying the IP address. Similar to how one would use the hosts file. I can do this using netcat nc 1.2.3.4 80 Host: example.com GET /contact-us.html <CR><CR> Can someone tell me how I would go about porting this to PHP? I would just like to set up a small page on my webserver where I can enter the domain and IP address and have the page displayed back to me. Thanks Colin This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=350182.0 |