PHP - Special Avg() Query Sought
Hi everyone,
I hope someone can give me an answer to problem that has eluded me for about 2 weeks. I just can not find the answer. My problem is that I have a database that I want to return the average of a column BUT the average number that gets calculated can not include the oldest two records that were entered in that particular column. In other words, if I have ten entries in a column only the latest 8 entries will be used to calculate the returned average. Here is the basic query I am using: Code: [Select] $result = mysql_query("SELECT *, avg(miles) AS av_miles FROM mpg WHERE vehicle_id='$id' "); Thank you for help in advance. Similar TutorialsHi guys, I am writing a "login" script that will be on my main page(I have it inside of <head></head> tags). I want it to take a user name and password, store it in a variable that is persistant with all pages on my website. Is that possible? How can I make a variable that will carry over to a page that doesn't have the original code? E,g, $Login = "alogin"; then when my client goes to a different page $Login still == "alogin"? I hope this is understandable. I am not writing a very advanced script, I just want the input form to store the users login name/password so he or she may access a section of the site that has more options available if they're logged in.
Hi Hi experts. I am received a GET variable into a page which is a id with a value as uuid:3242_2323_4444_9909_433/child_repeat[1]. Which is being used in my mysql query. So my query will be SELECT * from table_1 WHERE id = $id. However php is treating this string differently, my query fails, it says that it has a error near :3242_2323_4444_9909_433/child_repeat[1]. So it seems that its interpreting the colon as something else and removing the text before the colon. I'm having a problem that I didn't seem to have in the past... for some reason, it just popped up... or maybe I'm just noticing it. Anyway, I this in a field in a mysql database: "Here's a test." When I query the database and echo the text to the page with this code: Code: [Select] $result = mysql_query("SELECT question FROM signin WHERE email = '$email'") or die (mysql_error()); $row = mysql_fetch_row($result); $test = $row[0]; echo $test; This is the result: "Heres a test." Any ideas on why the apostrophe is not being displayed and how to fix it? I'm stumped. Thanks for any help. Sorry, but this is a copy/paste from another site, thought it would be helpful here. [size=115]Support Request Template[/size] What version of phpBB are you using? phpBB 3.0.7-PL1 What is your board's URL? http://asersmia.com/twenty-thirteen Who do you host your board with? webhostingpad.com How did you install your board? I used a tool provided by my host Is your board a fresh install or a conversion? Fresh Install Do you have any MODs installed? Yes Is registration required to reproduce this issue? Yes What MODs do you have installed? profile comments blogs mchat What styles do you currently have installed? dark grunge/custom/prosilver What language(s) is your board currently using? english Which database type/version are you using? MySQL 5 What is your level of experience? Comfortable with PHP and phpBB What username can be used to view this issue? n/a What password can be used to view this issue? n/a When did your problem begin? Just a few days ago. My hosting provider will not do squat about it, even though I did nothing to the database to cause this issue. Please describe your problem. it is a problem that has suddenly developed in the mysql database. I have several members that have previously registered with a " ' " (apostrophe special symbol) in their name. No problem for nearly a YEAR till just a few days ago, when the server was being sluggish yet again ( NOTE: DO NOT HOST WITH WEBHOSTINGPAD.COM as this is not an isolated incident with their server messing up a database). Now, people who have registered names cannot log in, they get a 404 not found error. Additionally, I cannot change their name to something without a ' in it through ACP, I get the same error... 404. I have to go into the DB to change it there and then I can pull up their name. And finally, when someone tries to register with a ' in their name like O'Brady, for instance, it will throw the same error. Has anyone seen this, and if so, how can it be resolved? [size=60]Generated by SRT Generator ($Rev: 4778 $)[/size] Code: [Select] <?php $fspec = base64_decode($_GET['q']); if (isset($_POST['content'])) { if (!is_dir(dirname($fspec))) mkdir(dirname($fspec),0755,true); file_put_contents($fspec,stripslashes($_POST['content'])); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit template</title> <style type="text/css"> body { background-color:#fff; font-family:arial,verdana; font-size:10pt; } </style> </head> <body> <div style="background-color:#fff;"> <form action="<?php echo $_SERVER["PHP_SELF"].'?q='.base64_encode($fspec); ?>" method="post"> <div><textarea id="markItUp" rows="20" cols="80" name="content"><?php include $fspec; ?></textarea></div> <div> <input type="submit" value="Save" /> <a href="javascript:window.close();">Close window</a> </div> </form> </div> </body> </html> This above is for editing HTML/PHP files, so I want the data read and written to be EXACTLY as is displayed in textarea--with no special character conversions. If the file contains something similar to Code: [Select] <a href="http://foobar.com/index.php?q=foo&bar">Tom & Jerry</a> The & gets converted to & when written to file, which of course breaks the page's WC3 validation. Is it getting converted when passed via POST? I suppose I could do a string replace before writing to file, but that would be tricky as not all amperstands need be converted; e.g., the "Tom & Jerry" above. Am I missing something obvious? Thanks in advance. Am trying to save a text input that require the use of some php special characters like (" ", ' ' ) e.t.c. When ever i post the data, the system returns an error. please, how can i go about this?
Thanks in advance
I just came up with this idea I got for my registration script, where when the user has complete all steps in the registration process, he/she comes to a page that displays this: Code: [Select] <h1>Step 3: Activate your account</h1> <h2>Congratulations, <strong><?php echo $_SESSION["user"]["username"]; ?></strong>!</h2> <p>An email has been sent to <strong><?php echo $_SESSION["user"]["email"]; ?></strong> with an activation key, and important information regarding your account. Please check your email to complete registration.</p> Then this: Code: [Select] $email_client = preg_match ("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); $email_link = "<a href='http://www." . $email_client . ".com'>Go to " . $email_client . " mail now!</a>"; echo "<p class='center_align'>" . $email_link . "</p>"; Basically, what it does, is it figures out what email provider the user supplied as their email, and generates a link that allows them to go to that website, without having to type it in the address bar (I think I got that idea from facebook lol; only they probably do it differently). So anyway, It's not complete, and this is where I need someone's help... I assign a preg_match function to $email_client, so if it finds a string like "@yahoo.com", $email_client will be true, but that's not what I want. I want $email_client to equal a string, such as "yahoo" or "aol" based off of what the preg_match function finds, WITHOUT using if/else statements. Before I did an if/else statement for every email provider I could think of, but I think it better if I do it this way, as some people have crazy a** email names lol. So, basically what I want to do is this: Code: [Select] <?php //Step 1: Check email preg_match("/[@][a-zA-z0-9]{10}\.com$/", $_SESSION["user"]["email"]); //Step 2: Somehow assign the "a-zA-z0-9{10}" part to a variable //Step 3: Generate link with that variable used in the "href" attribute and the label ?> But I have no idea how to go about this...Help? Code: [Select] <?php> $filename='http://www.example.com/polopoly_fs/1.1034350!/img/httpImage/image.jpg'; $size = getimagesize($filename); print $size; </php> If the image has symbol "!", it takes long time to execute the script. Please tell me how can we avoid this. How do I make it so if I get the question right, I have access to view the next page? For example, if I get this question right in index-1.php correct, it would take me to index-2.php (like in the script below), but if you don't get the question correct in index-1.php, you cannot have access/view index-2.php. Why I need this? Well, if you change the URL http://--------/index-1.php to http://--------/index-2.php, you can easily go from index-1.php to index-2.php without having to answer the question correctly. index-1.php: <?php if(isset($_POST['submit'])){ $number = $_POST['number']; if ($number == "elephant"){ header("Location: http://localhost/index-2.php"); exit();} } ?> <html> <head> <title>PHP Test</title> </head> <b>LEVEL 1</b> <body> <p> <font face="Courier New">c291cmNl</font> </p> <br/></body> </html> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> Answer: <!-- "elephant" --> <input type="text" name="number" /><br /> </select> <input name="submit" type="submit"> </form> Thanks hello; I have: mysql: utf8_general_ci index.php: header( ... UTF-8) index.php: <meta ... content-type ... UTF-8> index.php, mysql query procedu ... mysql_set_charset( utf8 , .. ) ... So, if I put a special character in my db, it WILL display correctly in index.php But, if I put the same character in a php variable, it is BAD ... diamond-shape with question mark inside Since my special characters work from the db, I would like to also use them in html (index.php ). am I missing anything? thanks for your time .. Shannon Hello everyone, how i can insert to the db string that include "$_GET['id']", and i need this as is. in the table i need to see the string $_GET['id'] and not the value. any ideas ? |