PHP - Count The Number Of Multiple Showing Variable In A Column
Hi everyone,
Like the title says I need to count the amount of 1's in a column but I can't figure out how. Gr and thanx already Ryflex Similar TutorialsI'm not sure how to approach this but here is my problem. I'm using a sql statement that counts the number of users in the database. I've created a session variable named $MerchantCount and then I need to multiple that number by this scheme 0-9 Needs to multiple by 2.5 10-19 Needs to multiple by 5.0 20 and up needs to multiple by 7.5 How would I do this? Thanks... 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')"; How to count the number of files/images from a folder? 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, I want to count the total number of multiple select that user has selected instead of getting the value the user has selected How should I go about doing the counting part? Code: [Select] <form action="1.php" method="post"> <select name="test[]" multiple="multiple"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> <option value="four">four</option> <option value="five">five</option> </select> <input type="submit" value="Send" /> </form> <?php $test=$_POST['test']; if ($test){ foreach ($test as $t){echo 'You selected ',$t,'<br />';} } ?> How do you count the number of folders in a directory? I got to thinking late last night (which generally leads to trouble), so please be gentle if some educating is in order, as I suppose I will touch a few related issues. As I develop my database, I will include two seperate columns. One for the time/date that an order was placed. A second for the time/date that an order is updated (unless there's a better way, please inform me). I pressume that if a record is updated several times, it will continually overwrite the time/date to the point that I will only see the latest update. Now I was wondering if I could create a third column to keep count of the number of times a record had been updated, so if it were altered 16 times, I would know when the last update occurred, and have the count number also. Will something like this coding work? SELECT updates FROM myTable WHERE id="$id" $updates =n if n<1, n=1 }else{ n++ 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 } } ?> Hi. I have the following code where I grab the names and average overall rating from my database and group by the name. Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ Does anybody know how I can count the number of names that have been grouped together? For instance: Name Overal ratingl John 2 Pete 5 John 8 It should group the john's, calculate the average rating (8+2)/2=5, and then show that there have been 2 johns making up the 5 rating? I've tried using the code below and messed around with it loads but cant get it to work: Code: [Select] $sql="SELECT name, AVG(overall) AS overall FROM $tbl_name COUNT name GROUP BY name ORDER BY AVG(overall) DESC"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ echo $rows['Count name']; Thanks in advance. Hi Everyone, I am working on implementing a blog comment system using the query below to display comments. My question is what is the best way to do a row count for the id column with this query or do I need to do a second db query to accomplish this? The purpose of this is to echo out the number of comments for that post, before displaying them. Any help is appreciated. Thanks in advance, kaiman <?php // get url variables $post_id = mysql_real_escape_string($_GET['id']); include ("../../scripts/includes/nl2p.inc.php"); // connects to server and selects database include ("../../scripts/includes/dbconnect.inc.php"); // table name $tbl_name3="blog_comments"; // select info from comments database $result3 = mysql_query ("SELECT count(*) FROM $table_name3 WHERE id='$post_id' ORDER BY id DESC LIMIT 1") or trigger_error("A mysql error has occurred!"); if (mysql_num_rows($result3) > 0 ) { while($row = mysql_fetch_array($result3)) { extract($row); // display number of comments // display date $row_date = strtotime($row['date']); putenv("TZ=America/Denver"); echo "<p class=\post\">On ".date('F, jS, Y', $row_date)." "; // display commenter name if($row['url'] == "") { echo $row['name']." wrote:</p>\n"; } else { echo "<a href=\"".$row['url']."\" target=\"_blank\">".$row['name']."</a> wrote:</p>\n"; } // display content $comments = $row['comment']; echo nl2p($comments); } } else { echo "<p class=\"large_spacer\">No Comments</p>"; } ?> i HAVE FOLLOWING VALUES IN FEED TABLE
a1a a1b a1c a1d ......
7 8 7 7
8 9 8 8
9 7 7 8
7 8 10 9
6 4 6 7
7 8 8 5
9 7 7 6
This in an array ( select a1a,a1b,a1c,a1d from feed where .....)
1) I want to know how many times each values has occured in the array ( eg: 7 occured 10 times, 8 occured 8 times)
2) How many 7's, 8's, 9's are there in a1a, howmany .....in a1b
Number of times each values occured OVERALL in array as well as also under each head
Please help
I have a database lets say punch_log The data in the table looks like: --------------------------------------------------------------------------- |punch_log_id | user_id | punch_id | punch_time | --------------------------------------------------------------------------- | 10010 | 21 | 1 | 2010-11-10 15:04:59| | 10011 | 21 | 2 | 2010-11-10 15:50:05| | 10010 | 21 | 1 | 2010-11-11 15:04:59| | 10011 | 21 | 2 | 2010-11-11 15:50:05| | 10010 | 21 | 1 | 2010-11-12 15:04:59| | 10011 | 21 | 2 | 2010-11-12 15:50:05| | 10010 | 21 | 1 | 2010-11-13 15:04:59| | 10011 | 21 | 2 | 2010-11-13 15:50:05| | 10010 | 21 | 1 | 2010-11-14 15:04:59| | 10011 | 21 | 2 | 2010-11-14 15:50:05| | 10010 | 21 | 1 | 2010-11-14 15:50:59| <-- this is why i need this. | 10011 | 21 | 2 | 2010-11-14 15:55:05| <-- this is why i need this. ---------------------------------------------------------------------------- Im currently using : $kust = $_POST['AKuu']; $kuni3 = $_POST['LKuu']; $valitudtootaja = $_POST['TNimi']; mysql_select_db($database, $con); $query2 = "SELECT *, SUM(punch_id) FROM punch_log WHERE user_id = '".$valitudtootaja."' AND punch_time BETWEEN '$kust' AND '$kuni3' AND punch_id ='1' "; $result2 = mysql_query($query2) or die(mysql_error()); while($row = mysql_fetch_array($result2)){ $X = $row['SUM(punch_id)']; When using the current query im getting Workers days at work = 6 it should be 5 but thats why i need some solution to group dates and then sum them. Does anybody have any ideas? Hi guys I'm kinda stuck..so hopefully you guys can lend me a hand I've got an array containing date elements ("Y-m-d")... I'm trying to output some data into googlecharts..so i need to count how many elements that are in the array with todays date -1 day, todays date-2 days...todays date -3days etc... Up until a set number of days (for example 7 days, 14 days etc).. Any advice on how to go about to achieve this? Hello, I am trying to create article directory for learning PHP MySql and i want to write a script for recording number of views for an article and store it in Database. Can anyone please direct me to a nice simple tutorial or help me with the steps or algorithm? Suppose the link for an article is http://www.domain.com/article.php?id=123 Do i need to put extra variables and create a tracking PHP file for it? I have a html table displaying data from mysql database. I can count rows properly with mysql_num_rows but is there a way to echo which row number it is. What I want to do is count the rows ordered by cities and echo row number. Thanks for any help. Folks, Having trouble here. Forgot how you use the COUNT. Not interested in the num_rows due to it being slow compared to COUNT. I have users table like this: id|username|sponsor_username 0|barand|requinix 1|phpsane|alison 2|mickey_mouse|requinix Now, I want to check if a sponsor username exists or not. Such as does the entry "requinix" exists or not in one of the rows in the "sponsor_username" column. In our example it does twice and so the variable $sponsor_username_count should hold the value "2". Else hold "0". I get error: Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
My code:
$stmt_1 = mysqli_prepare($conn,"SELECT COUNT(sponsor_username) from users = ?"); mysqli_stmt_bind_param($stmt_1,'s',$sponsor_username_count); mysqli_stmt_execute($stmt_1); //Show error if 'users' tbl was not successfully queried". if (!$stmt_1) { echo "ERROR 1: Sorry! Our system is currently experiencing a problem loading this page!"; exit(); } else { mysqli_stmt_bind_result($stmt_1,$sponsor_username_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Check if Sponsor Username in Url ($_GET) is already registered or not. If not then show "Invalid Url" or Link message. if ($sponsor_username_count < 1) { echo "<b>Invalid Url or Link!<br> Invalid Sponsor: \"$sponsor_username\"!</b><?php "; exit(); } }
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320119.0 |