PHP - Coding Help To Match And Count Array Results
I can't get the COUNT of the matching results? Please help.
$SomeVar = myname; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); while($scoreP = mysql_fetch_array($resultU)) { $scoreP['roundzAa']; $scoreP['roundzAb']; $scoreP['roundzAc']; $scoreP['roundzAd']; $scoreP['roundzAe']; $scoreP['roundzAf']; $scoreP['roundzAg']; $scoreP['roundzAh']; } $WinV = 'resultA'; $query = "SELECT * FROM acs WHERE resultx = '".$WinV."'"; $result = mysql_query($query); while($scoreUsr = mysql_fetch_array($result)) { $scoreUsr = $scoreM1['winxa']; $scoreUsr = $scoreM1['winxb']; $scoreUsr = $scoreM1['winxc']; $scoreUsr = $scoreM1['winxd']; $scoreUsr = $scoreM1['winxe']; $scoreUsr = $scoreM1['winxf']; $scoreUsr = $scoreM1['winxg']; $scoreUsr = $scoreM1['winxh']; } $count1 = count( array_intersect($resultU, $result) ); echo($count1); mysql_query("UPDATE comp SET id=$count1 WHERE username = '".$SomeVar."'"); ?> Similar TutorialsHi 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')"; How to write this in a shorter way? I've got a set of results and I need to check them against another database results. If they both are similar then I want to make it as "1" (points). The questions and the answers are in the same order (Question1, Question2, Question3 = Answer1, Answer2, Answer3). sa I guess the maching could be done using a set of arrays. E.g. get records from db1 get records from db2 get records from dbY get records from dbX COUNT the matching data from db1 against dbY = echo TOTAL_SCORE1 COUNT the matching data from db2 against dbX = echo TOTAL_SCORE2 I've managed to get the data from the databases in order. But i need to get the COUNT of the MATCHING records. php \\Assume this is db1 $SomeVar = $_POST['sitting2']; $queryU = "SELECT * FROM adxone WHERE username = '".$SomeVar."'"; $resultU = mysql_query($queryU); $scoreU = mysql_fetch_assoc($resultU); $userRa1 = $scoreU['roundzAa']; $userRa2 = $scoreU['roundzAb']; $userRa3 = $scoreU['roundzAc']; $userRa4 = $scoreU['roundzAd']; $userRa5 = $scoreU['roundzAe']; $userRa6 = $scoreU['roundzAf']; $userRa7 = $scoreU['roundzAg']; $userRa8 = $scoreU['roundzAh']; \\ Assume this is dbY $WinVar = 'examinationA'; $query = "SELECT * FROM markacs WHERE roundx = '".$WinVar."'"; $result = mysql_query($query); $scoreM = mysql_fetch_assoc($result); $winRa1 = $scoreM['markwinxa']; $winRa2 = $scoreM['markwinxb']; $winRa3 = $scoreM['markwinxc']; $winRa4 = $scoreM['markwinxd']; $winRa5 = $scoreM['markwinxe']; $winRa6 = $scoreM['markwinxf']; $winRa7 = $scoreM['markwinxg']; $winRa8 = $scoreM['markwinxh']; /*need to match if $winRa1 = $userRa1, $winRa2 = $userRa2, etc.. then get the COUNT of the matching results*/ How to check if a result of a database match with a result of another database. How do this? E.g. In DatabaseA holds a column called usernames. In DatabaseB holds a column called banned. Is it possible to match results of an Array with an Arrary of results of another database and COUNT the matching results? E.g. In DatabaseA holds 4 columns and the records are pulled in as an array. Science Geography Accounting Agriculture In DatabaseB holds 4 columns and the records are pulled in as an array. Geography French Accounting Science THE RESULT should echo = 1 How to get the count if any of this ($ArrayDrRes) contain the word "APPROVED"? $Array1 = array($user1, $user2, $user3, $user4, $user5, $user6, $user7, $user8); $Array2 = array('APPROVED'); $count3 = count( array_intersect($Array1, $Array2) ); echo $count3; I'm getting the number of friends in each STATE. How do I split the results in $returnS? $query = "SELECT statez, COUNT(statez)FROM abs GROUP BY statez"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line['COUNT(statez)'].",,".$line['statez'].",,,"; } echo $returnS; mysql_close($link); ?> in my mysql query, after the results have been grouped is there any way to count the results? i have a end result like this: 784 | x.x.x.x 754 | x.x.x.x 784 | x.x.x.x so how can i count the first column after its been grouped by IPs? here is my query: SELECT * FROM `hits`GROUP BY ip First up quick thanks in advance, any and all help is greatfully recieved
I have this query:
SELECT Player.MembershipNo , Player.FirstName , Player.LastName , Venue.VenueName as Venue, Results.MemCard, Results.EarlyReg , Position.Points as Venue_Points, Results.Date FROM Position , Player , Results , Venue WHERE Player.MembershipNo =Results.MembershipNo AND Results.Position =Position.Position AND Venue.VenueID =Results.VenueID AND Results.Date BETWEEN '2014-07-01' AND '2014-09-30' ORDER BY MembershipNo, Venuewhich returns these results: +--------------+-----------+----------+-------------------+---------+----------+--------------+------------+ | MembershipNo | FirstName | LastName | Venue | MemCard | EarlyReg | Venue_Points | Date | +--------------+-----------+----------+-------------------+---------+----------+--------------+------------+ | 0 | Bob | Stevens | The Dolphin | 1 | 1 | 32 | 27/08/2014 | | 0 | Bob | Stevens | The Enigma Tavern | 1 | 1 | 40 | 08/07/2014 | | 0 | Bob | Stevens | The Enigma Tavern | 1 | 1 | 16 | 15/07/2014 | | 1 | Dave | Green | The Dolphin | 1 | 1 | 20 | 13/08/2014 | | 1 | Dave | Green | The Dolphin | 1 | 1 | 2 | 20/08/2014 | +--------------+-----------+----------+-------------------+---------+----------+--------------+------------+ I'm trying to make a function which will display the top X results of the row Y which I set, for this instance I'm using the row browser and the top 5 results from my table statistics, the where is just to eliminate Search Bot results from showing up. I also want it to return the count of the amount of rows as well. So say there was 10 results for the browser 'Safari', then it would return the count of 10 for that result as well as the result itself. Code: [Select] $display->show_list('statistics', 'browser', '5', 'WHERE browser!=\'Search Bot\''); Here is my function. I'm cleaned it up a bit to remove certain checks and outputs if the query were to fail, etc. Code: [Select] function show_list($table, $row, $limit = 5, $where = NULL) { $item = mysql_query("SELECT DISTINCT $row FROM $table $where LIMIT $limit"); $result = array(); while ($fetch = mysql_fetch_array($item)) { $result[] = $fetch; } return $result; } Basically, how would I go about making it count the amount of rows for the row I've set, and then to output that along side the result? Hello all, I've built a database of coupons. Each coupon is assigned to a category (so all electronics coupons display under electronics). On my category list I'd like to display how many coupons is in each category. Currently this function displays my category list: function fetch_categories() { mysql_connect(SQL_HOST_NAME, SQL_USER_NAME, SQL_PASSWORD) or die(mysql_error()); mysql_select_db(SQL_DATABASE) or die(mysql_error()); $result = mysql_query("SELECT * FROM categories ORDER BY category_name")or die(mysql_error()); echo '<div id="category_list">'; echo '<ul class="cat_list">'; while($row=mysql_fetch_assoc($result)){ //get total of discounts in each category $count_result = mysql_query("SELECT * FROM category_relations, discounts WHERE category_relations.member_of = '$row[id]' AND discounts.active = '1'")or die(mysql_error()); $num_rows = mysql_num_rows($count_result); echo '<span class="numrows">('.$num_rows.')</span>'; echo '<li><a href="index.php?cat_ID='.$row['id'].'">'.$row['category_name'].' </a></li>'; } echo '</ul>'; echo '</div>'; } The above is a debug version so it's not all formatted correctly. However right now, that exports "3" for Airlines when right now, I have only one discount in the entire database. This is my category_relations table: Code: [Select] -- -- Table structure for table `category_relations` -- CREATE TABLE IF NOT EXISTS `category_relations` ( `id` int(10) NOT NULL, `member_of` int(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Dumping data for table `category_relations` -- INSERT INTO `category_relations` (`id`, `member_of`) VALUES (2, 2), (1, 1), (3, 1), (4, 1); And this is my discounts table: Code: [Select] -- -- Table structure for table `discounts` -- CREATE TABLE IF NOT EXISTS `discounts` ( `id` smallint(5) NOT NULL AUTO_INCREMENT, `redeem` tinyint(3) NOT NULL, `discount_title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `short_description` tinytext CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `eligibility` blob NOT NULL, `url` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `coupon_code` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `start_date` datetime DEFAULT NULL, `end_date` datetime DEFAULT NULL, `long_description` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `logo` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `business_name` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `phone` varchar(80) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_street` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_city` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_state` char(2) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `store_location_zip` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `categories` blob NOT NULL, `level` tinyint(5) NOT NULL, `active` tinyint(1) NOT NULL, `user_id` varchar(2555) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `level` (`level`,`active`), KEY `user_id` (`user_id`(333)) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ; -- -- Dumping data for table `discounts` -- INSERT INTO `discounts` (`id`, `redeem`, `discount_title`, `short_description`, `eligibility`, `url`, `coupon_code`, `start_date`, `end_date`, `long_description`, `logo`, `business_name`, `phone`, `store_location_street`, `store_location_city`, `store_location_state`, `store_location_zip`, `categories`, `level`, `active`, `user_id`) VALUES (1, 0, '$2.00 Off Transportation', '', 0x4172726179, 'www.baysideshuttle.com', '', '2010-01-01 00:00:00', '2011-01-01 00:00:00', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer varius ipsum id justo pellentesque laoreet. Curabitur tempus tincidunt...', NULL, 'Bayside Airport Shuttle', '850-123-3456', NULL, NULL, NULL, NULL, 0x4172726179, 0, 1, '24'); It seems to be completely ignoring my active check. How can I fix this, or is there a better way to do this query? hello, I have a search that matches users ISBN with two databases....code is below $query_search_exact_match = mysql_query("SELECT nvc_site.title, nvc_site.id, nvc_site.description, nvc_site.search_text, nvc_site.image, nvc_site.date, nvc_site.price, nvc_site.location_city, nvc_site_ads_extra.name, nvc_site_ads_extra.value, nvc_site_ads_extra.classified_id FROM nvc_site,nvc_site_ads_extra WHERE name = 'ISBN%3A' AND live=1") or die(mysql_error()); then i take the ISBN that the user entered and match that with the isbn's in the DB while ($fetch_extra = mysql_fetch_array($query_search_exact_match)) { $value = ereg_replace( "[^0-9]", "", $fetch_extra['value'] ); $to_find_isbn = mysql_real_escape_string(ereg_replace( "[^0-9]", "",$_POST['szs'])); if($value == $to_find_isbn) { echo "Match Found"; } else { echo "No Match Found"; } //ELSE doesn't work here.....it displays both the if and else at the same time } i need it to display no match found if there was no match found.....I am soo lost right now!! please help thank you Code: [Select] array ( 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '1', ), 1 => array ( 'c0' => '6/114', 'c1' => '6/111', 'cnt' => '1', ), 2 => array ( 'c0' => '6/145', 'c1' => '6/116', 'cnt' => '1', ), ) I want to "match" as on example code 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '1', ), 1 => array ( 'c0' => '6/114', 'c1' => '6/111', 'cnt' => '1', ), c0 & c1, to get (and the array to be reseted) 0 => array ( 'c0' => '6/111', 'c1' => '6/114', 'cnt' => '2', ), 1 => array ( 'c0' => '6/145', 'c1' => '6/116', 'cnt' => '1', ), ) how to do it? I think that on only SQL it's impossible to do that ("switch"), furthermore I think that the code above would be useful /* $_c1 = @array_merge($_c1,$_c1x); if(!empty($_c0)) { foreach($_c1 as $value) { if(!isset($c1x[$value['id']])) { $c1x[$value['id']] = $value; $c1x[$value['id']]['cnt'] = 0; } $c1x[$value['id']]['cnt']++; } $this->tpl->assign('c1x',$c1x); } */ please help mi, thank you very much Dead simple, I know it is but I'm still a little newbie. I have this chat box, and I don't want people to be able to swear in it so I need help making a function where you call the string as an argument and it returns true if the string has any words from an array in it, Even if the word is walking and not just walk. If it's true I can replace the entire string with something else. Can someone tell me what functions I need? I prefer you didn't do it all for me I need to learn Thanks in advance! I have a array of file path strings and trying to search the array for a string that would be the end of the path sting and return the index of the file path that contains the string. I've tried using something like this, but it finds the keyword in anyplace in the file path. I've also tried strripos() as well with the same results. Any suggestions? function array_search_partial($arr, $keyword) { foreach ($arr as $index => $string) { if(strpos($string, $keyword) !== FALSE) { return $index; } } }
Hello, I have several job categories on a recruitment website: $job_category[0]="accountant"; $job_category[1]="php programming"; $job_category[2]="baseball"; these job categories are contained within the urls imediately after the recruiting company's name and before the word "jobs", so we could have the following urls: www.url.com/company_name_accountant_jobs www.url.com/another_company_name_baseball_jobs www.url.com/yet_another_company_name_php programming_jobs Using the array $job_categories and the page path after the foward slash (e.g. yet_another_company_name_php programming_jobs) please could you tell me how to strip out the job category and the company name? (I'll extract the page path using a mod_rewrite) Thanks Stu example structure of text database- mytextfile.txt 10-11201|2010/09/01|Sam|Thurston 10-11307|2010/09/04|Tony|Piper 10-11405|2010/09/11|Sarah|Smith <?php $file2 = 'mytextfile.txt'; $openedfile =fopen($file2, "r") or die("ERROR- could not open file for editing."); // flock($openedfile, LOCK_EX) or die("Error!- Could not obtain exclusive lock on the file to edit."); $hold[$record_count] = explode("|", trim(fgets($openedfile))); while(!feof($openedfile)) { $record_count++; $hold[$record_count] = explode("|", trim(fgets($openedfile))); } ?> What I need to do is loop through this and one by one- take any arrays that contain a date that is between $dateX and $dateY (which comes via a form input) and place it in a new array $matched. I am stumped. 1-Is there a way to do it inside the above while loop that I am not seeing? 2- Do I need to open the file in another manner? 2- Would it be best to now loop through $hold[$record_count] I am trying to keep the process short so as not to use up too much memory. Point me in the right direction for this one please. |