Jump to content

Search the Community

Showing results for tags 'php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. hi im trying to use query to select from a table where the price is between to values that the user has to input such as min of 3 and max of 8 and return all the fields from the database where it is true im unsure how to do this but this is what i have so far $res = pg_query ($conn, "SELECT ref,artist,composer,genre,title,album,label,price,description FROM music WHERE price = < && > "); echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>";
  2. when i input this code it only uploads a single column into my database <html> <head> <title>MySQL file upload example</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="try2.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" name="submit"value="Upload file"> </form> <p> <a href="list_files.php">See all files</a> </p> </body> <?php $con=mysqli_connect("localhost","root","","book"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } if(isset($_POST['submit'])) { $fname = $_FILES['uploaded_file']['name']; $chk_ext = explode(".",$fname); if(strtolower($chk_ext[1]) == "csv") { $filename = $_FILES['uploaded_file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into data(name,Groups,phone_number) values('$data[0]','$data[1]','$data[2]')"; $result=mysqli_query($con,$sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> </html>
  3. I have this script from http://lampload.com/component/option,com_jdownloads/Itemid,382/cid,69/task,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens http://www.jayg.co.uk/gallery6/upload_gallery.php <form> <?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form> any ideas please? thanks
  4. Hi, Im creating a simple site in PHP, for the most part its going well, however I struggling with an error that I have encountered. Im generating a random salt upon registering a user. This works fine, However when logging in with this user I am struggling and receive an error. Can somebody please explain where I am going wrong? I have attatched some images to this post which includes coding and the error message. NOTE: signup works fine, it is just the log-in which is broken. I have however included screenshots of both pages for better understanding of how the site works. Signup: http://picpaste.com/pics/SignUp-gZnFffux.1416827271.PNG Log-in: http://picpaste.com/pics/log-in-gB895EyW.1416827394.PNG Error Message: http://picpaste.com/pics/error-pic-JwV9iLp8.1416827510.PNG Kind Regards, Shaun
  5. Greetings and Salutations, Everyone! I like to play around with PHP. I started about a decade ago... All that time and you'd think I'd be a pro by now (not even close)! I was on my way to PHP & MySQL glory when life happened and I didn't code consistently or in a dedicated fashion for something like 8 years. This has left me shamefully beyond rusty. (New HTML & CSS has come around, too. I've recently gone through some refresher courses for those languages.) Anyway, I've decided to get back into it. I'm here because I'd like to re-learn and expand my knowledge of PHP. I'll probably ask a bunch of silly questions. I apologize in advance! cheers, echo
  6. I am trying call an R batch file inside php script from browser. The R script basically generate an imgae and save in a folder. Unfortunately, I could call the R within php (means that no image is saved in the folder) using BROWSER. But when I run the php script from the commadline, it works and image is saved in the folder. <?php exec("Rscript /var/www/html/phil/figs/map.R"); ?> Execuition of following R batch code and php codes work and save image in the specified folder from the terminal. 58A-UD3R:~$ php /var/www/html/phil/x.php 58A-UD3R:~$ Rscript /var/www/html/phil/figs/map.R I totally in confusion why browser cannot successfully save image. Or is there anythinng need to be change in server for generating image? Anyone please help me for solving this probelm. Thank You..
  7. I'm writing a program that allows users to input a stock and view a historical price chart. Code is straight out of libchart charting library. Problem is, user is supposed to enter the stock symbol from a form handler (index.php) which then passes the symbol as a variable to the charting function, which doesn't get called at all: <? php function index() { chart($_POST['userinput']}; } ?> . <?php function chart($stock) { $prices=getdata($stock); //returns array of prices from yahoo finance $data=analyzer($prices); //produces metrics to be charted graph($data); } ?> //plots the metrics, outputs .html chart.php works on its own, as I've verified by hardcoding $argv='ibm'; in its code body. But index.php can't seem to call chart.php, as I've verified by including an echo/var_dump line in chart.php (doesn't get executed at all). It doesn't have anything to do with form handling either, as chart('ibm'); doesn't call chart.php either. I don't understand how a 6-line piece of code can be so problematic. All files are in the same folder, btw. Thanks.
  8. <?php $xb = 4; //width $yb = 2; //length function rectangle($x, $y) { $a = $x * $y; return $a; } ?> <br/> Please enter the values of the length and width of your rectangle. <br/><br/> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Width: <input type="text" name="" id="" value="2"> <br/><br/> Length: <input type="text" name="" id="" value="4"> <br/><br/> <input type="submit" name="submit" value="submit"> </form> <?php echo $rectangle; ?> I need to output the answer 8 when a user click on submit
  9. I have searched for the solution for so long and I still could not solve my problem. I have a localhost server where it stored some pdf files for download. I implemented the following function to force the download: if(isset($_POST['dlPDF'])) { $file = $_SERVER['DOCUMENT_ROOT'] .'/Upload/'.$pdfName; header("Content-Type: application/pdf"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$pdfName"); header("Content-Transfer-Encoding: binary"); // read the file from disk readfile($file); } However I could not open the pdf file properly since it says "the pdf file is not correctly encoded". FYI, the downloaded pdf file is always a few Kb larger than the original file. Please kindly let me know if there is anything I can do to make the pdf readable and I appreciate your help.
  10. Hi, I have a .txt file with data in the following way: FRENEMY : a person with whom one is friendly despite a fundamental dislike or rivalry : There seems to be a frenemy relationship between John and Andrew. PORTMANTEAU : a word or morpheme whose form and meaning are derived from a blending of two or more distinct forms (as smog from smoke and fog) : Lewis Carroll's Jabberwocky is loaded with portmanteau words. The following is my PHP: <?php //Check your text file exits if (file_exists('interesting_words.txt')) { //Retrieve content of text file $content = file_get_contents('interesting_words.txt', true); //Add every line of file to array $lines = explode("\n", $content); //Cycle through all line in file $words = array(); foreach ($lines as $line) { //Split word and description by : list($word, $description, $example) = explode(':', $line); //Create a words array to hold word and description $words[] = array('word' => ucfirst(trim($word)), 'description' => ucfirst(trim($description)), 'example' => ucfirst(trim($example))); } //Generate random number from date //Remove to generate random word every page load srand(date("ymd")); //Use random number from 0 to the cound of words array to pick word of the day $word_of_the_day = $words[rand(0, (count($words) -1))]; //Use word, descriptionand example keys to print the results. echo '<span id="word">'.$word_of_the_day['word'] . '</span>'.'<br>'.'<br>'; echo '<span id="description">'.$word_of_the_day['description'].'</span>'.'<br>'.'<br>'; echo '<span id="example">'.$word_of_the_day['example'].'</span>'.'<br>'.'<br>'; } ?> I would like to have it displayed in the following way: FRENEMY a person with whom one is friendly despite a fundamental dislike or rivalry. BUTTON One would click the button to open a new popup window to show example sentences. My problem is how do I go about coding for the window part. All help appreciated. Many thanks
  11. I have a mysql field that I want to store a php variable in and then retrieve it. Example: Color table has the field named colorBackground with the value of #FF0000 CSS table has the field named cssBackground with the value of .background { background-color: #444444; } What I want to do is make Color/colorBackground a variable {{$backgroundcolor = rsColor['colorBackground'] Then I want to change the CSS/cssBackground value to .background { background-color:$backgroundcolor; } Creating the $backgroundcolor works fine. I'm just not sure how to put the $backgroundcolor in my CSS/cssBackground field.
  12. Hi Been trying to run a query to get all rows from a table between two dates, but nothing seems to work. $query = "SELECT * FROM table WHERE date BETWEEN '%2014-11-17%' AND '%2014-11-18%'"; Strange thing if I try a search instead a query in phpmyadmin I don't see an operator called 'BETWEEN' on the remote host, but I do on my localhost. Does this mean it will never work on the remote host? Nevertheless it doesn't work on either and I do have records for both dates in the table. phpmyadmin: Version 4.1.14 localhost (wamp) Version 3.3.7deb7 on remote server Thanks
  13. Is it possible to have a link at the top of a page that has been displayed from a database? Just that some results show thousands of rows. Thanks.
  14. i have checkbox in a table and want to put the value as the id in the database then when i press submit it displays all the row data for each checkbox $res = pg_query ($conn, "SELECT artist,composer,genre,title,album,label,price,description FROM music"); echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>"; while ($row = pg_fetch_row($res)) { echo "<tr>"; echo '<td><input type="checkbox" name="check_list[]" value="' . $row['res'] .'"></td>'; for ($column = 0; $column < pg_num_fields($res); $column++) { echo "<td>" . $row[$column] . "</td>"; } echo "</tr>"; } echo "</table>\n"; ________________________________________________-- basket.php echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>"; echo "<pre>\n"; print_r($_POST['check_list']); echo "</pre>\n";
  15. I am in the process of trying to create a pedigree website (php/mysql)... I want to be able to calculate a dog's inbreeding coefficient on 10 generations. I am so not sure where to even begin. I have a database table: dogs: Fields: id name sireid damid equation: FX = å [ (½) n1+n2+1 (1 + FA)] http://www.highflyer.supanet.com/coefficient.htm Can someone give me a starting point? Do I need to learn bianary trees? could I do this with an array? Thanks
  16. <body> <?php include 'sql.php'; $query = "SELECT * FROM validation"; $result = mysqli_query($con , $query); $rows = mysqli_fetch_assoc($result) ; $totals = mysqli_num_rows($result) ; ?> <div id="css"> <form > <table width="80%" border="0" cellpadding="2" cellspacing="2" > <caption><h2>Personal Details of Customers</h2></caption> <tr class="white"> <td bgcolor="#330033"> </td> <td bgcolor="#330033"> Id Number </td> <td bgcolor="#330033"> Full Name </td> <td bgcolor="#330033"> Email Address </td> <td bgcolor="#330033"> Website </td> <td bgcolor="#330033"> Comment </td> <td bgcolor="#330033"> Time </td> </tr> <?php while($rows=mysqli_fetch_assoc($result) { <tr> <input type="raido" name="ID" value="<?php echo $rows['ID']; ?>" /> <td bgcolor="#FFFFCC"><?php echo $rows['ID'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Name'];?> </td> <td bgcolor="#FFFFCC"><?php echo $rows['Email'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Website'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Comment'];?></td> <td bgcolor="#FFFFCC"><?php echo $rows['Time'];?></td> <td> </td> <td> <a href="delete.php? ID= "$rows[ID]" /"> <input type="submit" name="del" value="Delete" /> </a> <input type="button" name= "edit" value="Edit" /> </td> </tr> } ?> </table> </form> </div> </body>
  17. I am creating a website for university coursework. <input name="submit" type="submit" class="submit_btn float_l" id="submit" formaction="add-contactme.php" value="Send" /> The above code is from my html for contact.html if that is correct. I am using a form and then a submit button. I keep getting Notice: Undefined index: name in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 11 Notice: Undefined index: email in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 12 Notice: Undefined index: phoneno in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 13 Notice: Undefined index: comments in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 14 Also if anyone could help me I would like to create a delete button after a person has added the values into the sql table, basically to the last row inputted into the database. I want to avoid using delete from contactme where name ='chris'; $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="contactme"; // Table name mysql_connect ("$host", "$username", "$password") or die ("cannot connect server "); mysql_select_db ("$db_name") or die ("cannot select DB"); $name = $_POST["name"]; $email = $_POST["email"]; $phoneno = $_POST["phoneno"]; $comments = $_POST["comments"]; $sql="INSERT INTO $tbl_name VALUES ('$name', '$email', '$phoneno''$comments')"; $result=mysql_query($sql); if($result){ echo "Successful" . " "; echo "view-contactme.php"; // link to view contact me page } mysql_close(); ?>
  18. Hi there, I have this conversion program I am trying to make. Basically I have one file called 'index.html' and another called 'convert.php', the basic function of this program is to show a form in the html page and then get the calculation from the php form and then show the result back on the html page. The html page uses a dropdown list of different conversions the user can select from. Below is the code I've got. Please can you help with fixing this thing! It's really annoying me! :@ HTML CODE: <HTML> <HEAD> <title>Unit Converter</title> </HEAD> <BODY> <h1>CONVERSION</h1> <form action="convert.php" method="post"> <link rel="StyleSheet" media="screen" href="convert.css"> Type of conversion: <br> <select name="conversionType"> <option value="null" selected="selected">Select type...</option> <option value="null"></option> <option value="null">--Temperature--</option> <option value="C-F">Celsius to Fahrenheit</option> <option value="C-K">Celsius to Kelvin</option> <option value="C-R">Celsius to Rankine</option> <option value="K-C">Kelvin to Celsius</option> <option value="K-F">Kelvin to Fahrenheit</option> <option value="K-R">Kelvin to Rankine</option> <option value="F-C">Fahrenheit to Celsius</option> <option value="F-K">Fahrenheit to Kelvin</option> <option value="F-R">Fahrenheit to Rankine</option> <option value="R-C">Rankine to Celsius</option> <option value="R-K">Rankine to Kelvin</option> <option value="R-F">Rankine to Fahrenheit</option> </select> <br><br> Value to convert:<br> <input type="text" name="conversionInput"> <br><br> <input type="submit" value="Convert"> </form> </BODY> </HTML> PHP CODE: <HTML> <title>Conversion Output</title> </HTML> <?php $conversionType = $_POST['conversionType']; $conversionInput = $_POST['conversionInput']; $conversionValue; $conversionFrom; $conversionTo; if ($conversionType == 'C-F') { $conversionValue = $conversionInput * (5/9) + 32; $conversionFrom = "° Celsius"; $conversionTo = "° Fahrenheit"; } if ($conversionType == 'C-K') { $conversionValue = $conversionInput + 273.15; $conversionFrom = "° Celsius"; $conversionTo = "° Kelvin"; } if ($conversionType == 'C-R') { $conversionValue = ($conversionInput + 273.15) * (9/5); $conversionFrom = "° Celsius"; $conversionTo = "° Rankine"; } if ($conversionType == 'K-C') { $conversionValue = $conversionInput - 273.15; $conversionFrom = "° Kelvin"; $conversionTo = "° Celsius"; } if ($conversionType == 'K-F') { $conversionValue = $conversionInput * (9/5) - 459.67 ; $conversionFrom = "° Kelvin"; $conversionTo = "° Fahrenheit"; } if ($conversionType == 'K-R') { $conversionValue = $conversionInput * (9/5); $conversionFrom = "° Kelvin"; $conversionTo = "° Rankine"; } if ($conversionType == 'F-C') { $conversionValue = ($conversionInput - 32) * (5/9) ; $conversionFrom = "° Fahrenheit"; $conversionTo = "° Celsius"; } if ($conversionType == 'F-K') { $conversionValue = ($conversionInput + 459.67) * (5/9); $conversionFrom = "° Fahrenheit"; $conversionTo = "° Kelvin"; } if ($conversionType == 'F-R') { $conversionValue = $conversionInput + 459.67; $conversionFrom = "° Fahrenheit"; $conversionTo = "° Rankine"; } if ($conversionType == 'R-C') { $conversionValue = ($conversionInput + 491.67) * (5/9); $conversionFrom = "° Rankine"; $conversionTo = "° Celsius"; } if ($conversionType == 'R-K') { $conversionValue = $conversionInput * (5/9); $conversionFrom = "° Rankine"; $conversionTo = "° Kelvin"; } if ($conversionType == 'R-F') { $conversionValue = $conversionInput - 459.67; $conversionFrom = "° Rankine"; $conversionTo = "° Fahrenheit"; } echo "$conversionInput $conversionFrom = $conversionValue $conversionTo"; ?>
  19. so i have my database form which you can select a some data using the checkbox and when submitting it should get the row info and display it on the next page iv been struggling for days on this and cant work out how to do it please could i have some help <form name="test" method="post" action="shoppingbasket.php" > <input type="submit" value="Submit" > <?php $conn = pg_connect("host=db.dcs.aber.ac.uk port=5432 dbname=teaching user=csguest password=r3p41r3d"); $res = pg_query ($conn, "SELECT artist,composer,genre,title,album,label,price,description FROM music"); echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>"; while ($row = pg_fetch_row($res)) { echo "<tr>"; echo '<td><input type="checkbox" name="check_list[]" value="' . $row['ref'] . $row['artist'] . '"></td>'; for ($column = 0; $column < pg_num_fields($res); $column++) { echo "<td>" . $row[$column] . "</td>"; } echo "</tr>"; } echo "</table>\n"; ___________________________________________________________________________________________________ shopping basket.php <?php echo "<table border='1'>"; echo "<tr><th>Select</th><th>Artist</th><th>Composer</th><th>Genre</th><th>Title</th><th>Album</th><th>Label</th><th>Price</th><th>Description</th></tr>"; if(!empty($_POST['check_list'])){ foreach($_POST['check_list'] as $row){ echo "$row was checked! "; } } ?> </form> </body> </html>
  20. In my shopping cart i want an alert message when the maximum number of 5 for the item has been reached or ask them to delete the item if the press - when the item quantity is at 1. i have it working in php: //add to quantity of item if (isset($_POST['itemadd'])){ $additem = $_POST['additem']; $sqladd = "SELECT quantity FROM orders WHERE id = '$additem'"; $query_add = mysqli_query($db_conx, $sqladd); while($row = mysqli_fetch_array($query_add, MYSQLI_ASSOC)){ $itemqty = $row['quantity']; if ($itemqty < 5){ $addqty = $itemqty + 1; $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'"; $add_query = mysqli_query($db_conx, $adding); header('Location: http://www.quichlicious.co.uk/cart.php'); //print $additem; exit(); } else { $usemes = "You have reached maximum quantity"; } } But rather than display the message in a div i would like a javascript alert box to pop up, i tried the following code: <script type="text/javascript"> function CheckQtyPlus(){ var qty = '<?php echo $qty; ?>'; alert("message here"+qty); } </script> but i get the same quantity number for every item in the cart, i had this error with the php update but i got round that by querying sql to give me the quantity of an item by the items id. can the same thing be done in javascript / ajax? $qty by the way is referenced earlier in the script to get information for the cart table to display items. thanks Michael
  21. Hi Members, I am search for the reason for the problem why my mysql query cannot fetch data and store in file based on id in $variable form. For example, $sql="SELECT * FROM mytable WHERE mine_id='1234'"; works for me. But when i use $sql="SELECT * FROM mytable WHERE mine_id='$id'";, files are created as empty. I chanaged the quotes and could not store the data in file. So anyone please help me. For more clear, i attach the part of my code for ($i=0;$i<=10;$i++) { $id=$seqs[$i]; $dbo = new PDO($dbc, $user, $pass); echo $sql = "SELECT * FROM mine_id WHERE locus_id='$id'"; $qry = $dbo->prepare($sql); $qry->execute(); $data = fopen('file.csv', 'w'); while ($row = $qry->fetch(PDO::FETCH_ASSOC)) { fputcsv($data, $row); } }
  22. I have setup a website that has a shopping basket and it displays the objects ordered in a table before being purchased, i have added a plus and minus button to adjust the quantity using the following code: $add ="<form action='cart.php' method='post'><input type='hidden' name='additem' value='$id'/><input type='submit' name='itemadd' onclick='CheckQty()' value='+'/></form>"; $sub ="<form name='sub' action='cart.php' method='post'><input type='hidden' name='subitem' value='$id'/><input type='submit' name='itemsub' value='-'/></form>"; //add to quantity of item if (isset($_POST['itemadd'])){ $additem = $_POST['additem']; if ($qty < 5){ $addqty = $qty + 1; $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'"; $add_query = mysqli_query($db_conx, $adding); header('Location: http://www.quichlicious.co.uk/cart.php'); //print $additem; exit(); } else { $usemes = "You have reached maximum quantity"; } } //subtract to quantity of item if (isset($_POST['itemsub']) && ($_POST['itemsub'] !="")){ $subitem = $_POST['subitem']; if ($qty > 1){ $subqty = $qty - 1; $subing = "UPDATE orders SET quantity = '$subqty' WHERE id = '$subitem'"; $sub_query = mysqli_query($db_conx, $subing); header("location: cart.php"); exit(); } else { $usemes = "<font color='red'>Please use delete to remove item</font>"; } } The issue i have is it works great if just one item is in the basket but if i have more than 1 item in the basket i can only adjust the very last item in the baskets quantity and the others just randomly jump numbers or will not change at all? $additem gets the item ID from the table.
  23. I manage to display data using below query that will show value for each month. How to calculate average value starting july onwards(based on user selection). Let say the value for element 'A' are Jul=80, Aug= 80, Sep=90. If user select Aug then the average is 80 and if user select Sep then the average is 83. Query: $sql2 = "Select element, SUM(CASE WHEN Month = 'Jan' THEN total ELSE 0 END ) AS Jan, SUM(CASE WHEN Month = 'Feb' THEN total ELSE 0 END ) AS Feb, SUM(CASE WHEN Month = 'Mac' THEN total ELSE 0 END ) AS Mac, SUM(CASE WHEN Month = 'Apr' THEN total ELSE 0 END ) AS Apr, SUM(CASE WHEN Month = 'May' THEN total ELSE 0 END ) AS May, SUM(CASE WHEN Month = 'Jun' THEN total ELSE 0 END ) AS Jun, SUM(CASE WHEN Month = 'Jul' THEN total ELSE 0 END ) AS Jul, SUM(CASE WHEN Month = 'Aug' THEN total ELSE 0 END ) AS Aug, SUM(CASE WHEN Month = 'Sep' THEN total ELSE 0 END ) AS Sep, SUM(CASE WHEN Month = 'Oct' THEN total ELSE 0 END ) AS Oct, SUM(CASE WHEN Month = 'Nov' THEN total ELSE 0 END ) AS Nov, SUM(CASE WHEN Month = 'Dec' THEN total ELSE 0 END ) AS Dis FROM tbl_ma GROUP BY element"; $rs2 = mysql_query($sql2); $getRec2 = mysql_fetch_assoc($rs2); Below is how print the data: <?php while ($row = mysql_fetch_assoc($rs2)) { ?> <tr> <td style="color:black;background-color:#f5efef"><div align="left"><?php echo $row['element']; ?></div></td> <?php if( $year != '2014' ){ ?> <?php if( 1 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jan']; ?></div></td><?php endif; ?> <?php if( 2 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Feb']; ?></div></td><?php endif; ?> <?php if( 3 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Mac']; ?></div></td><?php endif; ?> <?php if( 4 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Apr']; ?></div></td><?php endif; ?> <?php if( 5 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['May']; ?></div></td><?php endif; ?> <?php if( 6 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jun']; ?></div></td><?php endif; ?> <?php } ?> <?php if( 7 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Jul']; ?></div></td><?php endif; ?> <?php if( 8 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Aug']; ?></div></td><?php endif; ?> <?php if( 9 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Sep']; ?></div></td><?php endif; ?> <?php if( 10 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Oct']; ?></div></td><?php endif; ?> <?php if( 11 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Nov']; ?></div></td><?php endif; ?> <?php if( 12 <= $monthID ): ?><td><div align="center" style="color:black"><?php echo $row['Dis']; ?></div></td><?php endif; ?> <td><div align="center" style="color:black"><?php //echo average; ?></div></td> </tr> <?php } ?>
  24. Say you have a string that you know has two, and exactly two, periods in it, like this... $string = "3.12.8" How can you grab the three different values that are separated by periods (in this case, 3, 12 and ? I was thinking use strpos to find the position of the first period, then could use that info to grab everything up to that position. But then I couldn't figure out how you would find the position of the SECOND period. And even if I could get the exact positions of the two periods, it seems like there should be an easier way to simply retrieve values separated by specific characters. Is there a specific function for this type of thing, or was my initial though correct with having to do it in two parts essentially (find positions of periods, then use that knowledge to get the values)? Thanks!
  25. In HTML5 some attributes are no longer supported eg: name attr for <a> is no longer supported. What happens when in a tag like <a> exists a non supported attr? <a id="me" name="you"> Will it just be ignored like is not there or it can cause problems later on and how?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.