PHP - Sos Logical And Inner Join Help Guys
im trying to make a salary system which would display a month salary according to login hours so i got two different tables storing data like
1. users table id, name, password, salary
2.attendance table id, user_id, Employee_Name, Remark, Login_Hours, Date
so what im looking to do is fetch all users id, name and salary from users table and then match it with attendance user_id,Employee_Name ,Login_Hours, table and then also count numbers of result for a particular year-month so that i could do the hourly wage calculation.
could someone help out i got no idea how to achieve it
apprieciate your help,
thanks
i tried something like this it does output something but still dunno how to match results of both tables and get result
$date = '2014-11'; $query1 = "SELECT COUNT(*) as num FROM attendance WHERE Date LIKE '%".$date."%' AND Employee_Name='moses'"; $total_pages = mysql_fetch_array(mysql_query($query1)); $total_res = $total_res[num]; // total rows counting of total office days of a month $result2=mysql_query("SELECT id, user_id, Employee_Name, Remark, SUM(Login_Hours), Date FROM attendance WHERE Employee_Name='moses'"); while($row = mysql_fetch_array($result2)){ echo $sal_to_month = 9000/$total_res; //9000 is salary should be fetched from users table echo '<br/>'; echo $sal_to_month/9*$row['SUM(Login_Hours)']; } Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308855.0 I made a bot, that scrapes content from a forum, i cant access the forum in work, so am trying to make something discreat to read it on my own site while at work. Anyway the links to threads are something like this. I got help and i know how to extract the unique thread number using regex. However i have a problem. What i really need, now that i think about it, is a way of getting the thread number and the thread title (so i can make sense of what im reading.) The thread title is in the setWindowStatus function. I cant think of a way to do it. I dont even know if it would work in an array what id basically like is something that says 1) Thread title - Thread id 2) Thread title - Thread id etc that is stored in a way that i can easily manipulate. Code: [Select] <img src="http://s2.images.proboards.com/xx.gif" alt=" " border="0"/></font></td><td class="windowbg" bgcolor="FFFFFF" width="48%" style="cursor:pointer;" onClick="if(!pb_bubble)location.href='/index.cgi?board=general&action=display&thread=13483';" onMouseOver="mouseOverHighlightCell(this);setWindowStatus('Lurkers, show your face ');return true; Okay i'm trying to compare these sets of variables. code looks like this.. Code: [Select] if( $row->cash > $finalcash && $row->core1 > $finalcore1 && $row->core2 > $finalcore2 && $row->core3 > $finalcore3 && $row->core4 > $finalcore4 ) { return true; } else { return false; } First question is this the appropriate way of doing this? Or would a nested if statement work better? example: Code: [Select] if ($row->cash > $finalcash) { if ($row->core1 > $finalcore1) { if ($row->core2 > $finalcore2) { if ($row->core3 > $finalcore3) { if ($row->core4 > $finalcore4) { } else { return false; } } else { return false; } } else { return false; } } else { return false; } } else { return false; } I know it looks pretty messy, so i'm wondering if anybody is aware of an alternative to achieving this? i have two tables assume question and answer question table consists of Question_Date, Question_id and Question_title answer table consists of Answer_Date, Question_id, Answer_id and Answer_title let say i have 1000 records and i wish to display only the last 100 records combining both question and answer. How can i do this with loop..any suggestion would be appreciate thanks In php is there a way to shortcut logical operators... example: Code: [Select] if ($row['CustomerSaas'] == 'Yes' && ($row['CustomerSaasPaidStatus'] == 'Trial' || $row['CustomerSaasPaidStatus'] == 'Trial Ended')) { to Code: [Select] if ($row['CustomerSaas'] == 'Yes' && ($row['CustomerSaasPaidStatus'] == 'Trial' || 'Trial Ended')) { Hi there,
This may not be the correct space to post this - but I'm very new to all this.
I've created a page that will run a php script to output a query. I would then like to send that same query via email - however from a design perspective I don't think the correct process is to click 'submit' to view the query and then 'submit' to send the result via email?
Can you please advise on some design solutions regarding this issue?
Thanks!
Hi guys, i'm trying to increment a variable / session value whenever 'submit' comes in the POST. I can't seem to get around the logic of this. Code looks like this: Code: [Select] $var = 0 if($_POST('submit'){ $_SESSION['var2'] = $var++; } What I want it to do is increment the value of the session index everytime a user clicks 'submit'. But because i've reset $var to 0 everytime, it's always just going to stay at 1. I just can't think of a way to achieve this, does anyone have any clue on how I can? fixed. I have a simple question how would I do this? If a row in mysql i have "type" is set to "yes" do that stuff or if it's not do some other stuff I'm Jay, new to PHP hoping to start up and get some things done by handling some actual problems for a change.. So hey! Thanks.
I'm trying to $_GET a value and then input it into my database but this obviously doesn't work, I have no idea why. As soon as I run a "if (isset($_POST['submit']" action the value of the $_GET dissapears completly, I have no idea why, I've tried both XAMPP and WAMP with Apache and MySQL but it doesn't seem to work. Is this simply just not possible or am I doing something wrong...Help me!!! Hello to all... Can someone help me on this one? I have a hard time on modifying this code. This code was given to me as the reply on my old post.. However i put the wrong string on that post.. Now my problem is how to parse again this string Quote #1# "3032117","+639217195804","+447537404702","test","2012-01-13","03:26:15","test another sample sms. this is a sample sms","" "3032118","+639105701066","+447537404702","test","2012-01-14","03:27:12","test sms sample 2. test only.","" I need to drop the #1#, and split the string into an array on +447537404702..Please refer on the code below Code: [Select] function parse_csv($line,$delimiter=',',$quote = '"',$newline="\n") { $line = str_replace("\r\n",$newline,$line); //change extended newlines. $line = str_replace("\n",$newline,$line); //this is here in case you pass a different newline to the function. $line = str_replace('"",""','',$line); //remove double quoted commas. $line = str_replace($quote,'',$line); //remove quotes. $line = preg_replace('~,{2,}~',',',$line); //remove double commas. if(strstr($line,$newline)) { $parts = explode($newline,$line); //all new lines should be an array. } if(isset($parts) && is_array($parts)) { //if a newline exists foreach($parts as $value) { //rerun the function on each line. $result = parse_csv($value,$delimiter,$quote,$newline); //only include the results, if there is more than 1 line; if(isset($result[1])) { $arr[] = $result; } } } else { $arr = explode($delimiter,$line); //make an array based on the delimiter. //cleanup = delete lines that has no values. foreach($arr as $k => $v) { if(empty($v)) { unset($arr[$k]); } } } return $arr; } $file ='#1# "3032117","+639217195804","+447537404702","test","2012-01-13","03:26:15","test another sample sms. this is a sample sms","" "3032118","+639105701066","+447537404702","test","2012-01-14","03:27:12","test sms sample 2. test only.",""'; $array = parse_csv($file,',','"',"+447980123456"); echo '<pre>' . print_r($array,true) . '</pre>'; //show the array construct. //echoing the values out. foreach($array as $key => $value) { echo '<h4>' . $key . '</h4>'; foreach($value as $v2) { echo $v2 . '<br />'; } echo '<hr />'; } This is the wrong string Quote #1# "4","+447980123456","+447781484145","","2009-06-08","10:38:15","hello "","" world","Orange" "5","+447980123456","+447781484146","","2009-07-08","10:38:55","hello world","Orange" Can someone help me on this one? any help will be appreciated... Thanks in advance! This is the link on my old post http://www.phpfreaks.com/forums/index.php?topic=351398.new;topicseen#new This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=322691.0 Hey everyone A little advice would be great. okay... I have a system that registers users and then allows them to take part in a quiz, which uses sessions and a database however what the problem is, is that i would like the user to be able to see the results of there quiz rather than destroying a session on logout.php for example when they login, they will click member area for example and this will display info about the quiz they completed.... i.e. Scores How would i do keep this info so its not lost on logging out?? Thanks in advance guys Lance Hi, I have a lot while loops, for loops and PHP hard coded with HTML. The HTML now has become super hard to read sometimes I get confused where I am lol. My question is it better to make few other PHP files, with the loops and just call them with Include or Request or could you just tell me how you guys work around this? Hello world,
Im a development fan,but not a coder.
Im planning to hire a developer for a project but i want some advice from experts first.
My project is a market place where sellers and stores could place their ads, I want it very very custom,so here are the questions.
1. Do i use php from scratch or maybe a CMS?
2.Is there a possibly to develop a custom cms to admin this project if it has been developed on php or i have to learn to code by the way?
3.how i can detail exactly what i want to the coder,is there a glossary or something like that for the modules?
this is the question that came up now,but fell free of give me all advice you think i might know.
Thanks.
I have a script on my website, freestudentcloud.com. But i want: 1) that new users must activate there account. 2)If the user lose his pass that he can Change/renew his password. I hope someone can help me with my problems. I have no knowledge of php, but i have tried many thinks. like http://www.learnphponline.com/scripts/email-activation-for-php-forms This is the users.php Code: [Select] <?php if( ! defined( '_AppPath' ) ) { exit( 'Direct access to this script is not permitted' ); } class Users { var $app; function __construct( $app ) { $this->app = $app; } //****************************** // Insert new user //****************************** function create($return = false) { //Data validation $error; if(empty($_POST['password'])) $error = 'Please enter a password'; if(!empty($_POST['maxupload']) && !ctype_digit($_POST['maxupload'])) $error = 'Please enter numeric values only for max. upload limit'; if(empty($_POST['name'])) $error = 'Please enter a username'; //Check for errors if($error) { return array("error" => $error); } $user = array(); $user['name'] = $this->app->db->real_escape_string($_POST['name']); $user['password'] = md5('_password_'.$_POST['password']); $user['maxupload'] = $_POST['maxupload'] ? $_POST['maxupload'] : ''; $user['admin'] = $_POST['admin']; //remove white space from username $user['name'] = str_replace(" ","",$user['name']); //Check for illegal characters $valid = array('-', '_'); if(!ctype_alnum(str_replace($valid,'',$user['name']))) return array("error" => 'Only alphanumeric characters and "-" or "_" are allowed'); if(strlen($user['name']) > 30) return array("error" => 'Username is too big (30 characters allowed)'); //Insert user into database $query = "INSERT INTO users VALUES (NULL, '".$user['name']."', '".$user['password']."', '".$user['admin']."', '0', '".($user['maxupload']*1000)."')"; if(!$user['maxupload']) $query = "INSERT INTO users VALUES (NULL, '".$user['name']."', '".$user['password']."', '".$user['admin']."', '0', NULL)"; //Save user record in database $result = $this->app->db->query($query); if(!$result) return array("error" => "The username you chose is taken already"); //Set user id $user['id'] = sprintf("%011d", $this->app->db->insert_id); //Create meta entries for new user $this->app->meta->create("downloads_".$user['id'],0,$user['id']); //downloads entry $this->app->meta->create("uploads_".$user['id'],0,$user['id']); //uplodads entry $user['password'] = ''; //If is ajax call return upload data if($return == true) { return $user; } } //****************************** // Get users //****************************** function get() { $user = $this->app->session->get_var( 'id' ); $query = "SELECT id,name, admin, space, maxspace FROM users WHERE id != '$user'"; $response = $this->app->db->query($query); //Check if database has records if ($response->num_rows > 0) { //Records were found $users = array(); while($row = $response->fetch_array()) { //Change bytes to kylobytes if maxspace is set if($row['maxspace']) $row['maxspace'] = $row['maxspace'] / 1000; $users[] = $row; } return $users; } else return false; } function getinfo($user) { $query = "SELECT id,name, admin, space, maxspace FROM users WHERE name = '$user' LIMIT 1"; $response = $this->app->db->query($query); if ($response && $row = $response->fetch_assoc()) { return $row; } } //****************************** // Delete user //****************************** function delete($user) { $query = "DELETE FROM users WHERE id = '$user'"; $this->app->db->query($query); //Remove user meta entries $this->app->meta->delete("uploads_".$user); //uplodads entry $this->app->meta->delete("downloads_".$user); //uplodads entry } //****************************** // Change user password //****************************** function updatepassword() { //Data validation $error; if(empty($_POST['password'])) $error = 'Please enter a password'; //Check for errors if($error) { return array("error" => $error); } $password = md5('_password_'.$_POST['password']); $user = $this->app->session->get_var( 'id' ); $query = "UPDATE users SET password = '$password' WHERE id = '$user'"; $response = $this->app->db->query($query); return $response; } //****************************** // Update user info //****************************** function update($return = false) { //Data validation $error; if(!empty($_POST['maxupload']) && !ctype_digit($_POST['maxupload'])) $error = 'Please enter numeric values only for max. upload limit'; //Check for errors if($error) { return array("error" => $error); } $user = array(); $user['id'] = $_POST['value']; $user['maxupload'] = $_POST['maxupload'] ? $_POST['maxupload'] : NULL; $user['admin'] = $_POST['admin']; //Update user in database $query = "UPDATE users SET maxspace = '".($user['maxupload']*1000)."', admin = '".$user['admin']."' WHERE id = '".$user['id']."'"; if(is_null($user['maxupload'])) $query = "UPDATE users SET maxspace = NULL, admin = '".$user['admin']."' WHERE id = '".$user['id']."'"; $response = $this->app->db->query($query); //If is ajax call return upload data if($return == true) return $user; } //****************************** // Update user used space //****************************** function updatespace($space) { $user = $this->app->session->get_var( 'username' ); $query = "UPDATE users SET space = '$space' WHERE name = '$user' LIMIT 1"; $response = $this->app->db->query($query); if($response) return $response; } //****************************** // Login user //****************************** function login($user,$password) { $user = $this->app->db->real_escape_string($user); $password = md5('_password_'.$password); $query = "SELECT * FROM users WHERE name = '$user' AND password = '$password'"; $response = $this->app->db->query($query); if ($response && $row = $response->fetch_assoc()) { // Credentials matched $this->app->session->add_var( array( 'username' => $row['name'],'id' => $row['id'] )); if( $_SESSION ) { session_regenerate_id( true ); } # Redirect to dashboard $path = $this->app->path."manage/"; header ("Location: $path"); } else { return "Incorrect"; } } //****************************** // Logout user //****************************** function logout() { $path = $this->app->path."manage/"; session_destroy(); header("Location: $path"); } } ?> Register.php Code: [Select] <?php if( ! defined( '_AppPath' ) ) { exit( 'Direct access to this script is not permitted' ); } ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <title>Login</title> <!--STYLES--> <link rel="stylesheet" href="<?php echo $viewsdir ?>views/css/reset.css" type="text/css"> <link rel="stylesheet" href="<?php echo $viewsdir ?>views/css/styles.css" type="text/css"> <!--SRIPTS--> <script src="<?php echo $viewsdir ?>views/plugins/jquery.js" type="text/javascript"></script> <script src="<?php echo $viewsdir ?>views/plugins/jquery.form.js" type="text/javascript"></script> <script src="<?php echo $viewsdir ?>views/plugins/core.js" type="text/javascript"></script> <script> path = ''; </script> </head> <body> <div id="main" class="notice container"> <!--Wrapper--> <div id="wrapper" class="notice"> <!--Content--> <div id="content" class="padding"> <?php if($error) : ?> <div id="message" class="one message invalid clearfix" style="display: block;"> <?php echo $error ?> </div> <?php endif ?> <form id="on-login" method="post"> <!--Username--> <p class="placeholders"> <label for="user">Username</label> <input name="name" type="text" autocomplete="off" value="<?php echo $_POST['name'] ?>"> </p> <!--Password--> <p class="placeholders"> <label for="password">Password</label> <input name="password" type="password" autocomplete="off"> </p> <p> <label for="robot">Are you human ? <span class="help">- how much is 2 + 3 ?</span></label> <input type="text" name="robot" value="<?php echo $_POST['robot'] ?>"> </p> <input type="submit" class="submit" name="action" value="register"> <a class="help one" href="<?php echo $path."manage/"; ?>">Log in</a> </form> <!--End #content--> </div> <!--End #wrapper--> </div> <!--End .container--> </div> </body> </html> The database is: table: users Column: | id | name | email | password | admin | space | maxspace | What can i do? i do not ask to make the whole sript , i wanna learn, but i don't get it at all. Thank you, Tim This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=317497.0 This topic has been moved to PHPFreaks.com Questions, Comments, & Suggestions. http://www.phpfreaks.com/forums/index.php?topic=351181.0 goodguybadguy.net they can tell when you enter an email address that hasnt been registered yet. how the hell are they doing this? does gmail or yahoo have some sort of database they allow access to for this? |