Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
This is all simple debugging. I would hope you could figure out what to do next. The query is failing because there are no IDs identified. That would indicate to me that the $deleteAry may have no values. You should have picked up on that previously since the delete query was already echo'd to the page. Try echoing count($deleteAry) to the page to verify it has values. If it does, then do a print_r($deleteAry) to see if it has the keys/values that you expect.
-
Echo the delete query to the page $query = "DELETE FROM roms WHERE r_id IN (" .implode(',', array_keys($deleteAry)) . ")"; echo $query; //$result = mysql_query($query) or die(mysql_error());
-
Ah, hell Change this while($row = mysql_fetch_assoc()) To this while($row = mysql_fetch_assoc($result))
-
Because you didn't specify the above correctly. The "method" I provided will work. YOU should have been able to modify it for your particular needs. Looking at the structure a little closer I think this is what you need. If not, YOU need to take some responsibility to understand the structure and modify it accordingly. $array1['articles'][0] = $array2['articles'][0];
-
$array1[0] = $array2[0];
-
$start_ts = strtotime($row['Applied']); // when process started $end_ts = strtotime($row['Approval']); // when process finished $date_diff = ($end_ts - $start_ts); $Approval = ($date_diff>0) ? floor($date_diff/ (60*60*24)) : ''; // days difference from start to finish
-
Then I would have to assume you have no matching records to the initial SELECT query. Add this after the first query is run echo "Records returned from SELECT query: " . mysql_num_rows($result) . "<br>\n";
-
That' my mistake. Use the $query variable in the mysql_query() function. Wrong $result = mysql_query($result) or die(mysql_error()); Right $result = mysql_query($query) or die(mysql_error()); You need to make the change on the first line of code as well as the line I commented towards the bottom
-
Not tested, so there may be syntax errors, but I comment out the line that would actually do the delete so there is no harm in running it to test. I also added code to see the results before actually executing the delete operation. Once you fix any syntax errors and are confident of the results, uncomment the line that does the actual delete operation. <?php //Get list of all records $query = "SELECT id, name FROM games"; $result = mysql_query($result) or die(mysql_error()); $saveAry = array(); $deleteAry = array(); $saveHTML = ''; $deleteHTML = ''; //Process records into save/delete lists based upon duplicate names while($row = mysql_fetch_assoc()) { if(!in_array($row['name'], $saveAry)) { $saveAry[$row['id']] = $row['name']; $saveHTML .= "<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>\n"; } else { $deleteAry[$row['id']] = $row['name']; $deleteHTML .= "<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>\n"; } } $query = "DELETE FROM games WHERE id IN (" .implode(',', array_keys($deleteAry)) . ")"; //$result = mysql_query($result) or die(mysql_error()); //RUN THE SCRIPT WITH THE LINE ABOVE COMMENTED OUT TO TEST THE RESULTS //ONCE YOU ARE SATISFIED WITH THE RESULTS RUN AGAIN WITH THE LINE UNCOMMENTED echo "<b>Delete Query:</b><br>$query<br>\n"; echo "<table>\n"; echo "<tr><th colspan=\"2\">SAVED RECORDS</th></tr>\n"; echo $saveHTML; echo "<tr><th colspan=\"2\">DELETED RECORDS</th></tr>\n"; echo $deleteHTML; echo "</table>\n"; ?>
-
Give me a few minutes and I'll give you a script. I hope all the records have a unique ID.
-
You don't. If you want data from ALL the records, then you select all the records. It is a simple process to filter out the unique values in a particular field in the processing logic. however, I'm a little confused. You say So, if these were in error, why do you need the data from these records, but not the names. Seems like you would want to run a query to remove the records in error.
-
Well, think about it for a moment. If you have 10 records per page and you have 21 records, the result would be: 21 / 10 = 2.1 So, if you have 21 records would you need tow pages (i.e. round()] or would you need three pages [i.e. ceil()]?
-
Food for thought: Although it might be a little more work, PHP has a built in constant for the "directory separator" characters (aptly named DIRECTORY_SEPARATOR). The main advantage, in my opinion, is that it will use the correct directory separator based upon the platform you are using which makes portability much easier. Although, since you say that this is a windows machine, that may not be important to you. But, it does have the added benefit of not having to worry about the backslash being interpreted as an escape character. Also, even though I use that constant frequently in my code, the full name is a little long. So, I typically define a variable using the constant and then use the variable in my code. Example: $DS = DIRECTORY_SEPARATOR; $fullpath = $rootpath . $ds . $foldername;
-
Seriously? You want to loop through the entire string instead of running a simple regex? The function I provided will return the correct result after only one line of code if there are any matches over the minimum length. The remaining lines are only there if it needs to check for the longest match less than the minimum. And the majority of that code is comments
-
Replica of the Previous and Next day button of MS Outlook
Psycho replied to kamal213's topic in PHP Coding Help
function diaryHrefFromTimestamp($timestamp) { $day = date('d', $timestamp); $month = date('m', $timestamp); $year = date('Y', $timestamp); return "diary.php?&day={$day}&month={$month}&year={$year}&v=true"; } //Get vars from URL $day = $_GET['day']; $month = $_GET['month']; $year = $_GET['year']; //Create timestamps for prev/next days $prevDayTimestamp = strtotime("$day-$month-$year -1 day"); $nextDayTimestamp = strtotime("$day-$month-$year +1 day"); //Create href values for prev/next links $prevDayHref = diaryHrefFromTimestamp($prevDayTimestamp); $nextDayHref = diaryHrefFromTimestamp($nextDayTimestamp); echo "<a href='{$prevDayHref}'>Previous</a>\n"; echo "<a href='{$nextDayHref}'>Next</a>\n"; If the date passed in the URL was today's date the output from the above would be <a href='diary.php?&day=31&month=05&year=2011&v=true'>Previous</a> <a href='diary.php?&day=02&month=06&year=2011&v=true'>Next</a> -
Here is a function that should do exactly as you want function getParagraph($input, $minLength) { //Check for 1st paragraph of minimum length if(preg_match("#<p[^>]*>(.{{$minLength},})</p>#i", $input, $match)) { //Return 1st para matching min length, if found return $match[1]; } //No para of min length found, Check for any paragraphs preg_match_all("#<p[^>]*>(.*?)</p>#i", $input, $matches); if(count($matches)<0) { //No pragraphs found return false; } //Find longest paragraph and return it $longestPara = ''; foreach($matches[1] as $para) { if(strlen($para) > strlen($longestPara)) { $longestPara = $para; } } return $longestPara; } //Usage echo getParagraph($text, 30);
-
This will return the first paragraph that is at least 30 characters. // $text is the string to be searched //If this is a web page then I would assume you are using something like: // $text = file_get_contents('http://somedomain.com/somefile.htm'); preg_match("#<p[^>]*>(.{30,})</p>#i", $text, $match); $firstParagraph30orMoreCharacters = $match[1]; Edit: just realized from your first past that if there is no para 30 or more characters you need the longest of the ones that do exist. Give me a few minutes.
-
Replica of the Previous and Next day button of MS Outlook
Psycho replied to kamal213's topic in PHP Coding Help
OK, so the diary page is accessed via a link. So, when the user clicks a date in the calendar to open the diary I would assume that there are some parameters included in the URL of that link to specify what day is supposed to be displayed in the diary (so you WOULD be sending data to the diary page). Otherwise, how does the diary page know what day to display? I would guess the links in the calendar might look something like: <a href="diary.php?date=20110601">June 6</a> We would need to see what the format of the parameters are that you are passing on the query string. From that it would be very easy to create Next/Prev links in the diary page. -
Say what? You are creating multiple sets of fields to edit each record, but you are not providing any reference in those fields to be able to determine which record each is for. And, you have a lot of code that makes no sense whatsoever. For example: if (isset($_SESSION['user_id'])) { } That does absolutely nothing! if (checkAdmin()) { Before that IF statement is all the "update" logic and after it comes the HTML output. That doesn't seem right. That means if a user is not an admin you want them to be able to make the updates but not see the form. You should probably have a checkAdmin() check at the top of the page. If it fails then send them to another page or display an error message. Not to mention you have a ton of invalid HTML in your code: giving multiple elements the same ID, not setting the type on input fields, etc., etc. This was all coded on-the-fly and untested so I am sure there are some errors. <?php include 'dbc.php'; page_protect(); company(); if (!checkAdmin()) { exit(); } //Check if form was submitted if (isset($_POST['submit'])) { //Define values common to all records $SentOutDate = date("y.m.d H:i:s"); $SentOutBy = $_SESSION['user_id']; foreach($_POST['SentOut'] as $IssueNum) { //Create and run update queries $StaffMember = mysql_real_escape_string(trim($_POST['StaffMember'][$IssueNum])); $referrer = mysql_real_escape_string(trim($_POST['referrer'][$IssueNum])); $referred = mysql_real_escape_string(trim($_POST['referred'][$IssueNum])); $query = "UPDATE `Referrer` (StaffMember, referer, referred, SentOut, SentOutDate, SentOutBy) VALUES ('$StaffMember', '$referrer', '$referred', '1', '$SentOutDate', '$SentOutBy') WHERE IssueNum= '{$IssueNum}'"; mysql_query($query) or die (mysql_error()); } } //Create and run query to generate form fields $query = "SELECT * FROM Referrer WHERE SentOut='0'"; $result = mysql_query($query); if(!$result) { $formFields .= "<tr><td colspan=\"5\">"; $formFields .= "There was an error running the query<br><br>\n"; $formFields .= "Query: {$query}<br>\n"; $formFields .= "Error: " . mysql_error(); $formFields .= "</td><tr>"; } elseif(mysql_num_rows($result)<1) { $formFields .= "<tr><td colspan=\"5\">There were no results.</td><tr>"; } else { while ($row = mysql_fetch_assoc($result)) { $id = $row['IssueNum']; $formFields .= "<tr> \n"; $formFields .= "<td><h3 class=\"Text3\"><input type=\"text\" name=\"Referrerid[]\" id=\"Referrerid_{$id}\"size=\"4\" value=\"{$id}\" /></h3></td>\n"; $formFields .= "<td><h3 class=\"Text3\"><input type=\"text\" name=\"StaffMember[{$id}]\" id=\"StaffMember_{$id}\" size=\"4\" value=\"{$row['StaffMember']}\" /></h3></td>\n"; $formFields .= "<td><h3 class=\"Text3\"><input type=\"text\" name=\"referrer[{$id}]\" id=\"referrer_{$id}\" value=\"{$rows['referer']}\" /></h3></td>\n"; $formFields .= "<td><h3 class=\"Text3\"><input type=\"text\" name=\"referred[{$id}]\" id=\"referred_{$id}\" value=\"{$row['referred']}\" /></h3></td>\n"; $formFields .= "<td><h3 class=\"Text3\"><input type=\"checkbox\" name=\"SentOut[]\" value=\"{$id}\" id=\"IssueNum_{$id}\"></h3></td>\n"; $formFields .= "</tr>\n"; } } ?> <html> <head> <title>Book Off Holiday</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script src="php_calendar/scripts.js" type="text/javascript"></script> <link href="styles.css" rel="stylesheet" type="text/css"> </head> <body> <form name="form" action="SendReferrers.php" method="post"> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td colspan="3"> </td> </tr> <td width="160" valign="top"> <a href="admin.php">Admin CP </a> </td> <td width="732" valign="top"> <p><h3 class="titlehdr">New KPI</h3> <table width="300px" border="0" align="Centre" cellpadding="2" cellspacing="0"> <tr bgcolor="#000050"> <td width="20px"><h3 class="Text2">Referrer ID</h3></td> <td width="20px"><h3 class="Text2">Staff Member</h3></td> <td width="20px"><h3 class="Text2">referrer</h3></td> <td width="20px"><h3 class="Text2">referred</h3></td> <td width="40px"><h3 class="Text2">Sent Out</h3></td> </tr> <?php echo $formFields; ?> </table> <input name="submit" type="submit" id="submit" value="Create"> </td> </tr> </table> </form> </body> </html>
-
Your use of terminology will cause confusion. A "localhost" is not a webserver. Every machine has a "localhost" it is simply an internal domain name pointing the machine back to itself. When you use localhost in the URL you are simply making an http (usually) request back to the pc itself. It is no different than using the machines name or IP address. For example you can ping a cmputer back to itself using localhost even if it has no web server installed. And, you can have a webserver (which uses localhost) which is not free.
-
You HAVE to have a webserver installed. If you try to open a file with PHP code in it directly in your web browser it has no clue how to parse PHP code. So, it just triesd to renders it all as HTML. You have to request the page from a web server. THe server then sees you want a PHP page. It takes the page and processes it then sends the result (HTML code) to your browser. Once you have a webserver installed (check out XAMPP) you can put the php files into the htdocs folder on your PC. Then you could access them via http://localhost/filename.php
-
I think we need to see your form. I don't think this will work as you need it based on this statement The problem is that only ckeckboxes that are checked are passed in the POST data. If you are naming you fields as arrays with empty indexes so that they are automatically numerically indexed you will not be able to associate the checkboxes with the corresponding fields. For example, if you had five checkboxes and the user checked boxes 1, 3 & 5 they would be posted as an array with indexes of 0, 1, & 2. You should specify the value of the checkboxes as the primary index value of the records. Then in the input fields that correspond to each checkbox, name the fields as an array but explicitly assign the index for the arrays with the primary index value. You can then determine which checkboxes were checked (by their value) and then associate that with the appropriate fields with the corresponding values.
-
Change this $row_news = mysql_fetch_array($query); $news = array(); while($row = mysql_fetch_assoc($row_news)) To this $result = mysql_query($query) or die(mysql_error()); $news = array(); while($row = mysql_fetch_assoc($result))
-
Dump the results for all three records into an array, then use the array for the output <?php $query = "SELECT * FROM news WHERE published = '1' ORDER by id DESC LIMIT 3"; $row_news = mysql_fetch_array($query); $news = array(); while($row = mysql_fetch_assoc($row_news)) { $news[] = $row; } ?> <div id="myTabs"> <ul> <li><a href="#firsttab"><?php echo $news[0]['shorttitle']; ?></a></li> <li><a href="#secondtab"><?php echo $news[1]['shorttitle']; ?></a></li> <li id="last"><a href="#thirdtab"><?php echo $news[2]['shorttitle']; ?></a></li> </ul> <div id="firsttab" class="tab_content"> <div class="rafat"> <img src="<?php echo $news[0]['image']; ?>" /> <p><?php echo $news[0]['shortstory']; ?></p> </div> </div> <div id="secondtab" class="tab_content"> <div class="rafat"> <img src="<?php echo $news[1]['image']; ?>" /> <p><?php echo $news[1]['shortstory']; ?></p> </div> </div> <div id="thirdtab" class="tab_content"> <div class="rafat"> <img src="<?php echo $news[2]['image']; ?>" /> <p><?php echo $news[2]['shortstory']; ?></p> </div> </div>
-
You have your logic backwards. You have to check if there were results BEFORE processing the results. Although, I have a hard time believing that you are getting no results and no errors. <?php //Connect to DB mysql_connect ("localhost", "John","Harley08") or die (mysql_error()); mysql_select_db ("Customers"); //Parse user input and run query $term = mysql_real_escape_string(trim($_POST['term'])); $query = "SELECT * FROM storage WHERE box_number = '$term'"; $result = mysql_query($query); //Check results of query if (!$result) { //There was an error running the query echo "There was an error running the query<br><br>\n"; echo "Query:<br>{$query}<br><br>\n"; echo "Error:<br>" . mysql_erro(); } else if(mysql_num_rows($sql) < 1) { //No records returned echo 'No Boxes available please use your back button to select a new box.'; } else { //There were records returned, display them while ($row = mysql_fetch_array($sql)) { echo "box_num: {$row['box_number']}<br>\n"; echo "dept: {$row['Department']}<br>\n"; echo "company: {$row['Company']}<br>\n"; echo "status: {$row['status']}<br>\n"; echo "location: {$row['location']}<br>\n"; echo "description: {$row['box_desc']}<br><br>\n"; } } ?>