PHP - Running Balance Using An Array Mysql
Similar TutorialsHi i was wondering what im doing wrong, im trying to insert a query for submit button, it works if i run it straight in mysql, but not working when linked through php. Im just doing it for testing purpose right now only, so when i see that it works i will use another query. here it is Code: [Select] <?php include('config.php'); if($_SESSION['username']){ if(isset($_POST['ASubmit'])){ $query3=("update country set Status='test1' where Uname='Mclovin'");} echo '<td><form name="test" method="post" form id="form1"><label for="test">Status</label> <select name="Status"> <option value="">-----</option> <option value="In process" '.(($row['Status']=='In process')?'selected="selected"':'').'>In process</option> <option value="Approved" '.(($row['Status']=='Approved')?'selected="selected"':'').'>Approved</option> <option value="Denied" '.(($row['Status']=='Denied')?'selected="selected"':'').'>Denied</option> </select><input name="ASubmit" type="submit" value="Update">'; echo $row{'Status'}.'</td></form>'; } ?> Hey, I am a bit of a noob at php/mysql and trying to be clever(emphasis on trying). I want to pull some php/html code from a database in mysql, whilst it does display the html, the php does not. Can this even be done? Is it going to cause me issues later on? Code: [Select] [php] <?php $query = "SELECT * FROM pages"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)){ $body = $row["body"]; echo $body; }?> [/php] Any help would really be appreciated. Ell My my.cnf file has three sections (mysqld, mysqld_safe, mysql). It seems that they represent different modes which MySQL runs in. Is this correct? I read that some recommend running in safe mode. Should I be if it is being used to support PHP? I typically start MySQL as "service mysqld start" when running Centos. How should I be starting it if I want it in safe mode. I am trying to create a calendar of Events for my company's website. When I search for this type of calendar, I can find code that runs the calendar from one Events table. However, we could have an Event that has multiple performances. (For example, Lily Tomlin could be performing at the Atwood Concert Hall in Anchorage on 09/09/11 and at the Vagabond Blues in Palmer on 09/10/11.) So we have two tables to draw the information from: Events and Performance I can successfully create a MySQL query (see below) with PHP coding that will make a listing (as demostrated on our website http://www.centertix.net/). Code: [Select] "SELECT Events.PublishDate, Events.EventOnSaleDate, Events.BldgContractDate, Events.SetUpComplete, Events.EventTitle, Performance.PerfID, Performance.startDateTime, Performance.endDateTime, Performance.PerfType, venues.VenueName, venues.VenueCode FROM (Performance RIGHT JOIN Events ON Performance.EventID = Events.EventID) LEFT JOIN venues ON Performance.VenueCode = venues.VenueCode WHERE Events.BldgContractDate Is Not Null AND Events.SetUpComplete Is Not Null AND Performance.PerfType='Public Event'"However, I'm not advanced enough to create the if-clause or while-loop to check to see if the Performance.startDate = the calendar's date and then place the info into the appropriate calendar grid box. I think have determined where it should be place in my PHP code, but need help getting the calendar to work. Here's the code where I think it should go: Code: [Select] for($list_day = 1; $list_day <= $days_in_month; $list_day++): if(($list_day == date("j",mktime(0,0,0,$this->month))) && (date("F") == date("F",mktime(0,0,0,$this->month))) && (date("Y") == date("Y",mktime(0,0,0,$this->month,$list_day,$this->year)))) { $this->calendar.= '<td class="'. $this->style .'-current-day">'; } else { if(($running_day == "0") || ($running_day == "6")) { $this->calendar.= '<td class="'. $this->style .'-weekend-day">'; } else { $this->calendar.= '<td class="'. $this->style .'-day">'; } } /* add in the day number */ $this->calendar.= '<div class="'. $this->style .'-day-number">'.$list_day.'</div>'; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $this->calendar.= '<div class="'. $this->style .'-text"><a href="">PERFORMANCE INFO</a></div>'. "\n"; /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF NO MATCHES FOUND, PRINT NOTHING !! **/ $this->calendar.= str_repeat('<p> </p>',2); $this->calendar.= '</td>'; if($running_day == 6): $this->calendar.= '</tr>'; if(($day_counter+1) != $days_in_month): $this->calendar.= '<tr class="'. $this->style .'-row">'; endif; $running_day = -1; $days_in_this_week = 0; endif; $days_in_this_week++; $running_day++; $day_counter++; endfor; Please help me plug the calendar in with the appropriate events! If you would like to see how far I have gotten, you can check out this link: http://www.myalaskacenter.com/calendars/calendarSample2.php Hi All, I have a form that enables the user to know events that occur in a specific city. Most of the time they get the results in a few seconds, despite the fact that many rows in various tables might be searched for detailed infos about the events in that city. However, this form partly relies on a table against which a MySQL event regularly does some operations. If the user uses the form while the event is being executed, they have to wait up to 30 seconds before getting the results, and sometimes only part of the html page is generated. Is there a way to avoid this lengthy waiting time ? I am wondering whether or not the best would be putting the site on maintenance while the event is being executed, with a "please come back in a few minutes" message. Thanks in advance for your help. I am creating a site to display some products. For ease of updating I want it to run off a MySQL database. I have created the database and php scripts to output and input data etc. I know want to show that data in my web pages. My question is.... Is it best to insert HTML into the php output script to display the information and make the site look how I want....OR ....... should I create a template of the site in HTML and then somehow call the php output script (and the particular row of the database...) Basically... should I put the html code into the php - OR - put the php into the HTML?? I hope this make sense...... thanks I have a custom finance management site and within it I can see amount owed paid and total account balance. I have a table called `Transactions` with 8 fields ID - unique post ID UID - User ID name - Name of the person or business amount - amount of the transaction, in the format of -100.00 or +100.00 date category comment delete - default 0 What I want is to check every unique name and add up the totals and if it totals up to a negative send out a email. I already have a PHP script for the user to see this list, I just want to know if there is some way possible to automate this weekly via cron job. Is it possible? Thanks in advanced! Hello, Im making a little script to keep track on how much people have currently earnt on my site. I have everything work but i can't figure out how to work out the current balance At the moment ive got: Code: [Select] $currentbalance = $row['totalpaid'] - $row['points']; Which works untill the points becomes more then the total paid then it starts going in minus. Im sure there's a simple fix but i just can't think of a way. Any help would be great. Thanks I am using a php web video script which allows Users to purchase videos successfully. The purchases are made from the amount available in the Users’ “wallet” (the User can also earn compensation, which gets added to his “balance”.). When there’s not enough available in the “wallet” for the purchase, the script checks and displays a message “not enough money”. I’d like help adding the ability where the script first checks the “wallet” amount, and if empty will then check the “balance” amount, and use a required amount from the balance, and if both are empty, then the “not enough money” appears. Here’s the portion of the code that I believe needs the modification: // get cost video $db->where('name', 'video_play_price'); $db_cost = $db->getOne('config'); $video_cost = (float)$db_cost->value; $count_video = count($id_array); $user_id = $user->id; $wallet = (float)str_replace(',', '', $user->wallet); $amout = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); $amout += $video->video_play_price?$video->video_play_price:$video_cost; } // $amout = $video_cost * $count_video; $charge = ( $video_cost *0.50 ); if ($wallet >= $amout) { //$new_wallet = (string)($wallet - $amout); $wallet = (string)($wallet - $amout); $db->startTransaction(); $inserted_records = 0; foreach ($id_array as $id) { $video_id = (int)PT_Secure($id); // $uploader_amount = $video_cost - $charge; //100 - 20% = 80 // get video data $video = $db->where('id', $id)->getOne(T_VIDEOS); $video_cost_new = $video->video_play_price?$video->video_play_price:$video_cost; $uploader_amount = ( $video_cost_new *0.50 ); // add data to paid table $insert_buy = $db->insert('u_paid_videos', [ 'id_user' => $user_id, 'id_video' => $video_id, 'session_key' => $_SESSION['session_key'], 'video_play_price' => (string)$video_cost, 'video_title' => $video->title, 'user_id_uploaded' => $video->user_id, ]); if ($insert_buy) { $inserted_records++; } //add wallet users' video $userwallet = $db->where('id', $video->user_id)->getOne(T_USERS); //$videouserwallet = $userwallet->balance+$video_cost; $videouserwallet = $userwallet->balance+$uploader_amount; $db->where('id', $video->user_id); $update_balance = $db->update(T_USERS, [ // 'wallet' => $videouserwallet, 'balance' => number_format($videouserwallet, 1, '.', ''), ]); } $db->where('id', $user_id); //$update_wallet = $db->update(T_USERS, [ $update_wallet = $db->update(T_USERS, [ 'wallet' => $wallet, ]); if (($inserted_records == $count_video) && $update_wallet) { $db->commit(); echo json_encode([ 'status' => 200 ]); exit(); } else { $db->rollback(); echo json_encode([ 'status' => 400, 'error' => 'Buy process error' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error_num' => 1, 'error' => 'Not enough money' ]); exit(); } } else { echo json_encode([ 'status' => 400, 'error' => 'Bad Request, Invalid or missing parameter' ]); exit();
I am trying to generate data similar to a running balance for a checkbook. My approach (correct me if there is a better method) is to get the balance from the previous record ID and then add/subtract the new value and create a new total balance. However, I am not havig succes with MAX(id) or last_insert_id -- is one preferable over the other?? if($result = mysqli_query($link, $sql)){ if(mysqli_num_rows($result) > 0){ $sql = "SELECT MAX(id) FROM persons"; echo "<br /<br />"; echo $sql; Please assist. hello I am a chemical teacher in the middle school I hope Balancing Chemical Equations via PHP I google some thing perhaps the CML( http://en.wikipedia.org/wiki/Chemical_Markup_Language) may give me a hand. and this one the http://shinkirou.org/blog/2010/11/balancing-chemical-equations-with-linear-algebra/ tells me using the Linear Algebra is a good way how can I Balancing Chemical Equations via PHP( by CML )? is their a demo ? thank you very much~! Hi friends, I am creating a site where users can add credit to their account via Liberty Reserve, and after that their account will automatically be updated with the amount they added so that they can use it to purchase products.. And after any purchase, the amount will be subtracted from their account.. I cant really find a php code to do that... i have done a search on here but still cant find anything close to it.. Can someone kindly help? Thank you Does anybody have links or scripst on a script where the user has an account with money which decreases as one purchases items. Regards Hello,
I designed (not coded) a finance application for windows phone 8.1 and one of the features that would be ideal is to copy your login steps in order to access your bank account automatically. Yes this does not sound safe or sane. How do I convince app users to use it?
Anyway, I want this access. My rationale is that, the login information would be stored locally and if my phone was hacked then what's the loss in my login steps being hacked... they would probably be encrypted anyway but...
The goal is to be able to open up a clone browser (eg. within the app) and then every step that you take, enter url, login credentials, security questions, pages accessed... the clone browser remembers and then later on as part of the app's function, it would automatically update your balances. I mean I suppose you could come up with the formulas, cash advance fees, interest rates, etc... but at the same time this doesn't seem to be a fixed thing... eg. hard to keep track and get the exact cent amount... or maybe I'm just bad at math
Some things in mind bitmapping, key strokes, string search, number search...
Anyway scripting came to mind, not sure if php or python but
Any thoughts?
How can i save array from inputs, witch is $igraci and it have 5 values, to mysql base, i tryed but in mysql it shows Array. This is form: <form action="dodaj_klan.php" method="post" > <p> <label>Naziv klana:</label> <input name="naziv" type="text" size="20%" /> <label>Web Sajt:</label> <input name="website" type="text" size="20%" /> <label>E-Mail:</label> <input name="email" type="text" size="20%" /> <br /><br /> <label>Igraci klana(5):</label> <input name="lider" type="radio" value="1" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="2" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="3" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="4" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="5" /> <input name="igraci[]" type="text" size="20%" /> <label><i>(obelezi lidera klana)</i></label> <br /><br /> <input class="button" type="submit" name="submit" value="Dodaj" /> </p> </form> Now i wonna save this igraci[] array in mysql, i tried like this but it doesn't work: $igraci = $_POST['igraci']; $query = "INSERT INTO klanovi (naziv, website, email, igraci) VALUES ('{$naziv}', '{$website}', '{$email}', '{$igraci}')"; $result = mysql_query($query, $connection); How can i do this? Thanks.. So I'm querying my database to add the results (mapID's) into a PHP array. The MySQL query I used in the below code would usually return 10 values (only 10 mapID's in the database) Code: [Select] while($data = mysql_fetch_array(mysql_query("SELECT mapID FROM maps"))){ $sqlsearchdata[] = $data['mapID']; } Instead the page takes ages to load then gives this error: Quote Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes) It says the error begins on the first line of the above code. I'm assuming this is not the right way to add the value from the MySQL array into a normal PHP array. Can anyone help me? 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) My current code lists between 1-6 results from a MySQL array. How do I extract the data from the list and put it into its own variable (eg: $result1, $result2 etc.) ? Code: [Select] $ran_x = rand(1,6); $ran_x = rand(1,6); $x_query = "SELECT * FROM `x` ORDER BY RAND( ) LIMIT $ran_x"; $get_x = mysql_query($appearance_query); echo 'x(s): '; echo '<br />'; while($row = mysql_fetch_array($get_x)) { echo $row['Appearance']; } Any help would be great, Thanks, otester My language table structure looks like : id | english mail_accepted | Your e-mail is accepted. thank_you | Thank you for your visit. What I want to do is, I want to take all these data to an array like : "lang" array And I can use these in the page like Code: [Select] <?php echo "goodbye ".$lang['thank_you']; ?> I know how to take data, lets say Code: [Select] <?php $query = "select * from language.. "; mysql_query($query); ?>But then ?, which function should I use to take the data to my "$lang" array ? firstly i am quite rusty at php/sql so sorry in advance. I have a php script to produce graphs with the GD library, alls working well, but I want to modify it so the data comes from my database. so I connect to the database in the usuall way but the script uses an array $values = array("23","32","35","57","12","3","36","54","32","15","43","24","30"); so I need mysql to out put in the same format This is what I have so far, it prints out the data with some formating, thank you for any help you can offer Gary Code: [Select] // Make a MySQL Connection $query = "SELECT Question, COUNT(Answer) FROM question1 GROUP BY Question"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo "There are ". $row['COUNT(Answer)'] ." ". $row['Question'] ." items."; } |