PHP - Count Function
This is a dummy question but i cant get multiple criteria in the count function.
This is what i'm trying to do:
SELECT COUNT(Name, Expansion, Foil) AS NameCheck FROM Osiris WHERE Name="$name" Expansion="$expansion" Foil="$foil"I have Colums named: `Name` `Color` `Type` `Subtype` `Power` `Toughness` `Manacost` `Rarity` `Expansion` `Foil` `Stock`I want to check before i enter a new record if its not already there, by checking the Name, Expansion and Foil colum on the same record. I think i have just messed up that code line but i cant seem to find any solution on the web. Thanks in advance! Similar TutorialsI have no idea why but no matter what the eventid is, the label always returns 20 and I"m not sure why. Is my synatx wrong? $eventid = (int)$_GET['eventid']; $result = mysqli_query($dbc, "SELECT count(label) FROM `events` WHERE `event_id` = '$eventid'"); $label = $result + 1; echo $label; Hi, I want the user to be able to go to one page and hit a button, once he hits the butten I want a count down to start from 10 minutes. When the user goes to the page within those 10 minutes, I want it to show him a live countdown until those ten minutes run out. Any ideas how I would go about doing this? 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; } } Code: [Select] function width2($noid) { $getwidth = mysql_query("SELECT * FROM block WHERE sid='$theid'",$this->connect); while($row1 = mysql_fetch_assoc($getwidth)) { $this->width2($noid); } } how do i count how many times the function loops? How can I modify the following code to not display $hash_row['total'], but to display the sum of the counted "total" value + 1? Is there a way that I can assign that variable in the "select query" area (for instance, "COUNT(hr.hasher_id) + 1 as total1"), and then call $hash_row['total1] in the result table? I'm not sure if the syntax exists to add an integer value to a COUNT value and assign to a new variable... Code: [Select] <?php include "modules/dbase_connection.php"; #create MySQL connection $sql_connection = sql_connect("blah","blah","blah","blah"); # select the Hashers and hashes by total number<br /> $hash_query = " SELECT ha.*, COUNT(hr.hasher_id) as total FROM hashers as ha, hash_records as hr WHERE hr.hasher_id = ha.hasher_id GROUP BY hr.hasher_id ORDER BY total DESC "; $hash_result = mysql_query($hash_query) or die(mysql_error()); $x = 1; while($hash_row = mysql_fetch_array($hash_result)) { #display the table header if($x == 1) { echo ' <br /> <table align="left"> <br /> <tbody> <tr><br /><td colspan="2"><strong>Potential On-Sec</strong></td><br /></tr>'; $x++; } echo '<tr><br /><td>' . $hash_row['hasher_name'] . '</td><br /><td>' . $hash_row['total'] . '</td><br /><td>- ' . $hash_row['real_name'] . '</td><br /></tr>'; } echo '</tbody></table></td><br />'; ?> I know there has to be a better way to count how many entries I have in my mysql db than what I'm currently using. Let me just show you what I'm trying to do and it will make better sense. http://batads.com/display.php You see how I am echoing the number of each category on one page? I am sure the current script I am using is insanely inefficient and as my DB grows I think it will cause me problems. Any suggestions on how to do this more efficiently? Below is what is currently running that page. Thank you. Code: [Select] <td><h4>Public Ads</h4><br> <?php echo '<a href="browse1.php?cat=1">Bill Boards<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='1'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=2">Transportation<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='2'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=4">Shopping Centers<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='4'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=3">Posters / Signs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='3'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=5">Bus Stops<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='5'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=6"> Other-Public<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='6'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Event Sponsorship</h4><br> <?php echo '<a href="browse1.php?cat=7">Concerts<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='7'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=8">Fairs<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='8'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=10">Sports<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='10'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=9">Trade Shows<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='9'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=11">Other-Event<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='11'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Online Ads</h4><br> <?php echo '<a href="browse1.php?cat=12">Banner Space<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='12' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=13">Social Media<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='13' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=14">Email Lists<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='14'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=15">Blog Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='15'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=16">Ezine Articles<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='16'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1area.php?cat=17">Other-Online<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='17'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Print Ads</h4><br> <?php echo '<a href="browse1.php?cat=18">Magazine<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='18'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=19">Newspaper<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='19'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=20">Brochure<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='20'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=21">Press Release Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='21'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=22">Other-Print<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='22'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Broadcasting Ads</h4><br> <?php echo '<a href="browse1.php?cat=23">TV / Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='23'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=24">Radio<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='24'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=27">Movies<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='27'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=25">Mobile Phone<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='25'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=28">Cinema<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='28'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; }?> <?php echo '<a href="browse1.php?cat=26">Press Release TV<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='26'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=29">Other-Broadcast<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='29' "; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> <td><h4>Commercial Space</h4><br> <?php echo '<a href="browse1.php?cat=33">Private Property<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='33'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=34">Vehicle Wrap<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='34'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=35">Front Yard<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='35'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=36">Self Promotion<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='36'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=37">Other-Commercial<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='37'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </tr> <tr> <td><h4>Business Ads</h4><br> <?php echo '<a href="browse1.php?cat=30">Window Display<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='30'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=31">Interior Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='31'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=32">Point of Sale Ads<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='32'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=41">Other-Business <a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='41'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?></td> </td> <td><h4>Misc</h4><br> <?php echo '<a href="browse1.php?cat=38">Creative Advertising<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='38'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=39">Video Games<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='39'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> <?php echo '<a href="browse1.php?cat=40">Other-Misc<a/>'; $query = "SELECT category, COUNT(*) FROM postlisting WHERE category='40'"; $result = mysqli_query($dbc,$query); while($row = mysqli_fetch_array($result)) {echo '('.$row[COUNT(category)].')<br>' ; } ?> </td> </tr> </table> Write a function Counter() that keeps track of the number of times it is called. This function should not take any parameters and return the number of times that it has been called. 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 Hello, I'm using the following code to count the amount of SQL results and divide it. Works great as is but I want to alter it so it works with categories. $amount = mysql_query('SELECT COUNT(`car_id`) AS num FROM `tbl_cars`') or die(mysql_error()); $amount_row = mysql_fetch_assoc($amount); I tried adding... WHERE car_cat = '".$cat."' which causes an error. Why doesn't this work, and how can I get the amount of results as a variable? Hey All, I need to count and display the number of rows I have. <?php //declare the SQL statement that will query the database $query = " SELECT COUNT(id) FROM connectvisits WHERE staffid = '$staffid' "; //execute the SQL query and return records $result = mssql_query($query); $thismonth = mssql_num_rows($result); echo "Total Meetings This Month: "; echo $thismonth; echo "<br />"; ?> For some reason I keep getting a result of 1. Everything else I try gives me a "Resource ID" number. Any help would be apprecaited. Maybe I have the completely wrong code. Thanks! hey i'm just woundering how i would go abouts on echoing unread messages sent to a user i want to beable to see how many unread messages i have returns -30. how can i remove the minus so it just returns 30 Code: [Select] $days = (strtotime(date("Y-m-d")) - strtotime($info['expiredate'])) / (60 * 60 * 24) echo $days Hello,
I am trying to get the report of my sales table. I want to get total number of leads for each month. And then i have to use this data to create graph using google graph.
But i am not getting how eactly i can get this.
Here is my code
<?php if(isset($_POST['submit'])) { $type = $_POST['type']; $sql="select * from leads where lead_customer='".$type."'"; $query=mysql_query($sql); while ($row = mysql_fetch_array($query)) { list($year,$month,$day)=explode("-", $row['last_modified']); $l = $row['last_modified']; $count=mysql_num_rows($month); echo $count; $myurl[] = "['".$month."', ".$count."]"; } print_r($myurl); echo implode(",", $myurl); } ?>But for $count, it doesn't show any values. below is my database. Capture.PNG 18.16KB 0 downloads Please suggest me Hey, having an odd issue, looking to show players whos within 25 ranks of them lower and higher, i'm unsure as to why the following code doesn't actually do it... would anyone care to explain... Code: [Select] <?php $score = $playerdata['score']; $sql = "SELECT * FROM `players` WHERE '$score' BETWEEN 25 AND 75 ORDER BY `score` DESC"; $query = mysql_query($sql) or die(mysql_error()); $i=0; while($players = mysql_fetch_array($query)) { $i++; ?> What I was trying to do was take the value of the question from the resultset and get it to only show the first 30 characters then check to see if its in the middle of a word or not and do a while loop until it reaches the first space. And then have it add the ... after it. It echos the dots but doesn't echo the question string. Code: [Select] $query = "SELECT polls.ID, polls.question, polls.totalVotes FROM polls ORDER BY polls.dateCreated"; $result = mysqli_query ( $dbc, $query ); // Run The Query $rows = mysqli_num_rows($result); $question = stripslashes($row['question']); $string = substr($string, 0, 30); $char = strlen($string); while ($char > 0) { if ($string{$char} == " ") break; $char = $char - 1; } $string = substr($string, 0, $char); Then on my table I have this: Code: [Select] <tbody> <?php echo $string; while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { echo ' <tr> <td>"' . $string . '..."</td> <td><a href=# id="answers" title="' . stripslashes($row['question']) . ' Answers">Answers</a></td> <td>' . $row['totalVotes'] . '</td> <td style="text-align:center;"><img src="img/notepad.png" class="edit" rel="' . $row['ID'] . '"/></td> </tr>'; } ?> </tbody> |