PHP - Anyway To Make Count(*) Return 0?
Hi I'm using the below code <?php //Getting failed orders for Online $data=mysqli_query($mysqli,"SELECT Error, COUNT(*) as total FROM db WHERE Department='Online' AND Date BETWEEN '$Fromdate' AND '$Todate' GROUP BY Date"); ?> var totalOnline=[<?php while($info=mysqli_fetch_array($data)){ echo $info['total'].',';} /* ?>]; Now some of these doesn't return anything as it should, but is there a way to return 0 instead? Similar TutorialsIs it possible to count how many returns there are on a if statement? Where you can see Code: [Select] echo 'yes'; it will echo this twice according to my condition, all I want is the the value 2 that it has returned twice... ? Code: [Select] while($row = mysql_fetch_array($bookings)) { if(time() > $row['returnby'] && $row['returned']==0) { $books_overdue = count($row['returned']); } if(time() > $row['returnby'] && $row['returned']==1) { $returned_ontime = count($row['returned']); } if(time() <= $row['returnby']) { echo 'yes'; } } thanks for help. 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 Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. 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 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 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? If a user is on Page X, but not logged in, when they log in to my website, I want them to return back to Page X (in this example). To handle this, I am adding this code to the top of each webpage... Code: [Select] // Set current Script Name. $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME']; And then as part of my Log In script I have... Code: [Select] // Redirect User. if (isset($_SESSION['returnToPage'])){ header("Location: " . BASE_URL . $_SESSION['returnToPage']); }else{ // Take user to Home Page. header("Location: " . BASE_URL . "index.php"); } What do you think about this approach? Thanks, Debbie return (int) $value VS return $value
What is the purpose of using int in a bracket? return (int) $value
Which is the best and safest method?
Thank you
Hello First of all i am very weak about OOP and classes in php. I am learning now but i stuck with very silly problem. My codes are below. <?php class myTestClass { function __construct() { $this->OldName("This is Old Name"); } function OldName($VeryOld) { if($VeryOld == "This is Old Name") $this->NewName(); else $VeryOld = "Something Wrong"; return $VeryOld; } function NewName() { echo "This is Brand New Name"; } } $i = new myTestClass(); ?> if i send value to OldName "This is Old Name" then codes works fine. But if i send "This is Old Nameeee" then does not appear anything. what i want to do is print "Something Wrong" text if i enter different value. I have no idea what return do and how it do? How to retrieve/print "Something Wrong"? i can do that with echo but i want to transfer result of return to another function. Really appreciate for any help/idea. Hi Everyone,
My name is Raoul Grosser, live in The Netherlands.
I'm a front/backend developer working with AngularJS and Bootstrap and Symphone2.
I've been writing PHP code for over 4 years now my focus is on opensource projects.
If you have any question, please let me know!
Hey all. My site has a config database table that has a column showlogin to set whether or not login functionality is enabled. I'm playing around with MySQLi, Classes, and Returns. My return is always 1. Where am I going wrong? test.php <?php // Start Session session_start(); // Production Settings ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ALL); include 'db.php'; $mysqli = new mysqli($host, $user, $pass, $db); class styles { function showlogin($show) { global $mysqli; $select = $mysqli->query("SELECT showlogin FROM config LIMIT 1"); $value = $select->fetch_object(); if ($value->showlogin = 1) { return 1; } return 0; } } $login = new styles(); echo $login->showlogin($show); ?> Hi, I'm new to the forum, I have a slight issue with my script. Basically, I need to figure out a script that will allow me to do the following: - The user defines x amount of ours to count down (ie. 16 hours, 8 hours, 4 hours) - The script then starts the count down of the x hours - I need the script to count between 08:00 - 20:00 after 20:00 it needs to stop, then start again at 08:00 - The script also need to stop throughout the weekend (ie counts until 20:00 on friday, stops saturday & sunday, then starts 08:00 on monday) Can this be done? If so, any pointers or help? Many thanks, Lewis. I 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; I would appreciate if someone could figure this out or tell me the easiest way to do this. I need a count up counter that appears in a textbox so I can record the time a user is on a page. On a side note, I do have their Start and finish time timestamp recorded in myphpadmin database but I am looking for the easiest (or best) way to do this. Any advice or scripts would be very much appreciated.
Thanks in advanced.
I did find this counter that works but the numbers appear 0.0.1 if counting up. I don't want to confuse the user. I really want to display to the user how long they was on a certain page.
<script> $(document).ready(function() { var time = '00:00:00', parts = time.split(':'), hours = +parts[0], minutes = +parts[1], seconds = +parts[02], input = $('#timeInput'); var timer = setInterval(function(){ seconds++; if(seconds == 60) { seconds = 00; minutes++; if(minutes == 60) { minutes = 00; hours++; } } var newTime = hours + ":" + minutes + ":" + seconds; $('#timeInput').val(newTime); }, 1000); }); </script> <input type="text" name="time" id="timeInput"/> |