PHP - Count Method
I am printing question id and corect answers and incorrect one.
Example: Questionid =8 Incorrect Incorrect Incorrect Correct Correct Incorrect This will be repeated for other question id. Now I would like to count total answers. In my example it will be 6. I would like to count the correct one so that will be 2. And print 2 as outcome. So far I have Code: [Select] $sqlll=questionid(); while($infoo = mysql_fetch_array( $sqlll)) { echo "<hr><br><strong>{$infoo['Que_ID']}</strong><br />\n"; $_Session1=$infoo['Que_ID']; $que=question($_Session1); while($infooo = mysql_fetch_array( $que)) { $answer1 = $infooo['Que_Answer1'] == $infooo['Ans_Answer1']; $answer2 = $infooo['Que_Answer2'] == $infooo['Ans_Answer2']; $answer3 = $infooo['Que_Answer3'] == $infooo['Ans_Answer3']; $answer4 = $infooo['Que_Answer4'] == $infooo['Ans_Answer4']; if ( $answer1 && $answer2 && $answer3 && $answer4) { echo ('<b><p style="color: green; text-align: left"> Correct </p></b>'); $scoree = $scoree + 1; } else { echo ('<br><b><p style="color: red; text-align: left"> Incorrect </p></b></br>'); $intt= $intt +1; } } 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
My script has 3 classes (that are relevant to this discussion): DB, User and Validate. They are all in independent files and loaded automatically, when required, by an autoloader.
The error messages I am getting a Any pointers as to what I am doing wrong, or what I should be doing, would be most welcome. 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 I know I'm posting this inside the PHP coding board but I'm curious on how most handle this situation. I have a page that uses php to retrieve data from my database and I want to have it place a | in between each of the returned data which it does but it still places one after the last returned row. I'm wondering if I should do this with jquery load and then have it place that character in between each of the data or if there's a way to do it with php or what? Any ideas? Code: [Select] <?php require ("../header.php"); ?> <div id="titlehistory" class="content"> <h1 class="pageheading">Title History</h1> <?php $titlesQuery =" SELECT titles.titleName, titles.shortName FROM titles WHERE titles.statusID = 1 ORDER BY titles.ID"; $titlesResult = mysqli_query($dbc,$titlesQuery); ?> <p><span class="minilinks"> <?php while ( $row = mysqli_fetch_array ( $titlesResult, MYSQLI_ASSOC ) ) { $fieldarray=array('titleName','shortName'); foreach ($fieldarray as $fieldlabel) { ${$fieldlabel} = $row[$fieldlabel]; } echo '<a href="/titlehistory/'.$shortName.'">'.$titleName.'</a> |'; } ?> </span></p> <p class="nohistory">Please select a title to view.</p> </div> <?php require ("../footer.php"); ?> I am trying to insert the current Date/Time into mysql database using the following code. I do not understand how $submitDate & $submitTime are to be set. Will this work as coded? Code: [Select] <?php class SubmitDateRecord { const DB_TABLE = 'timesheet'; const DB_FIELD_SUBMIT_TIME = 'submit_time'; private $submitDate; private $submitTime; public function setSubmitDate($submitDate) { $this->submitDate = $submitDate; } public function getSubmitDate() { return $this->submitDate; } public function setSubmitTime($submitTime) { $this->submitTime = $submitTime; } public function getSubmitTime() { return $this->submitTime; } public function addRecord() { $insertTable = "`".self::DB_TABLE."`"; $insertFields[] = "`".self::DB_FIELD_SUBMIT_TIME."`"; $insertValues[] = "'{$this->submitDate} {$this->submitTime}'"; $sqlBuilder = new SQLQBuilder(); $query = $sqlBuilder->simpleInsert($insertTable, $insertValues, $insertFields); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); if ($result) { return true; } else { return false; } } private function _buildRecordObjects($result) { while ($row = mysql_fetch_array($result)) { $submitdateObj = new SubmitDateRecord(); $submitdateObj->setAttendanceId($row['attendance_id']); $submitdateObj->setEmployeeId($row['employee_id']); /* $row['submit_time'] comes in '0000-00-00 00:00:00' format. * We want date in '0000-00-00' format and time in '00:00' format. */ $tmpArr = explode(' ', $row['submit_time']); $submitdateObj->setSubmitDate($tmpArr[0]); $submitdateObj->setSubmitTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero $submitdateObj->setStatus($row['status']); $submitdateArr[] = $submitdateObj; } return $submitdateArr; } } Hi There, I am trying to implement a facebook plugin into my website. When the user posts a link to my site on their wall it will redirect them back to my page with some GET info in the URL eg. www.example.com/download.php?post_id=43221. I don't need to know the Post Id number, I just need to know if they went to the facebook page. So my question is, how would I make it s that if there is a Post ID number it displays the page and if not it directs them to another page? Please help me with this, i'm totally stumped. Thanks George Bates Hi, I have a problem and can't seem to figure out how to do it.. Basically i have these 2 tables: Quote People Pid Pname Pdateadded Pdeleted And.. Quote Quote: PeopleCon PCid Pid PCorder Pdateadded Pdeleted Now, currently i insert the data into a table "People".. like you guys have helped me with.. But what i need to do is, first check to see if the author already exists in the People table, if so then just INSERT into PeopleCon, ELSE INSERT into both People and PeopleCon... Also if there are 4 authors, and 2 exist in People, and 2 do not. What needs to happen is the first 2 are simply inserted into PeopleCon, but the last 2 are INSERTED into both People and PeopleCon. When the authors are inserted into PeopleCon, the PCorder row needs to increment by the number of authors byt order of author. So this is the logic: Multiple authors are entered in textboxes Fire the script Check to see if author already exists in "People" table IF it does exist, INSERT into PeopleCon table ELSE do the insert into the People AND PeopleCon table, first it will INSERT into the People, and GET the MAX (ID) and insert into the PeopleCon So i currently have this, but as 3 separate methods: class People { public function checkNameExists(){ $query = "SELECT * FROM People WHERE Pname = '". mysql_real_escape_string($_POST['author'])."'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0): $row = mysql_fetch_array($result); return true; else: return false; endif; } public function insertAuthor(){ $callback = create_function('$author','return "(\'".mysql_real_escape_string($author)."\',NOW(),0)";'); $sql = sprintf( 'INSERT INTO People (Pname, Pdateadded, Pdeleted) VALUES %s' ,implode(',',array_map($callback,$_POST['author'])) ); $result = mysql_query($sql); return "Successfully added NEW author"; } public function insertAuthorCon(){ $sql = "INSERT INTO PeopleCon (Pid, PCorder, PCdateadded, PCdeleted) VALUES ( 'MAX ID WILL GO HERE', 'INCREMENT OF ORDER GOES HERE', now(), 0 )"; $result = mysql_query($sql); return "Successfully added existing author"; } But obviously i need to combine these together into one method to match what i am trying to achieve.. Can anyone point me in the right direction? Thanks again... here is what i am trying to do. i have a url in my browser like this: http://localhost/jmla/index.php?option=com_content&view=article&id=1295:sovereign-a-country-risk-workshop as usuall we get elements form the url using the $_GET method, but here when i try to get id from the above url. i can get 1295:sovereign-a-country-risk-workshop. whereas the id is only 1295 and the other part is alias which i want to get seperately. is there a way to do so? Hi all, What is the maximum size of data that we can pass through GET Method? And can we increase its size ? The following query code works correctly, however, I'm trying to figure out which is best when working with themes, templates, content pages. My themes are my different versions of the main site designs. As of right now I have the following code plus the database structure. site_themes - id, theme_name, status_id (only one theme can have a value of 1(active) at any given time) site_templates - id, template_name, header_code, footer_code, status_id (any can have a value of 1(active) at any given time, Code: [Select] <?php require("kowmanager/config/database.php"); $site_variables_query = "SELECT * FROM site_variables WHERE id = '1'"; $site_variables_result = mysqli_query($dbc, $site_variables_query); $row = mysqli_fetch_array($site_variables_result, MYSQLI_ASSOC); $site_theme_query = "SELECT * FROM site_themes WHERE status_id = '1'"; $site_theme_result = mysqli_query($dbc, $site_theme_query); $row2 = mysqli_fetch_array($site_theme_result, MYSQLI_ASSOC); if ($row['site_is_down'] == 'Yes') { } else { echo "site is up"; } ?> Hi there, I want to allow the ability for DJ's to turn on and off radio requests. Now obviously I've encorporated a check box and submit button within a PHP login. But I was wanting to know if this can be done with PHP or is a database required as the option will need to be remembered for a period of time. I'd probably look to do it by making it display on a page 'requests enabled' if enabled and a blank page if disabled. therefore I could encorporate: <?php if(!empty($requests)) { //requests template } else { //radio requests disabled template } ?> What's the best method for this? Thanks 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 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! 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? 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 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 Hi, I'm want to be able to change small site contents by using links like: site.com/?radio1, site.com/?radio2, but i want an easier way of making small bits of text change, for example, at the moment, i'm using: Autofresh is: <?php $link ='hits.php?on'; if (isset($_GET['on'])) echo "Enabled |<a href=\"?off\"> Disable?</a>" ?> <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo "Disabled |<a href=\"?on\"> Enable?</a>" ?> Is it possible to do that with only one <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo "Disabled |<a href=\"?on\"> Enable?</a>" ?> So i can have multiple echo's and assign which echo i want to use, for example: <?php $link ='hits.php?on'; if (isset($_GET['off'])) echo1 "Disabled |<a href=\"?on\"> Enable?</a>" echo2 "Enabled |<a href=\"?off\"> Disable?</a>" ?> <?php include echo2 ?> i know that wont work, but since im new to php, i need to explain what i mean. THANKS James |