PHP - Pulling Information From File
Hi Everyone,
Let me start by saying i need any help put to me in dumb person terms, i know nothing but the bare bare basics of most web coding let alone php, enough to make very simple pages and forms. On to my problem... What i am aiming for us a single web page which takes a list of names from a file, generates a 2 column table, makes the second column into boxes where data can be entered in to, then i want it to be submitted to email in the form of a html email, the email doesn't need any fancy formatting or colour scheme, just want the the table of names and entered information sent Now this is how far i have got (with help obviously): Code: [Select] <body> <h1 align="center"><u>7B Praise Points</u></h1> <div id="contact-wrapper"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <?php $file = file("7B.txt"); $count = 0; print "<table cellspacing='2'>\n <tr><td>Student Name</td><td>Number of Praise Points</td></tr>\n"; foreach($file as $line){ $line = trim($line); $split = split("\t",$line); print "<tr>\n<td>$split[0]<input name='name$count' type='hidden' value='$split[0]'></td>\n<td>$split[1]<input name='points$count' type='hidden' value='$split[1]'></td>\n</tr>"; $count++; } print "</table>"; ?> <p> <input name="submit" type="submit" value="Submit"> </p> </form> </div> </body> So i've got it generating the table from the list of names in the file called "7B.txt" all i need to be able to do is making the second column in to a data entry box and generating the email Starting with the first problem of making the second column in to data entry boxes how do i go about doing this? Thanks Similar TutorialsI am creating a music blogging site however the main page will only show one video the code is below anyone have any ideas? " <?php //open database $connect = mysql_connect("******","username","password") or die("Not connected"); mysql_select_db("collegebooxboox") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. $link </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> " I am having trouble pulling a youtube embedded code from my database. Everything else comes out fine however it just doesnt pull anything out where the embedded code is supposed to be. Any ideas I put the code below. All help would be greatly appreciated, also if anyone is feeling generous and would like to help me some more please message me I have a couple other small questions. Code: [Select] <?php //open database $connect = mysql_connect("Database","name","password") or die("Not connected"); mysql_select_db("database") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> hello. please could someone help me with this conundrum im trying to pull my content dynamically. im almost there but im stuck with some code. so i have a layout with 3 columns and in each column i have a place holder. ph01, ph02, ph03 each page has its own id and depending on what the page id is i what to pull different elements into the 3 placeholders. so for this code in the database i have the following: table name: placeholders pages_id = page id ph_number = placeholder number contElements_id = element ids id pages_id ph_number contElements_id 1 1 1 1, 2, 3 2 1 2 4, 5, 6 3 1 3 7, 8, 9 table name: contelements name = name of the element id name 1 E1 2 E2 3 E3 4 E4 5 E5 6 E6 7 E7 8 E8 9 E9 SO, page_ID=1 has 3 placeholders and they should show: ph01 should display = E1, E2, E3 ph02 should display = E4, E5, E6 ph03 should display = E7, E8, E9 this is the code im trying to put together. on the page im using this include function in the left, center and right columns. Code: [Select] $phNo = "1"; echo include_admin_contElements($phNo, $pageID); $phNo = "2"; echo include_admin_contElements($phNo, $pageID); $phNo = "3"; echo include_admin_contElements($phNo, $pageID); now this is where the problem is.... i think in the function file i have this but its a mess.. Code: [Select] function include_admin_contElements($phNo, $pageID){ $PH = Placeholders::find_all(); foreach ($PH as $PHs){ $PHid = $PHs->id; $PHpid = $PHs->pages_id; $PHce = $PHs->contElelments_id; $PHn = $PHs->ph_number; if($pageID == $PHpid){ $CE = Contelements::find_by_PHce($PHce); foreach ($CE as $CEs){ echo $CEid = $CEs->id; echo $CEname = $CEs->name; } } } } - so the idea is i get $phNo, $pageID from the page, - then find all the placeholders in the database Quote Placeholders::find_all(); - then if the $pageID is the same as the $PHpid in the placeholder database Quote if($pageID == $PHpid){ get the content elents for that page. - then i want to get the elements that belong to that page using Quote Contelements::find_by_PHce($PHce); but that does not work Code: [Select] public static function find_by_PHce($PHce=0){ $sql = "SELECT * FROM ".self::$table_name." WHERE id=".$PHce.""; $result_array = self::find_by_sql($sql); return $result_array; } anyway... im stuck. this code doesn't even seperate the 3 different placeholders. it needs a more experienced eye.. its a mess please help thanks ricky I'm not sure I know how to explain what I want to allow you to understand. I'm working on a ventilation app that has different fan sizes. In the input php file I have a dropdown list that's populated by what's in the database. I'd like a results page that lists the fan size and number of each size and the cfm's each fan kicks out. the problem is that I don't know how to do anything with it other than hard code it. What I'd like, is for it to also pull all of the fan sizes and list them, that way the database can be fluid. This is the code I'd like to replace with some sort of loop. //9" fan $results = mysql_query("SELECT * FROM fan WHERE size=9", $link); while ($row = mysql_fetch_array($results)) { $capacity9 = $row['capacity']; }; //--------------------------------------------------------- //10" fan $results = mysql_query("SELECT * FROM fan WHERE size=10", $link); while ($row = mysql_fetch_array($results)) { $capacity10 = $row['capacity']; }; //--------------------------------------------------------- //14" fan $results = mysql_query("SELECT * FROM fan WHERE size=14", $link); while ($row = mysql_fetch_array($results)) { $capacity14 = $row['capacity']; }; //--------------------------------------------------------- //16" fan $results = mysql_query("SELECT * FROM fan WHERE size=16", $link); while ($row = mysql_fetch_array($results)) { $capacity16 = $row['capacity']; }; //--------------------------------------------------------- //18" fan $results = mysql_query("SELECT * FROM fan WHERE size=18", $link); while ($row = mysql_fetch_array($results)) { $capacity18 = $row['capacity']; } //--------------------------------------------------------- //20" fan $results = mysql_query("SELECT * FROM fan WHERE size=20", $link); while ($row = mysql_fetch_array($results)) { $capacity20 = $row['capacity']; }; //--------------------------------------------------------- //24" fan $results = mysql_query("SELECT * FROM fan WHERE size=24", $link); while ($row = mysql_fetch_array($results)) { $capacity24 = $row['capacity']; }; //--------------------------------------------------------- //36" fan $results = mysql_query("SELECT * FROM fan WHERE size=36", $link); while ($row = mysql_fetch_array($results)) { $capacity36 = $row['capacity']; }; Hey all!. I was wondering if there was a way to process information from major websites using php? It seems I am running into issues. Here is what I am trying to do: I need to pull the full list of companies from pinksheets.com that are listed on the exchanges. I can download the list via XLS format, but I need to do this for all the exchange websites such as nasdaq etc. Is there a way to do this where I can comb for the information such as CEO name, ticker , company name and any companies that get taken off or added to the list? The lists I am already talking about are on the sites I mentioned and you can look them up but I am adding 40,000+ companies to my site it manually entering them would be a huge issue,. Do any of you have any fixes? Sorry if this is in the wrong section. Thanks!. Smash. Hiya peeps, I have been sent this today; select company_map.*, map.*,addresses.address,addresses.nomitative,addresses.number, c.postcode from company_map join map on map.id=company_map.map_id join company c on c.company_id=company_map.company_id join addresses on addresses.address_id=c.address_id where company_map.company_id='79' and company_map.ui_shell_id <> 0 and language_id='en' when I print all the results from this I get a postcode, I was wondering if anyone could read this code and simplify it for me, I really need to know what table this query is pulling the postcode from. Many many thanks, James. I am pulling an youtube embedded code from a database however when I have the homepage pull it from the database it will not show anything after the video.... EXAMPLE...(this is what it should look like) 1.) Title By: Author Youtube Video Message Posted By: (however this is what it looks like) 1.) Title By: Author Youtube Video *The "message" and "Posted By:" just do not show up* The code is below can someone help me with this problem., it would be greatly appreciated. Code: [Select] <?php //open database $connect = mysql_connect("Database","name","password") or die("Not connected"); mysql_select_db("database") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'link' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'username' field in the table $messsage = mysql_result($result,$loops,"message"); $author = mysql_result($result,$loops,"author"); $title = mysql_result($result,$loops,"title"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz.) $title By: $author </br> $link </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> Below are two pages...Post.php. and Posted.php the posted page checks and makes sure everything is filled out and makes sure that the link has not been already added. The problem I am having is that it is not pulling over the link information. Every time you hit submit it drops down and goes to saying that you forgot to fill something in and I have it showing everything right now so when that happens I can see what is not going through and the $link never comes through. Any ideas? if anyone needs a better explanation please post and I will try to explain better....basically I am trying to post and everything posts but the link. POST.PHP Code: [Select] <h1>Post</h1> <div class="descr"></div><form method="post" action="posted.php"> <table align="center"> <tr> <td> Youtube Embed Link </td> <td> <input name="link" type="text" id="link"/> </td> </tr> <tr> <td> Title Of Song </td> <td> <input name="title" type="text" id="title" /> </td> </tr> <tr> <td> Author </td> <td> <input name="author" type="text" id="author" /> </td> </tr> <tr> <td> Text: </td> <td> <input name="information" type="text" id="information" /> <br /> </td> </tr> <tr> <td colspan="2" align="center"> <br> <input name="submit" type="submit" value="Post" /> </td> </tr> </table> </form> POSTED.PHP Code: [Select] <?php //msut be logged in page session_start(); if ($_SESSION['username']) { echo""; } else die("You must log in first!"); //form information $submit = $_POST['submit']; $row4 = $_SESSION['username']; // form data $link = strip_tags($_POST['link']); $information = strip_tags($_POST['information']); $title = strip_tags($_POST['title']); $author = strip_tags($_POST['author']); $date = date('Y-m-d'); //Connect To Database $hostname=''; $username2=''; $password2=''; $dbname=''; mysql_connect($hostname,$username2, $password2) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $querycheck = "SELECT * FROM videos WHERE username='$row4'"; $result = mysql_query($querycheck); while($rowz = mysql_fetch_array($result)) $linkcheck = $rowz['link']; if ($submit) { if ($link&&$information&&$title&&$author) { if ($link == $linkcheck) { die ("This link has already been posted."); } else { //Connect To Database $hostname=''; $username2=''; $password2=''; $dbname=''; mysql_connect($hostname,$username2, $password2) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $queryreg = mysql_query("INSERT INTO videos Values ('','$row4','$link','$title','$author','$information','$date')"); } } else { die ("You forgot to put something in the link/title/author/text box. $information $title $link $author"); } } ?> I'm ok with PHP but probably not half as good as some of you guys on here. I am basically trying to find a way to grab a line from a huge and I mean huge text file.... its basically a list of keywords I want to call by line number but without preferably going through them all before I get to that line.....otherwise couldmcrash my server obviously. At the moment im using this Code: [Select] $lines = file('http://www.mysite.com/keywords.txt'); // Loop through our array, show HTML source as HTML source; and line numbers too. foreach ($lines as $line_num => $line) { echo "$line_num"; } This works but im sure theres gotta be a better way of doing to save on usuage because this is putting the whole file into the memory and if I can simply say to php give me line number 97, would umm RULE.... Hope you guys can come up with a solution as your much smarter than me ty Hi all: I have been going nuts trying to get this to work. I have gone through many attempts based on internet searches and examples that simply do not work. I have files stored in my MySQL db. The files cna be of any type and are being displayed in a listed report. The files are hyperlinked and clickable, but here is the issue: When I click on a file in: http://development.products-and-services.ca/cms/test.php I get: http://development.products-and-services.ca/cms/test2.php?content=DHall_CV_webdev_eng.pdf as a blank page result. The objective is to get a file download alert or to see the file in the browser. Any ideas? Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time. Can someone please point me in the right direction? maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc. Thanks Working on a music/video project. Uploaded tracks are stored in user files and product info is stored to DB. What I've been trying to figure out is getting the product information directly from the upload, much like you see in the shot attached. As I haven't had success with that, I've been trying to get the duration of a track using this code. Code: [Select] $fp = fopen($file, 'r'); $size_in_bytes = filesize($file); fseek($fp, 20); $rawheader = fread($fp, 16); $header = unpack('vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits', $rawheader); $tsec = number_format($size_in_bytes/$header['bytespersec'],2); $minutes = intval(($tsec / 60) % 60); $seconds = intval($tsec % 60); $sec="$minutes".":".($seconds<10 ? "0$seconds" : "$seconds");This is working fine when file names are plain text, however it fails when when there are commas or brackets. I don't know if the code can be adjusted to work with these file names or I need to take a different approach. Code: [Select] examples $file ="A cool track, once again"; $file ="A cool track (once again)"; As artists can be picky about their music, I don't want to rename their tracks, but really we shouldn't even have spaces in the names. I could save original name to DB and rename the file, but not sure about restoring original when it come time to download the file. In any case, I hope you understand my problem and can offer some advice. Thanks. I want to make the news feed on my website easier to maintain. I just created a form that I will use to add the information. The form saves the files that it creates as "entry-date-time.txt" and places it in a folder for the year and a sub folder for the month. Such as "2011\09". I have displayed data from a single flat file before, but I am unsure how to go about displaying the data from multiple files. Can anyone show me an example? I want to be able to paginate the data, displaying a number of updates per page from newest to oldest. I don't have MySQL access on the server or I'd just use that, instead. Ok Basically I need to know how to do this: I upload a txt file that contains this: Code: [Select] "MLE ",20,"2057NALL ","ND ","Amber for 2057 1 ","!Amber for 2057 ",00003.65,00001.02 "MLE ",20,"211-2 ","D ","Dome-Courtesy 10 ","!Dome-Courtesy 1 ",00001.60,00000.61 How would I get Information from each different line like the below: Code: [Select] 2057NALL | Amber for 2057 1 | 00003.65 | 00001.02 211-2 | Dome-Courtesy 10 | 00001.60 | 00000.61 Any help on this subject would be greatly appreciated. PhotonicCoder Is there a way to get the source path for an uploaded file? It seems that's a function of the browser and the two I've tried FF and Safari don't return it in $_FILES['file']['name']. I am new to PHP so I'm sorry if anything I ask isn't clear. I'm actually a writer, but my boss randomly decided I need to learn PHP so here I am My first project is to take information from a simple HTML form that asks for users to fill out three text boxes, select if they are user 1 or user 2, and upload a file. I then have to store the information in a text file and display that information in the browser directly below the HTML form. The information must be ordered alphabetically by the first letter of whatever is entered in the first text box. Each entry must be on its own line. For example: Person 1 enters: Sally Mae Johnson User 1 Flowers.jpg Person 2 comes along later and enters: George Michael Johnson User 2 books.jpg Right now it displays in the order entered like this: Sally Mae Johnson User 1 Flowers.jpg George Michael Johnson User 2 books.jpg I need it to display in alphabetical order by the first letter of the first name like this: George Michael Johnson user 2 books.jpg Sally Mae Johnson User 1 Flowers.jpg I'm so close, but I just can't figure out how to finish it up. If anyone can help they'd be a life saver! Here's what I wrote so far: <body> <?php $fone = @$_POST["one"]; $ftwo = @$_POST["two"]; $fthree = @$_POST["three"]; $fselect = @$_POST["select"]; if ($_FILES) { $name = $_FILES['upload']['name']; (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/$name")); } //write to the file $values = "$fone\t"; $values .= "$ftwo\t"; $values .= "$fthree\t"; $values .= "$fselect\t"; $values .= "<img src='uploads/$name'><br />\n"; //open and write to the file $fp = @fopen("store.txt", "a") or die("Couldn't open the file!"); $numBytes = @fwrite($fp, $values) or die ("Couldn't write values to file!"); @fclose($fp); ?> <form action="test_it2.php" enctype="multipart/form-data" method="post"> Box 1: <input type="text" name="one" size="15" /> Box 2: <input type="text" name="two" size="15" /> Box 3: <input type="text" name="three" size="15" /> Select One: <select name="select"><option value="empty">Please Select</option><option value="user1">User 1</option> <option value="user2">User 2</option> <p>Upload a File:</p> <p><input type="file" name="upload" /> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <input type="submit" name="submit" value="submit" /> <input type="hidden" name="submitted" value="submitted" /> </p> </form> <?php print "<P>Here are the users:<br />"; $file = "store.txt"; if (file_exists($file)) { $file1 = fopen("store.txt" , "r"); while (!feof($file1)) { $display = fgets($file1, filesize("store.txt")); echo $display . " "; } fclose($file1); } else { echo "<P>Error occured! Please try again!</p>"; } ?> </body> </html> Hey everyone, I don't know what i'm doing wrong or missing some code snippet (duh! thats why i'm here. lol). The html form with meeting time doesn't transfer the information over to my calendar php file. calendar.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Lab 5</title> <link rel="stylesheet" type="text/css" href="settings.css" /> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> </head> <body> <center> <form method="get" action="calendar.php"> Student Name: <input type="text" name="name"/> <input type="submit" value="Submit" /> <input type="reset" value="Clear" /> </center> <p align="center">Today is <?php print(date("l, F\ jS\ Y")); ?> </p> <?php $date = time(); $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); $first_day = mktime(0,0,0,$month, 1, $year); $title = date('F', $first_day); $day_of_week = date('D', $first_day); switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } $days_in_month = cal_days_in_month(0, $month, $year); //Table starts here echo "<table border=1 cellpadding=10 align=center height=500 width=494>"; echo "<tr><th colspan=7> $title $year </th></tr>"; echo "<tr><td width=42>Su</td> <td width=42>Mo</td> <td width=42>Tu</td> <td width=42>We</td> <td width=42>Th</td> <td width=42>Fr</td> <td width=42>Sa</td></tr>"; //Days in week $day_count = 1; echo "<tr>"; // blank days while ( $blank > 0 ) { echo "<td></td>"; $blank = $blank-1; $day_count++; } //Set the first day of the month $day_num = 1; //This while loops works while there are still days in that month while ( $day_num <= $days_in_month ) { echo "<td> $day_num </td>"; $day_num++; $day_count++; //Starts new row for every week if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Finaly we finish out the table with some blank details if needed while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } echo "</tr></table>"; ?> <a href="http://helios.ite.gmu.edu/~easad/IT207/Lab5/DecCal.php" target="info">Next Month</a> <p> <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a> </p> </body> </html> MeetingTime.html Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link rel="stylesheet" type="text/css" href="settings.css" /> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <title>Meeting Time Sign Up</title> </head> <body> <h1> Meeting Time Setup Form</h1> <form method="get" action="calendar.php"> <table border="1" cellpadding="15" width="75%"> <tr><td width=42>Day: </td> <td width=42><input type="checkbox" name="available" value="Mon" />Monday</td> <td width=42 ><input type="checkbox" name="available" value="Tue" />Tuesday</td> <td width=42 ><input type="checkbox" name="available" value="Wed" />Wednesday</td> <td width=42 ><input type="checkbox" name="available" value="Thr" />Thrusday</td> <td width=42 ><input type="checkbox" name="available" value="Fri" />Friday</td></tr> <tr><td width=42 >Time: </td> <td width=42 > <p><select multiple="multiple" size="3" style="width: 180%;"> <option>7:00am</option> <option>7:00am</option> <option>7:30am</option> <option>8:00am</option> <option>8:30am</option> <option>9:00am</option> <option>9:30am</option> <option>10:00am</option> <option>10:30am</option> <option>11:00am</option> <option>11:30am</option> <option>12:00pm</option> <option>12:30pm</option> <option>1:00pm</option> <option>1:30pm</option> <option>2:00pm</option> <option>2:30pm</option> <option>3:00pm</option> <option>3:30pm</option> <option>4:00pm</option> <option>4:30pm</option> <option>5:00pm</option> <option>5:30pm</option> <option>6:00pm</option> <option>6:30pm</option> <option>7:00pm</option> <option>7:30pm</option> <option>8:00pm</option> <option>8:30pm</option> <option>9:00pm</option> <option>9:30pm</option> <option>10:00pm</option> </select></p> </td> <td width=42 > <p><select multiple="multiple" size="3" style="width: 180%;"> <option>7:00am</option> <option>7:30am</option> <option>8:00am</option> <option>8:30am</option> <option>9:00am</option> <option>9:30am</option> <option>10:00am</option> <option>10:30am</option> <option>11:00am</option> <option>11:30am</option> <option>12:00pm</option> <option>12:30pm</option> <option>1:00pm</option> <option>1:30pm</option> <option>2:00pm</option> <option>2:30pm</option> <option>3:00pm</option> <option>3:30pm</option> <option>4:00pm</option> <option>4:30pm</option> <option>5:00pm</option> <option>5:30pm</option> <option>6:00pm</option> <option>6:30pm</option> <option>7:00pm</option> <option>7:30pm</option> <option>8:00pm</option> <option>8:30pm</option> <option>9:00pm</option> <option>9:30pm</option> <option>10:00pm</option> </select></p></td> <td width=42 > <p><select multiple="multiple" size="3" style="width: 180%;"> <option>7:00am</option> <option>7:30am</option> <option>8:00am</option> <option>8:30am</option> <option>9:00am</option> <option>9:30am</option> <option>10:00am</option> <option>10:30am</option> <option>11:00am</option> <option>11:30am</option> <option>12:00pm</option> <option>12:30pm</option> <option>1:00pm</option> <option>1:30pm</option> <option>2:00pm</option> <option>2:30pm</option> <option>3:00pm</option> <option>3:30pm</option> <option>4:00pm</option> <option>4:30pm</option> <option>5:00pm</option> <option>5:30pm</option> <option>6:00pm</option> <option>6:30pm</option> <option>7:00pm</option> <option>7:30pm</option> <option>8:00pm</option> <option>8:30pm</option> <option>9:00pm</option> <option>9:30pm</option> <option>10:00pm</option> </select></p></td> <td width=42> <p><select multiple="multiple" size="3" style="width: 180%;"> <option>7:00am</option> <option>7:30am</option> <option>8:00am</option> <option>8:30am</option> <option>9:00am</option> <option>9:30am</option> <option>10:00am</option> <option>10:30am</option> <option>11:00am</option> <option>11:30am</option> <option>12:00pm</option> <option>12:30pm</option> <option>1:00pm</option> <option>1:30pm</option> <option>2:00pm</option> <option>2:30pm</option> <option>3:00pm</option> <option>3:30pm</option> <option>4:00pm</option> <option>4:30pm</option> <option>5:00pm</option> <option>5:30pm</option> <option>6:00pm</option> <option>6:30pm</option> <option>7:00pm</option> <option>7:30pm</option> <option>8:00pm</option> <option>8:30pm</option> <option>9:00pm</option> <option>9:30pm</option> <option>10:00pm</option> </select></p></td> <td width=42 > <p><select multiple="multiple" size="3" style="width: 180%;"> <option>7:00am</option> <option>7:30am</option> <option>8:00am</option> <option>8:30am</option> <option>9:00am</option> <option>9:30am</option> <option>10:00am</option> <option>10:30am</option> <option>11:00am</option> <option>11:30am</option> <option>12:00pm</option> <option>12:30pm</option> <option>1:00pm</option> <option>1:30pm</option> <option>2:00pm</option> <option>2:30pm</option> <option>3:00pm</option> <option>3:30pm</option> <option>4:00pm</option> <option>4:30pm</option> <option>5:00pm</option> <option>5:30pm</option> <option>6:00pm</option> <option>6:30pm</option> <option>7:00pm</option> <option>7:30pm</option> <option>8:00pm</option> <option>8:30pm</option> <option>9:00pm</option> <option>9:30pm</option> <option>10:00pm</option> </select></p></td>; </tr> </table> </br> <input type="reset" value="Clear" /> <input type="submit" value="Submit" /> <input type="hidden" value="newuser" /> </form> </body> </html> I'm going to be blunt, I've been working on a website for quite some time now and I never really stopped to think about the effects that an over abundant amount of queries could actually slow things down. I'm quite new to the whole PHP / MySQL thing so I am still learning. While reading through some things about optimization of queries I've learned some valuable information, such as working with Indexes, and not running unnecessary queries which the data doesn't seem to change that often. So for a few aspects of my site which don't really change in particular periods of time, I've decided to write the contents of them into a text file then retrieve and display them as normal through my site. Things that last an hour, or a day, will no longer be queries on each page load; tremendously reducing the amount of queries which my database would take. Currently I have the following code: if($database->numrows($query) > 0) { $myFile = 'testFile.txt'; if($fh = fopen($myFile, 'w')) { $i = 0; while($row = $database->fetchassoc($query)) { ++$i; $stringData = '' . $row['id'] . '--' . $row['name'] . '--' . $row['color'] . '--' . $row['bdaytest'] . '--' . $row['gmtoffset'] . "\n"; fwrite($fh, $stringData); } fclose($fh); } } Which Prints Out Quote 32--User3--0--1939-10-03--+0.0 27--User7--0--1979-10-04--+17.0 28--User65--150--1969-10-05--+17.0 30--User1--0--1959-10-06--+6.0 31--User9--0--1949-10-07--+3.0 29--User5--0--1989-10-08--+17.0 The problem stems from pulling the information from the file and exploding it. That file would be for yesterday's up to 7 days from now's birthdays. The amount of lines could change, possibly messing up the possibility of an array. I was thinking about pulling the information into an array, than exploding it from within that array, posting it to variables.. and then have it display all in a while. Am I on the right track, or is there some other alternative I can use? Only data that will always be visible on the website, will be held in these text files. Any suggestions on how I pull the information from the text file and explode it to display exactly how I need it to be displayed? Hello! I have a 2 questions: Q1: How do you store answers from a php file(see code below) into another file?(php preferably) I know it would probably be easier using a database, but I would like to know how to do it with a text/php file. Below you can see a piece of code for a page students would go on to fill in online exercices. They would first have to input their names. These names would have to be sent to a php file called "StudentAnswers.php". As well as their answers I also have another file that is called "QandA.php" which is called on with include in the piece of code below so the students can't see the answers before they submitted their answers. Q2: But how do I complete the if code(see question marks) so the answer only shows IF(as soon as) they clicked on the submit button? Code: [Select] <html> <body> <h2>Exercices</h2> <p> <form name="input" action="StudentAnswers.php" method="get"> Student name: <input type="text" name="user" /> </form> </p> <p> What is the gradient of T(x,y)=2x+3? <form name="input" action="StudentAnswers.php" method="get"> <input type="text" name="1b" /> <input type="submit" value="Input answer"/> </form> if ( ????????? ) { ???????"; } <?php include("QandA.php"); echo $Question["1b"];?> <p> </body> </html> B |