PHP - Multiply/addition Php Mysql Help?
Heja
I have a MySQL database which contains information of members and the current balance of there accounts (eg: $1000) it also shows there current gain (eg: 1.2%) what i have been doing is individually updating each clients percent and balance. What i'm trying to work out is how to add a percent gain for the week and both the percent and balance of the clients are updated according to the submitted gain for example: Client 1 has $1,000 and has a current gain of 1.5% Client 2 has $,2000 and has a current gain of 2.5% I want to update both clients by 1.5% and then both clients be updated like so: Client 1 would now have $1,010.50 and now has a gain of 3.0% Client 2 would now have $2,020.50 and now has a gain of 4.0% I was looking around and could find much information on the internet or exactly has this can be achieved so i started to work on a addition and try atleast add the % however it dont go accordingly, i suppose im very rusty at my php. I started working around something like this: Code: [Select] mysql_select_db('mem') or trigger_error("SQL", E_USER_ERROR); $a1 = mysql_query("SELECT profits FROM account"); $a= $a1; $b=$b1; /* html <input type="text" name="b1" id="b1"> the % i want to update*/ $add=($a+$b); $sql = "UPDATE mem SET balance = balance +'$add'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } This obviously does not work but it could possibly give you a better understanding of maybe what im trying to do here. Any help would be appreciated. Thanks Similar Tutorialshi. I am stuck on the dropdown box value calculation. anyone can help me on this problem ? I appreciate it. I have two dropdown boxes on my webpage, and the values that in the dropdown boxes are retrived from the mysql database. dropdown box "A" displays two differnt values, which are "Chassise_Name" and "Chassise_price", and The dropdown box "B" displays the quantity of the item. Dropdown box "A" Dropdown box "B" SuperServer 7036A-T(Black) $90 3 "Superserver 7036A-T(Black)" is retrieved from the Chassis_Name ; "$90" is retrieved from the chassis_Price; "3" is retrieved from the Quantity in other table. Question: how can I take only the price on the Dropdown box "A" multiply the number in the Dropdown box "B"? Here is my code: Code: [Select] echo "<table border='1'>"; echo "<tr><td>"; $result = mysql_query("SELECT Chassis_Name, Chassis_Price FROM Chassis where Chassis_Form_Factor='ATX'") or die(mysql_error()); echo '<select name="Chassis" onChange="change()">'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option Name="Chassis">',$row['Chassis_Name'],' ',$row['Chassis_Price'],' ','</option>'; } echo '</select>'; echo "</td>"; echo "<td>"; $result= mysql_query("SELECT Number FROM Quantity") or die(mysql_error()); echo '<select name="Quantity" Value="Quantity" onChange="change()" >'; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result)) { // Print out the contents of each row into a table echo '<option Name="Quantity">',$row['Number'],'</option>'; } echo '</select>'; echo "</td></tr>"; echo "</table>"; ?> 1. Are there any functions that can make a multiply effect using PHP GD? 2. What is the best way to recolour a one-colour PNG while keeping transparency? I've tried this but savealpha isn't working. 3. How can I implement this ImageMagick code into a non-OOP PHP script and use variables for the image urls? Code: [Select] convert label:Rose label_white.gif composite -compose Multiply -gravity center \ label_white.gif rose: compose_multiply.gifhttp://www.imagemagick.org/Usage/compose/#multiply ImageMagick is my last resort... or the resort before using Flash. 4. Also, when the user chooses an option, how can I make the image update automatically (without refreshing)? The information will be passed via GET. Help, please? hi there - probably simple but cant find a straight example of this anywhere and i am very newby when it comes to programming. have a php search file that works fine with my mysql database. it use this argument for searching: Code: [Select] $result = mysql_query("SELECT * FROM ppl_tracks WHERE Keywords LIKE '%$_POST[searchkeywords]%' AND Mixed !=false ORDER BY Track");obviously Keywords is the field searched but i want it to look for 'searchkeywords' in another field - 'Description' and while at it - is it possible to enter 2 or more keywords in the submit form (using $POST) that will be searched in the 2 fields and will return a list ordered by relevancy (how many of the keywords searched appear in each record) hope this makes sense to someone I'm trying to build a small php script to help automate adding vacation time to keep track of employees available vacation. I can run the sql below, and it executes fine: Quote Update `vacation` set avail_vacation = `avail_vacation` - `used` where employee = "employee1"; I'm trying to build this into a php function. This is what I have so far: Code: [Select] <?php function sql_addition() { global $conn; global $_POST; $sql = "update `vacation` set `avail_vacation`= `avail_vacation` + `added` where employee = .sqlvalue(@$_POST["employee"])"; mysql_query($sql, $conn) or die(mysql_error()); } <html> <tr> <td class="hr"><?php echo htmlspecialchars("Add Hours")." " ?></td> <td class="dr"><input type="text" name="added" value="<?php echo sql_addition('"', '"', trim($row["added"])) ?>"></td> </tr> ?> </html> It's showing the error below where the field should be for submitting hours to add: Quote <input type="text" name="added" value="You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Help would be greatly appreciated. Hi I'm having an issue with a piece of code, it pretty much works but the line to output the total weight only seems to be picking up the count and not multiplying it by the weight. Any ideas why this is? Thanks in advance Code: [Select] <?php mysql_connect("localhost", "*****", "******") or die(mysql_error()); mysql_select_db("inventory") or die(mysql_error()); $data = mysql_query("SELECT * FROM testDB ORDER BY uid DESC LIMIT 30") or die(mysql_error()); Print "<p>"; while($info = mysql_fetch_array( $data )) { $totalweight = ($info['count' * 'itemtype']); Print $info['count'] . " "; Print $info['itemtype'] . " "; Print $totalweight . " kgs <br />"; } Print "</p>"; ?> I have a really confusing question. I dynamically generate arrays, but for the simplicity of the example we can just use two arrays. Code: [Select] Array 1 ( [0] = 1 [1] = 5 ) Array 2 ( [0] = 2 [1] = 6 ) How can I make the arrays multiple based on the same key value? array 1[0] * array 2[0] = 2 array 1[1] * array 2[1] = 30 I then want to sum the total of the multiplication. $total = 2 + 30; I need to do this to calculate covariance for a statistics procedure I am trying to run but I can't wrap my head around how to do the logic. Hello I though this code would work Code: [Select] mysql_query("UPDATE cart SET totprice = quantity * price WHERE ID='{$id}'")or die(mysql_error());because this is working fine Code: [Select] mysql_query("UPDATE products SET rating = rating + 1 WHERE ID='{$id}'")or die(mysql_error()); Anything wrong with it, or how should i do it? hii everyone how to add the values of rows in a database.... I have added the code of my database table Code: [Select] CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=23 DEFAULT CHARSET=utf8; And i have some rows like (1,peter, $94) (2,John,$16) .... .... .... .... .... i want to add those values (i.e their money) and shows like [ total money = $110]... I have done few queries like Code: [Select] SELECT id,SUM(money) FROM usersand Code: [Select] mysql_query("SELECT * FROM `users` SUM `money` WHERE id='$id'");But nothing seems to work out... Any help guysss.... Thanks in advance... Am trying to get a current price, add it to what is in the database and update the table with the new value. Every time i do it, it won't do the addition but update the table with the current price. Please, what am i doing wrong?
$sql2 = mysql_query("SELECT * FROM pbudget WHERE project_name = '$project' "); $budget = mysql_fetch_array($sql2); $actual = $budget['actual'] ; $actual = $budget['spent'] ; $tot = ($spent + $amount); $final = ($actual - $amount); //$final = ($actual + $amount); $r = mysql_query("UPDATE pbudget SET actual = '$final', spent ='$tot' WHERE project_name = '$project'") or die(mysql_error()); $que = mysql_query("UPDATE budget SET actual = '$final', spent ='$tot' WHERE category = '$cat'") or die(mysql_error()); 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! I am new to php and need help creating addition and multiplication tables using the html code we were given. I feel like I am on the right track, but I am getting a few errors and I cant figure them out. One of the errors is that it tells me I am not putting in a valid number for rows even though it is a positive number so it should work. Here is my code and all help is appreciated thanks in advance.
<html> <head/> <body> <form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>"> <table border="1"> <tr><td>Number of Rows:</td><td><input type="text" name="rows" /></td></tr> <tr><td>Number of Columns:</td><td><select name="columns"> <option value="1">1</option> <option value="2">2</option> <option value="4">4</option> <option value="8">8</option> <option value="16">16</option> </select> </td></tr> <tr><td>Operation:</td><td><input type="radio" name="operation" value="multiplication" checked="yes">Multiplication</input><br/> <input type="radio" name="operation" value="addition">Addition</input> </td></tr> </tr><td colspan="2" align="center"><input type="submit" name="submit" value="Generate" /></td> </tr> </table> </form> <?php //check to see if num of rows is numberic if (isset($_POST["rows"]) && is_numeric($_POST["rows"])){ //check to see if rows is a positive number if($_POST["rows"] > 0){ if(isset($_POST) && $_POST['operation'] == "multiplication") { for($r = 0; $r < $_POST["rows"]; $r++){ echo '<tr>'; for($c = 0; $c < $_POST["columns"]; $c++){ echo '<td>' .$c*$r. '</td>'; echo '</tr>'; }} } else if (isset($_POST) && $_POST['operation'] == "addition") { for($r = 0; $r < $_POST["rows"]; $r++){ echo '<tr>'; for($c = 0; $c < $_POST["columns"]; $c++){ echo '<td>' .$c+$r. '</td>'; echo '</tr>'; } } } } else{ echo 'Invalid rows columns parameters'; exit(); } } else{ echo 'Invalid rows columns parameters'; exit(); } ?> </body> </html> Hello People. Please can someone point me to where I can learn to program the following all one one page? Here is a screenshot of what I'm after. Idea being that you put hours and minutes into the top row. Then hours and minutes into the next row. Click the button and get the answer at the bottom. The answer to 1 hour 40 minutes added to 1 hour 40 minutes should obviously be 3 hours 20 minutes. Here's how I would approach it in another language, but am brand new to php hence the help required. Make the following variables. Hour1 Hour2 Minute1 Minute2 Total_Hours Total_Minutes Combined_Time I would then write something like Total_minutes = minute1 + Minute2 Total_hours = Hour1 + hour2 combined time = Total_hours * 60 + (Total_Minutes) // reset the total hours Total_hours = 0 Loop here.... while combined_time >60 Total_hours = Total_hours + 1 combined_time = combined time -60 re-do the loop Now in the boxes at the bottom put bottom hour box = total hours bottom minute box = combined_time (remaining minutes) here's the code I have so far. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <table width="527" border="0" cellspacing="5" cellpadding="5" bgcolor="#c0c5c9"> <p>Time Calculator</p> <p>Put your hours and minutes in the top boxes. Click the add time button<br /> to get the answer </p> <table width="401" border="1" cellspacing="5" cellpadding="5"> <tr> <td width="109"><input type="int" name="hour01" size="10" maxlength="10" /> Hrs</td> <td width="251"><input type="int" name="min01" size="10" maxlength="10" /> Mins</td> </tr> <tr> <td><input type="int" name="hour02" size="10" maxlength="10" /> Hrs</td> <td><input type="int" name="min02" size="10" maxlength="10" /> Mins</td> </tr> <tr> <td><input type="submit" name="submit" value="Add Time" /></td> <td><input name="hour_answer" type="int" size="10" maxlength="10" /> Hrs <input type="int" name="minute_answer" size="10" maxlength="10" /> Mins</td> </tr> </table> <tr></tr> </body> </html> <html> <head> <title>Sum Html Textbox Values using jQuery/JavaScript</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> $(function() { $(document).on('blur keyup', '.add, .sub', function(e) { var sum = 0; $('.add, .sub').each(function(i) { if (!isNaN(this.value) && this.value.length != 0) { if ($(this).hasClass('add')) { sum += parseFloat(this.value); } else { sum -= parseFloat(this.value); } } }); $('#total').text(sum.toFixed(2)); }) }) </script> </head> <body> <form method="post" action="calc.php"> Addition: <br/> Field 1: <input type="text" class="add" name="1" value="7500"/><br/> Field 2: <input type="text" class="add" name="2" value=""/><br/> Field 3: <input type="text" class="add" name="3" value=""/><br/> Field 4: <input type="text" class="add" name="4" value=""/><br/><br/> Total Addition: <br/><br/> Substraction: <br/> Field 1: <input type="text" class="sub" name="5" value=""/><br/> Field 2: <input type="text" class="sub" name="6" value=""/><br/> Field 3: <input type="text" class="sub" name="7" value=""/><br/> Field 4: <input type="text" class="sub" name="8" value=""/><br/><br/> Total Substraction: <br/><br/> Grand Total: <div id="total"></div> <input type="submit" value="submit" /> </form> </body> </html> create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! |