PHP - Confused, Im Gettinbg Double Entries In Text File
//if any items in order table then display all items in order table
$order_sql = "select * from orders"; $order_result = $handle -> query( $order_sql ); if($order_result->num_rows) { echo '<table bgcolor=#FFFF66 ><td>'; while ($order = $order_result -> fetch_assoc()) { $category_sql = "select category from category where category_id = {$order['category_id']}"; $category_result = $handle -> query( $category_sql ); $category_name = $category_result -> fetch_row(); $menu_sql = "select item_name from menu where item_id = {$order['item_id']}"; $menu_result = $handle -> query( $menu_sql ); $menu_name = $menu_result -> fetch_row(); echo $category_name[0] . ': ' . $menu_name[0] . ' ' . $order['size'] . ' ' . $order['type'] . ' ' . $order['amount'] . '<br />'; //insert data into order.txt file for print $file_insert = $category_name[0] . ": " . $menu_name[0] . " " . $order['size'] . " " . $order['type'] . " " . $order['amount'] . "\r\n"; @ $fp = fopen( 'order.txt', 'ab' ); if($fp) { fwrite( $fp, $file_insert, strlen( $file_insert ) ); } else { echo 'could not insert data into order.txt file for print, CLICK ON NEW ORDER'; } fclose($fp); } Similar TutorialsI'm trying to compare 2 files, each with data separated by ::. I'm trying to make a comparison that if the data to the left of the separator from one file is not found in the same column of the other file, then it is copied to an array. For example: file1.txt abc::def ggg::hhh mmm::ppp file2.txt abc::def zzz::aaa bbb::ccc So... ggg::hhh mmm::ppp is copied from file1.txt because ggg and mmm was not found on the same side in file2.txt ...but I'm not getting any error message with this. The operation just hangs. Code: [Select] <?php $dic1 = file('file1.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $dic2 = file('file2.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $titleText = array(); // Storing results into this array. foreach ($dic1 as $dic1line){ list($dic1field1, $dic1field2) = explode('::', $dic1line); foreach ($dic2 as $dic2line){ list($dic2field1, $dic2field2) = explode('::', $dic2line); if ($dic1field1 != $dic2field1) { // Found a non match in DB. array_push($titleText, "$dic1field1 :: $dic1field2\n"); // Store all finds in array. } } } // Finish outputting anything left over. if (empty($titleText)) { // $value was not found -- array is empty. echo 'All matched, or something else.'; } else { $arrayOut = implode("", $titleText); // output the results found in the search. echo $arrayOut; } unset($value); ?> Anyone know how to do this? Thanks. Hello, I'm requesting your help here cause I'm really confused. I'm looking for deleting entries when an image doesn't load on my links test. I got all my links in a .txt file like this : links.txt = Code: [Select] <div class="gallery"> <a href="http://www.website.com/page"> <img src="http://tc16.easythumbhost.com/image.jpg" onerror="ImgError(this)"/> </a> </div> #enddiv the "onerror" code in img src sends an "Image Missing" pic. What I'd want is to change the "onerror" function to open a php script which deletes all the lines of the div. This is the script I use to show the links on my page : Code: [Select] $links = "links.txt"; $fd = fopen ($links, "r"); $content = fread ($fd,filesize ($links)); fclose ($fd); $delimiter = "#enddiv"; $splitcontent = explode($delimiter, $content); $output = array_slice($splitcontent, 0,100); foreach ( $output as $divs ) { echo "$divs"; } I've searched hours and tried lots of codes before posting Help would be very appreciated. Thanks. Hi Hope someone can help me please. I have constructed an audio dictionary and have discovered an error now that I have added a few entries to the database. A user can search the database and can click on a result to be taken to the content associated with the entry he chooses. This is the search function; Code: [Select] $search=$_POST["search"]; //get the mysql and store them in $result $result = mysql_query("SELECT word FROM pro_words WHERE word LIKE '%$search%'"); //get the db content that is specified above if (mysql_num_rows($result) < 1) { echo "<br><br><h2> We didn't find anything. Sorry - we did look though.</h2>"; }else { echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr><td align="left"><b>Word</b></td></tr>'; echo "<br><br><h2>Success! Here's what we found:</h2><br>"; while ($r=mysql_fetch_array($result, MYSQLI_ASSOC)) echo '<h2><tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr></h2>'; } You will see that content is displayed in a new file called word.php. This is relevant code from word.php Code: [Select] $query = "SELECT word,word_type1,sentence1,word_type2,sentence2,word_type3,sentence3 FROM pro_words"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<div class="colmask rightmenu">'; echo '<div class="colleft">'; echo '<div class="col1">'; echo '<p>Here are some example sentences that show how we use the word; </p>'; echo '<div id="small"><i> ' . $row['word_type1'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence1'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type2'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence2'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type3'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence3'] . '</p></div>'; } The problem is that every entry on the database is echoed in word.php whereas I would like only the entries for the word selected to appear. Thanks in advance for any help; do say if you need more info. I have a Windows-style ini file that contains entries as such:
[Timers] Timer(1)=50 Timer(2)=30 Timer(3)=20 The entries represent an array of 3 different timers Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated? I don't know if this relevant to php or css in my template folder I have file named (index.template.php). It contains this code <?php echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="Keywords" content="BHL-SimpleTool Content Manager System" /> <meta name="Author" content="BHL-SimpleTool is coded by Othman A. Taha" /> <meta name="Description" content="Site Powered by BHL-SimpleTool CMS" /> <title>BHL-SimpleTool v1.0 - Alpha</title> <link rel="stylesheet" href="themes/default/style.css" media="all" type="text/css" /> <link rel="stylesheet" href="themes/default/forms/forms.css" media="all" type="text/css" /> <link rel="stylesheet" href="modules/forum/Themes/default/style.css" type="text/css" /> <link rel="stylesheet" href="inc/jq/css/style.css" type="text/css" /> <script language="javascript" type="text/javascript" src="js/bbcodes.js"></script> <script language="javascript" type="text/javascript" src="js/smileys.js"></script> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript" src="js/easySlider1.5.js"></script> </head> <body> <div id="wrapper"> my website run here </div> </body> </html>'; ?> It works fine( I made the top-margin to be 0px). But when I include index.template.php in my main (index.php) the top margin show a big margin from the top Note: I included (index.template.php) in my main (index.php) like this: <?php function __autoload($class_name) { require_once 'classes/Sessions' . '.php'; } $sessInfo = new Sessions(); $sessInfo->RunAllBhlSimpeToolStuff(); ?> Hi Guys, I'm having a problem with some file upload code I wrote and I was wondering if you could help me figure out why it's not working?? Here it is; Code: [Select] if($_POST['photo'] == "") $photo_update = "images/item_pictures/default_item.png"; else { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] ."<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; //Check image doesn't exist in first folder then uploads if doesn't. if (file_exists("images/item_pictures/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "images/item_pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "images/item_pictures/" . $_FILES["file"]["name"]; } //Check image doesn't exist in second*admin*folder then uploads if doesn't. if (file_exists("admin/images/item_pictures/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "admin/images/item_pictures/" . $_FILES["file"]["name"]); $photo_update = "admin/images/item_pictures/" . $_FILES["file"]["name"]; echo "Stored in: " . $uploaded_file; } } } else { echo "Invalid file"; } } Thanks in advance Jacbey I currently am working on a project where I code a "simple" telephone directory. There are three main tasks that it needs to do: 1. Directory.php(index page) has a "First Name" and "Last Name" field and a search button. When a name is searched from the directory.txt file, it displays First Name, Last Name, Address, City, State, Zip and phone in findinfo.php in designated text boxes...first name, last name, etc. 2. From the findinfo.php, like previously stated, the users information is listed in the appropriate text boxes. From there, there is an update button that will overwrite the user's information to directory.txt if that button is selected. It will then say the write was sucessful. 3. (completed this step) From the index page, there is a link that will take you to addnew.php where you enter First Name, Last Name, Address, City, State, Zip and phone in a web form and write it to directory.txt. This is the php code for the third step: <?php $newentryfile = fopen("directory.txt", "a+"); $firstname = $_POST['fname']; $lastname = $_POST['lname']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $newentry = "$firstname $lastname\n\r $address\n\r $city, $state $zip\n\r $phone\n\r"; if (flock($newentryfile, LOCK_EX)) { if (fwrite($newentryfile, $newentry) > 0) echo "<p>" . stripslashes($firstname) . " " . stripslashes($lastname) . " has been added to the directory.</p>"; else echo "<p>Registration error!</p>"; flock($newentryfile, LOCK_UN); } else echo "<p>Cannot write to the file. Please try again later</p>"; fclose($newentryfile); if(empty($firstname) || empty($lastname) || empty($address) || empty($city) || empty ($state) || empty($zip) || empty($phone)) { echo "<p>Please go back and fill out all fields.</p>"; } ?> So to sum it all up, what would be my best approach? I am totally stumped and not sure which function to use. Should I work my way from step 1 to step 2? I see it as when I do the search for the name from directory.php, it takes me to findinfo.php, listing the users information in the text boxes. From there, if I needed to, having the user's information already listed I could hit the update button to overwrite the new information to directory.txt. Doing the update when then tell me that the write was successful. I have literally been scouring the internet for hours. What would be the best function to do this? I hope I was clear enough. Please help me out and thank you for your time. Hi, I am writing several scripts and some are used to amend extra information to a text file. However, I added a hyperlink to the text file so that the user can go back to a page where they can add extra information. However, since I have done this every time I amend more text to the text file, the extra text appears below the hyperlink rather than above it, and I was wondering if there was a way around this. My amend code is as follows: Code: [Select] <html> <head> <title>Amend File</title> <link rel="stylesheet" type="text/css" a href="rcm/stylesheet.css"> </head> <?php if($_POST['append'] !=null) { $filename="C:/xampp/htdocs/rcm/denman2.txt"; $file=fopen($filename, "a"); $msg="<p>Updated Information: " .$_POST['append']. "</p><br>"; fputs ($file, $msg); fclose($file); } ?> <body> <h1>Do you want to append to a document?</h1> Enter Updated Information: <form action="amendfile2.php" method="post"> <input type="text" size="40" name="append"><br><br> <input type="submit" value="Add updated information to report"> </form> <form action="viewfile3.php" method="post"> <input type="submit" size="40" value="View Web Blog"> </form> <form action="loginform.php" method="post"> <input type="submit" value="Click here to go to the Log In Screen"> </form> </body></html> And my text file is as follows: Code: [Select] <h1>Accident Report</h1> <p>First Name: Andrew Last Name: Denman Age: 18 Complete Weeks Since Accident: 2<br> <a href="amendfile2.php">Amend to this file</a> Any help would be appreciated Ok i have been working on this for a day+ now. here is my delema simple .ini text file. when a user makes a change (via html form) it makes the correct adjustments. problem is the newline issue 1. if i put a "\n" at the end (when using fputs) works great, except everytime they edit the file it keeps adding a new line (i.e. 10 edits there are now 10 blank lines!!!!) 2. if i leave off the "\n" it appends the next "fgets" to that lilne making a mess Code: [Select] ##-- Loop thruoght the ORIGINAL file while( ! feof($old)) { ##-- Get a line of text $aline = fgets($old); ##-- We only need to check for "=" if(strpos($aline,"=") > 0 ) { ##-- Write NEW data to tmp file fputs($tmp,$info[$i]." = ".$rslt[$i]."\n"); $i++; } ##-- No Match else { fputs($tmp,$aline."\n"); }//Checking for match }//while eof(old) what in the world is making this such a big deal. i dont remember having this issue in the past I tried opening with w+, and just w on the temp file a typical text line would be some fieldname = some value the scipt cycles through the file ignoring comments that are "#" ps the tmp file will overwrite the origianl once complete all i really want to know is WHY i cant get the newline to work, and what is the suggested fix EDIT: i just tried PHP_EOL and it still appends another newline Hello, i am currently getting an Microsoft Excel formatted text file whose save type is .Txt from a URL.I used to open it and will change the save type as excel file. Please suggest whether we can do this with php code. currently my code is like this, <? php copy("http://www.faa.gov/airports/airport_safety/airportdata_5010/menu/emergencyplanexport.cfm?Region=&District=&State=&County=&City=LAS%20VEGAS&Use=&Certification=","./contactsexport.xls"); ?> where as the contactsexport.xls type is .Txt which i need it in .xls Thanks in Advance. Below is the part of my code that creates the html table. How do I add pagination every 30 entries? $db = mysql_connect("localhost","trend_learnu","asdfasdf"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td> <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>'; $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) the problem is that when I add an item to be displayed in the blog, shows three instead, which two are empty. It should not create three entries when I just add one entry. How can I fix this? <?PHP /* define the blog content file name */ $filename = "myBlogContent.txt"; ?> <?php /* check to see if the file exists */ if (!file_exists($filename)) { echo "The Blog Is Empty"; }else{ /* get the file lines into an array */ $BlogArray = file($filename); /* count the number of blog entries */ $count = count($BlogArray); $i=0; while($i<$count) { $new_array = explode("|", $BlogArray[$i]); echo "Posted by: " . $new_array[1] . "<br>"; echo "Posted on: " . date("m/d/y h:iA", time($new_array[0])) . "<br>" echo "Title: " . $new_array[2] . "<br>"; echo $new_array[3] . "<hr>"; $i ++; } } ?> <?PHP /* obtain the form data */ $who = $_POST['who']; $title = $_POST['title']; $content = $_POST['content']; $content = str_replace(array("\r\n", "\r", "\n"), "<br>", $content); /* create timestamp variable for current date and time */ $when_ts = time(); /* define the blog content file name */ $filename = "myBlogContent.txt"; /* prepare the variables for adding to the file */ $new_line_content = $when_ts . "|" . $who . "|" . $title . "|" . $content . "\n"; /* open the file in the APPEND MODE */ $fh = fopen($filename, 'a+') or die("can't open file"); /* add the new content */ fwrite($fh, $new_line_content); /* close the file */ fclose($fh); //exit; // Closes further script execution . ?> Hello, I am trying to read data from a text file but also adding up the 4th column for example 'name' 'more' '1.00' 'evenmore' so were the 1.00 is I want to add it up is there anyway ? How would I open a text file from another server and echo it. http://mysite.com/news/feed.txt Ok, I have a log file that is written to. I only want the text file to have the last fifty lines (\n) delimited So, how do I make it delete the excess from the TOP of the file? So if it had 60 lines, I would want it to only have lines 10-60 to net 50 total. Thanks. is there a php solution that will take the raw data from one file and paste it into another text file? I have a master file and a download file that always starts at quarter past midnight . this data needs to be pasted into the master file, in the correct place , possibly overlapping and replacing data that already exists. the length of the download file will vary but will always start at 00. 15 the two files are www.maidenerleghweather.com/download.txt and also www.maidenerleghweather.com/master.txt any help appreciated . Hello, I had simple php website in one folder, no database in the website. I need a method for text search in the web directory... Any help? Thanks $tracking_file_location = "../dispatch-manager/logs/tracking_file.txt"; $tracking_file = fopen("$tracking_file_location", "r") or die("Unable to open file!"); $tracking_file_size = filesize("$tracking_file_location"); $tracking_file_text = fread($tracking_file,$tracking_file_size); fclose($tracking_file); |