PHP - How Can I Find Missing Numbers?
Hi,
I have a list of 5000 ID's but there are about 150 missing i want to find out what ones are missing, How can i do with this PHP? Thanks Similar TutorialsI'm trying to increment a numerical value and after several hours of reading haven't come up with a solution. this may be too much information but here it is; I'm using this code to change the values in r5include.html Code: [Select] <?php $ident = $_POST['ident']; ?> <?php $ident2 = ($ident . 2); $filename = 'r5include.html'; $string = file_get_contents($filename); $old = array("'images/up.jpg'","add.html' target='_blank'"); $new = array("'$ident/$ident2.jpg'","$ident.html' target='iframe2'"); $data = str_replace($old,$new,$string); $handle = fopen($filename, "w+"); fwrite($handle,$data); fclose($handle); ?> but before I do that I'm copying the original to a temp file with this code: Code: [Select] <?php $filename = 'r5include.html'; $string = file_get_contents($filename); $tempfile = 'temp.html'; $handle = fopen($tempfile, "a"); fwrite($handle,$string); fclose($handle); ?> This is what goes to temp.html: Code: [Select] <img height=75 src='images/up.jpg' hidefocus='true' usemap='#record51' /> <map name='record51'> <area shape='rect' coords='0,0,75,75' href='add.html' target='_blank'> I would like to increment the 2 instances of record51 to record52 and increment again each time the process is initiated. And then append it to r5include with this: Code: [Select] <?php $myFile = "r5include.html"; $fh = fopen($myFile, 'a') or die("can't open file"); $filename = 'temp.html'; $string = file_get_contents($filename); fwrite($fh,$string); fclose($fh); ?> So the question is is it possible? and if so how do I increment the record number? Thanks, hello, is there any way that i can take a string like this: 99,99,28,99,28,112,78,99,28,112,78,28,112,78,112,78,112, and find and remove the recurring numbers so i am left with this:? 99,28,112,78 thanks for your time Joe Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim To make a long story short, I have a series of forms, where certain options are visible depending on what the user selected on the previous form. The final form processing is where I'm having issues. I have the following for each option, to check if that option was selected (this is all somewhat pared down for clarity): Code: [Select] if (isset($_POST['option1']) && $_POST['option1'] > 0){ $option1 = mysql_real_escape_string($_POST['option1']); $query1 = "DELETE FROM table WHERE itemid = '$option1'"; } I have that basic thing for each of the options, where it assigns a deletion query based on each individual option. Later in my code, I have the following, which again checks if each option was selected (it's restated because it's after several error checks) then is supposed to run the query that was assigned in the previous part: Code: [Select] if ($_POST['option1'] > 0){ mysql_query($query1); } if ($_POST['option2'] > 0){ mysql_query($query2); } if ($_POST['option3'] > 0){ mysql_query($query3); } (etc, for all the options) My problem is that the queries are not executing and I can't see any reason why not. Query #1 is working... it executes the deletion query and all is well, but if I try to select any options other than #1, the query doesn't execute. I tried echoing the queries within the second if statements above (where it runs the queries) and it's echoing them fine (and they look normal), so I know it's able to run the queries, it just isn't... Am I blind? lol. I must be missing something obvious because this is driving me crazy. Thank you in advance. Please let me know if you need more info. Hi. I am new to PHP and trying out database connections. I am trying to query the database, to see if the date matches a record in the field 'date'. If it does echo yes, if there are no matches 'no'. Can anyone tell me what is missing from my code: Code: [Select] <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("date_picker", $con); $date= $_POST['date']; $new_date = date('Y-m-d',strtotime($date)); $sql = 'SELECT date FROM availability' if (date = $new_date) echo "Yes"; else echo "No"; mysql_close($con) ?> Really not seeing where my missing parenthesis goes. Code: [Select] if(isset($this->uri->segment(3)) AND ((empty($this->uri->segment(3))||($this->uri->segment(3) === FALSE)||(trim($this->uri->segment(3)) == ''))) Let's say I have an array: $myArray[0] = "AtG2"; $myArray[1] = "AtG4"; $myArray[2] = "AtG1"; $myArray[3] = "AtG3"; $myArray[4] = "AtG5"; I want to sort it alphanumerically, so that the key/value pairs are as follows: [zero*] => "AtG1" [1] => "AtG2" [2] => "AtG3" [3] => "AtG4" [4] => "AtG5" * = I have to write [zero] because putting an actual zero number inside of [ and ] braces converts it to an HTML list bullet. It *appears* that natsort() is the proper function for this. The only problem I'm having is that natsort() doesn't manipulate key/value pairs. To confuse me even more, literally every example I can find on using natsort() uses it in conjunction with print_r() like so: natsort($someArray); print_r($someArray); Obviously, something is happening to $someArray when passed to natsort(), otherwise, print_r() wouldn't be able to order the indices in synch with the natural ordering algorithm. Well, I don't need my web app to use print_r()! I just need the darn key/value pairs reordered so that when I echo $myArray[3], I know I'm going to get "AtG4". What am I missing here? What is the point of calling it a "sort" if it doesn't manipulate the key/value pairs??? How can I get what I want?!? well when i am in my forum thing and i go to click on a 'topic' it says no topic exists. and there is one there idk what im missing in the code to make it view it in my table.. Code: [Select] <?php require("top.php"); ?> <div id='content'> <div id='homepageright'> <?php include_once("scripts/connect.php"); if($username){ $cid = $_GET['cid']; $tid = $_GET['tid']; $sql = "SELECT * FROM topics WHERE category_id='".$cid."' AND id='".$tid."' LIMIT 1"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1){ echo "<table width='100%'>"; if($username){ echo "<tr><td colspan='2'><input type='submit' value='Add Reply' onClick=\"window.location = post_reply.php?cid=".$cid."&tid=".$tid."\" /><hr /> "; } While ($row = mysql_fetch_assoc($res)) { $sql2 = "SELECT * FROM posts WHERE category_id='".$cid."' AND topic_id= '".$tid."'"; $res2 = mysql_query($sql2) or die(mysql_error()); while ($row2 = mysql_fetch_assoc($res2)) { echo "<tr><td valign='top' style='border: 1px solid #000000;'><div style='min-height: 125px; '>".$row['topic_title']."<br /> by ".$row2['post_creator']." - ".$row2['post_date']. "<hr /> ".$row2['post_content']."</div></td><td width='200' valign='top' align='center' style='border: 1px solid #000000;'>User Info Here</td></tr><tr><td colspan='2'><hr /></td></tr>"; } echo "</table>"; } } else{ echo "This Topic Does Not Exist."; } } else{ echo "You Must Be Logged In To Continue."; } ?> </div> <div id='homepageleft'> <?php ?> </div> </html> </body> I am running a search query from MYSQL and it works, but now I want to get a little custom. I am selecting one field, out of many called paid1 which in database is either Yes or No. I want to do this: if paid1 is NO display Pay Now and everything else display Yes. I want this to be under new heading of paid1b. So the code should look something like this: $paid1b= if(['paid1'}==No){echo "Pay Now";} else {echo "YES";} But I am missing something somewhere. What is it? Thanks The user will click on the first button (.Applybutton) which opens a bootstrap modal with the ID ApplyModal. From then on an apply button (.SendButton) will send the job id that is passed in the first button press $_POST['jobid'] to the database. I'm using the following script to download large file (>100Mb). It works well except that it seems to not ever save the final chunk. If the file is 149,499 on the server, it finishes its download at 145,996. Why? How do I get the last 2% or so to flush and complete the download? Thank much for your help. FYI, this also happens the same on smaller files so its not stopping for time or file size issues. Code: [Select] $path = "the/file/path.mp4"; $headsize = get_headers($path,1); $ext = str_from_last_occurrence($_vars['filepath'],"."); if ($ext=="mp3") { $type = "audio"; } elseif ($ext=="mp4") { $type = "video"; } function readfile_chunked($filename,$retbytes=true) { // Stream file $handle = fopen($filename, 'rb'); $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $cnt =0; if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); if ($retbytes) { $cnt += strlen($buffer); } } $status = fclose($handle); if ($retbytes && $status) { return $cnt; // return num. bytes delivered like readfile() does. } return $status; } header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate'); header("Content-type: ".$type."/".$ext); header('Content-Length: ' . (string)($headsize['Content-Length'])); header('Content-Disposition: attachment; filename="'.str_from_last_occurrence($_vars['filepath'],"/").'"'); header("Content-Transfer-Encoding: binary"); readfile_chunked($path); exit; I am trying to get a paragraph from a website. Everything works but the first letter is kept on missing. The code shown below is used to get the paragraph. Not sure why the first letter is missing. Please help!!! Code: [Select] if ( isset( $offer[ 0 ] ) ) { // Tidy it up - remove commas and weird Word chars $off = strip_tags( $offer[ 0 ] ); $off = substr( $off, strpos( $off, ";" ) + 1 ); $off = str_replace("'", "", $off ); $off = trim( $off ); } else { $off = "0"; } nothing is echoed for the second foreach??? foreach($pictures as $picture) -im breaking cause it's a large file Code: [Select] $doc = new DOMDocument(); $doc->load('accommodation.xml'); $i = 0; $accommodations = $doc->getElementsByTagName('accommodation'); foreach($accommodations as $accommodation) { if(++$i > 2) break; $supplierID = $accommodation->getElementsByTagName('code')->item(0)->nodeValue; $pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue; $pictures=array(); foreach($pictures as $picture) { echo $url = $picture->getElementsByTagName('url')->item(0)->nodeValue; } }//end //XMl schema <?xml version="1.0" encoding="utf-8"?> <accommodations> <accommodation> <code>1</code> <pictures> <picture> <url>http://example.com/images.k.jpg</url> </picture> </pictures> Hey guys I'm not amazing at PHP, but know just enough to be dangerous. Basically I'm trying to get these records from my database to display in rows of 4. For some reason every time, I'm missing a record (the first record returned in my query). It's probably something simple is my code. Would be grateful if anyone could lend a suggestion. Code: [Select] <?php $a=0; $b=3; while ($ArrayData = mysql_fetch_array($QueryData)) { //if a=0, start new row if ($a==0) { echo '<tr>'; } //create cell //if thumbnail exists, use it, otherwise throw in the unavailable image if ($ArrayData["PhotoThumb"]!="") { $ImageToUse = $ArrayData["PhotoThumb"]; } else { $ImageToUse = "image_unavailable_thumb.jpg"; } echo ' <td width="33%" align="center" valign="top"><p><a href="item.php?ItemID='.$ArrayData["ItemID"].'"><img src="images/'.$ImageToUse.'" border="0" /></a></p> <p><a href="item.php?ItemID='.$ArrayData["ItemID"].'" class="cart_body_text">'.$ArrayData["ItemName"].'</a><br /> <span class="style1"> <strong>$'.sprintf("%01.2f", $ArrayData["UnitPrice"]).'</strong></span><br /> </p> </td>'; //increment by 1 $a++; //if a = 3 then close the row using </tr>, ready to start a new one if ($a==$b) { echo ' </tr>'; //reset counter, ready to start new row $a=0; } } if ($a > 0 ) { echo '</tr>'; } ?> Thanks guys! Hi, I have set up a new website, but the old website is using /mainpage.html as it's homepage when searching in Google. This page no longer exists, so when a user clicks on the page in Google, the website is not found. Is there a way i can set up a forwarder to point the missing file to the new index.php page? Thanks I've been trying to figure out this issue for a couple of days now. I have a client that insists in using the Innovaeditor in IE. I have placed a stylesheet in on the editors, and it breaks the scrollbar in IE. When I take it out it returns. I still want to preserve the styles I want to set, and be able to scroll down the editor box. It works fine in Firefox. Any help would be MUCH appreciated. Hey guys, been awhile since I have been here, but I hit a little issue in reading session data reliably every time. What I am doing is reading the variables and values from a rarurlencoded string. Then putting that into a session array to populate parts of a form and fill in some hidden fields. After the form posts every now and then, about 1 in 50 or so attempts, I have one (always the same one) that just vanishes. Anyone ever experience anything like this? Hi all - It's gotta be something obvious, but I can't for the life of me how I'm sending output in this file before I send a header redirect. Can anyone see it? <?php //Initialize securimage captcha session_start(); require_once('dbconnect.php'); // initialize db connection to populate email address include_once('../securimage/securimage.php'); $language = $_POST['lang']; include($language . ".php"); //Load language file for feedback. TODO: Maintain separate file for this so the script doesn't need to load so many unused variables? $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { die($contact_bad_captcha); } // pump post vars into local vars and clean them up, assign to session to display on contact completion function lang($language) { //Give hidden post var for language a human name switch ($language) { case en: return "English"; break; case es: return "Español"; break; default: return "Español"; } } $reason = htmlentities($_POST['reason'], ENT_QUOTES); $name = htmlentities($_POST['name'], ENT_QUOTES); $email = htmlentities($_POST['email'], ENT_QUOTES); $phone = htmlentities($_POST['phone'], ENT_QUOTES); $cell = htmlentities($_POST['cell'], ENT_QUOTES); $method = htmlentities($_POST['method'], ENT_QUOTES); $comments = htmlentities($_POST['comments'], ENT_QUOTES); $lang = lang($language); // Query for email addresses $query = "SELECT `description`,`email` FROM contact WHERE `code` = \"" . $reason . "\" AND `language` = \"" . $language . "\""; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $to = $row['email']; $reason = $row['description']; } $subject = "ELP Contact Form Submission From " . $name; $_SESSION['name'] = $name; $_SESSION['email'] = $email; $_SESSION['phone'] = $phone; $_SESSION['cell'] = $cell; $_SESSION['method'] = $method; $_SESSION['comments'] = $comments; // Build the mail object $header = "From: " . $email . "\r\n"; $header .= "Reply-To: " . $email . "\r\n"; $header .= "Bcc: email@address.com\r\n"; $header .= "Content-type: text/html; charset=iso-8859-1\r\n"; $message = "Reason: " . $reason . "<br>"; $message .= "Name: " . $name . "<br>"; $message .= "Email: " . $email . "<br>"; $message .= "Phone: " . $phone . "<br>"; $message .= "Cell: " . $cell . "<br>"; $message .= "Method to contact: " . $method . "<br>"; $message .= "Comments/Questions: " . nl2br($comments) . "<br>"; $message .= "Language: " . lang($language); // Send it after checking that variables are set correctly if (isset($name) && isset($email) && isset($method) && isset($comments) && isset($header) && isset($message)) { mail($to, $subject, $message, $header); header("Location: ../contactcomplete.php?lang=" . $language); // Forward to completion page which displays what was sent } else { echo $contact_general_error; //Unknown error } ?> Code: [Select] Warning: Cannot modify header information - headers already sent by (output started at /home1/supresen/public_html/configs/es.php:1) in /home1/supresen/public_html/configs/email.php on line 67 Thanks for the help! I've got a syntax error, but I can't for the life of me see where there's a problem. unexpected T_VARIABLE, expecting ',' or ';' ... on line 35 Code: [Select] <? include("header.php"); ?> <html> <head> <title>login </title> </head> <body> <?php // this is the login page require ('databaseconnect.php'); // set the page title if (isset($_POST['submitted'])) { $e = escape_data($_POST['username']); } else { echo '<p> >font color="red" size="+1> You forgot to enter your user name</font></p>'; $e = FALSE; } // validate password if (!empty($_POST['password'])) { $p = escape_data($_POST['password']); } else { $p = FALSE; echo '<p><font color="red" size="+1:>You forgot to enter your password!</font></p>; } if($e && $p) { $query = "SELECT ID, first_name FROM table WHERE (username='$e' AND password=SHA('$p') AND active IS NULL"; $result = mysql_query($query) or trigger_error("Query: $query\n<br /> MySQL Error: " . mysql_error()); if (@mysql_num_rows($result) ==1) { $row = mysql_fetch_array ($result, MYSQL_NUM); mysql_free_result($result); mysql_close(); $_SESSION['first_name'] = $row[1]; $_SESSION['id'] = $row[0]; // start defining url $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); // check for trailing slash illegal access attempts if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) { $url = substr ($url, 0, -1); // chop off slash } $url .= '/index.php'; ob_end_clean(); //delete the buffer header(:location: $url"); exit(); } else { // no match made echo '<p> >font color="red"size="+1"> Either the user name and password are not correct or you have not activated your account. </font></p>'; } mysql_close(); } ?> <h1>Login</h1> <p> your browser must allow cookies to log in.</p> <form action="login.php" method="post"> <fieldset> <p><b>User name: <input type="text" name="username" size="20" maxlength="20" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?> /></p> <p><b> Password: <input type="password" name="password" size="20" maxlength="20" /></p> <div> align="center"><input type="submit" name="submit" value="Login" /></div> <input type="hidden" name="submitted" value="TRUE" /> </fieldset> </form> <? include("footer.php"); ?> |