PHP - Need A Count Of Comma Seperated Numbers - Simple (i Think)
I have a field in my MySQL DB that holds numbers separated by a comma (example: 1, 3, 45, 137, 87). I simply want to get a count of how many numbers are in there. (Using my example the result would be 5). I'm sure this is a simple question but I don't know how. I'm able to extract the numbers but I can't get the count to read anything other than 1. Can anyone help?
Similar TutorialsI need to some how pull comma separated images $data[23] from this $data array and then put them into there own array so I can insert them into separate rows in a database. This is the provided array: $data[0] => VIN $data[1] => StockNumber ...(all the other number here) $data[23] => Image_URLs (comma seperated) $data[24] => Equipment // I need something like this (obviously doesn't work?!@#) $delimiter = ","; $img = explode($delimiter, $data[23]); foreach($img as $pic){ $sqlPic = "insert into class_prodimages (pid image rank) values('".$LastId['id']."', '$pic', '".rand(1,20)."')"; } Any help here? Hi Guys,
How do i put a comma separator after a thousand ? Example if $grand28 was equal to 1234.00 how do i get it to read 1,234.00
here is my code " . sprintf("%.2f", $grand28) . "
Hey, guys!
Why the output of my code in both "echo" is only the number "2"?
<?php $x = 4; $y = 2; //Addition. echo "Addtion: " . $x + $y . "<br>"; echo 'Addtion: ' . $x + $y . '<br>'; ?>Thanks! SELECT COUNT(*) obviously counts all records matching the WHERE clause, however... Field1 / Field2 1 / A / A 1 / B 1 / A I want to count all records where Field2 is "A", but if Field1 is set to "1" then that record counts as half. So above would return a result of 2 (one and two halfs = 2) I'm sure SQL can do this without the need to perfrom PHP calculations. Hope this makes sense. Thanks in advance. Looke on the PHP manual for the "count" function and it has confused me. it seems to count arrays more than anything. i have a small site and i wanted to display how many items are contained within a Database table. for example i want it to count the amount of users are in the user table. and i then need to echo that amount + 100. Can someone help me with the code. i have already included a database connect script within the header of the page with includes etc. Help would be appreciated. but i would like to know how the code works else i will never learn. I'm trying to work out a count of how many of what assets are in a certain location: there should be 13 different categories (asset types) in a location and i want the individual count of each category. here's what i have - which seems to give me a total count of all assets and locations together plus one asset description and one location..... almost right. Code: [Select] $con = mysql_connect('localhost','root',''); if(! $con) die(mysql_error()); mysql_select_db("test",$con); $result = mysql_query("SELECT DISTINCT COUNT(`Asset Description`) AS TOTALAD, LOCATION, `Asset Description` AS AD FROM master WHERE LOCATION like 'NC%'"); while($row = mysql_fetch_array($result)) { echo $row["LOCATION"]; echo "<br />"; echo $row["TOTALAD"]; echo "<br />"; echo $row["AD"]; echo "<br />"; } mysql_close($con); I am having trouble parsing data that is separated by comas in an XLS file. The upload and parsing scripts work beautifully, but the problem I am having is the data is read in from one cell (all 5 fields for the row are in column A) I am exploding it by , but some of the cells contain comas. For example a cell might contain "jim,jones,12345678,jim@jones.com,More, Data,192.168.1.1" but the next one might be "Dave,Thomas,98765432,dave@wendys.com,something else, 255.255.255.0" The problem I am having is More, Data should be one cell. Not all position 4 will have a , so I can't just add it back because the IP address would be appended to more... Any ideas? I hope thats clear enough... Hi, I am trying to find a way that will allow me to convert information passed via POST into array so I can run foreach on the array. For example if information in $_POST[ids] is 1000, 1001, 1002, 1003 I would like to get it into an array $array = array("1000", "1001", "1002", "1003") 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 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330192.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')"; Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim 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 Hey, i got this code which takes info from mysql: while ($row= mysql_fetch_array($result)) { $title = $row["alertid"]; $title2 = $row["alerttext"]; $title3 = $row["alertdate"]; $bla = "{\"alertid\":\"$title\",\"alerttext\":\"$title2\",\"alertdate\":\"$title3\"},"; echo "$bla"; } it is displayed like this: [{"alertid":"1","alerttext":"text1","alertdate":"date1"},{"alertid":"2","alerttext":"text2","alertdate":"date2"},{"alertid":"3","alerttext":"text3","alertdate":"date3"},] I wanted to ask, how can I remove the last comma, after date3"}, but keep other commas..? Hi, If I need to put commas within a variable how can this be achieved? i.e. if statement..... { $output = "text1,text2,text3"; Incase your wondering what I'm trying to do.. basically im using a header file on my site... i want different keywords within the meta tags depending on the page the user is on, so i want to include aprox 20 keywords in the $output which will be inserted in the comma area of the meta tags. Probably quite an easy way to do it but I'm not sure how to do it! Any help appreciated! Hello Guys, I am trying to strip the last comma but I can't get it to work... Please advise Here is my code, it adds the coma in between all numbers and on the end. Code: [Select] $query1 = mysql_query("SELECT b_id FROM benefits"); while ($row = mysql_fetch_array($query1)) { $b_id = $row['b_id']; $b_id . ","; echo $b_id2; } displays 1,2,3,4,5,6,7,8,9,10, I also tried this but it didn't work. It removed all the commas Code: [Select] $query1 = mysql_query("SELECT b_id FROM benefits"); while ($row = mysql_fetch_array($query1)) { $b_id = $row['b_id']; $b_id . ","; $b_id2 = rtrim($b_id,','); echo $b_id2; } This seems like such a simple error, however I've no idea why I am getting it. apparently I have an unexpected comma on line 4 of the code below. I can't work out what the error is. Any ideas? Sorry to be a pain if it really is something simple, but I'm a bit new to all this php stuff. <?php function percentCalc($value1,$value2,$value3,$value4,$value5,$total) { $array=($value1,$value2,$value3,$value4,$value5); while (list($key,$arraycontent)= each($array)) { $c_percent=(($arraycontent/$total)*100); $final_array[]=$c_percent; } return $final_array; } ?> Lets say I pull a value from a database field that has a value of 1,2 and what I want to do is seperate them and then run each of those values against a separate table how would that be accomplished. |