Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,450
  • Joined

  • Days Won

    175

Everything posted by mac_gyver

  1. you would put the sum logic into the existing query (2nd one in the posted code), so that it would produce a total for each row.
  2. it's likely that the actual data you are getting from your database query isn't what it looks like or you have a variable scope problem. when you printed the $start_point value, where exactly in your code did you do that and what does using var_dump($start_point);, right before the code you have shown us, give for the value?
  3. your online test page stops producing output after the <body> tag. that's a sign you are getting a fatal php runtime error prior to any php echo statements. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects? edit: especially since your database table name is not calendar.
  4. in programming, you need to be careful what wording you use. when you mentioned inserting data, that was taken to mean insert data into a database table. what you actually meant is displaying data in the calendar you are outputting on the web page. there's no inserting involved, you are taking data you have at some point in your code and producing html that displays that data the way you want it to be on a web page. using the mysqli code converter to get your code to use the mysqli functions isn't going to get you much sympathy, because it produces messy, lazy, error prone code. learn to actually use the mysqli or PDO statements and rewrite the code yourself. there's a minor problem with the (test) $entries data that's in the code now, in that the data you eventually retrieve from your database table and put into $entries will have leading zero's on the month and day fields and will have - separator characters. by default, unless you do more work to get there, the format will be YYYY-MM-DD. the line of code to build the corresponding $dateKey value will be - $dateKey = sprintf('%04d-%02d-%02d',$currYear,$currMonth,$d); if you change the format of the test data in $entries and the above line of code, this should get your code to display your test data. the next task would be to retrieve the event data from your database table, that matches the $currYear, $currMonth values, and store it into the $entries array in the necessary format.
  5. besides listing what you want, do you have a specific programming question or a problem you need help with?
  6. some points that hopefully will help - 1) you should be development and testing code on a localhost development system, where you can easily set php's error_reporting to E_ALL and display_errors to ON in the php.ini so that ALL the errors php detects will be reported and displayed. the last problem pointed out, about the syntax of using a php array variable inside a string, in your main file, would have been producing php parse/syntax errors, that will only show up if you have php's error_reporting/display_errors set in the php.ini. 2) the ->get_result() method is specific to a certain type of underlying database client driver being used (mysqlnd) and may be producing a php run-time error (which is why, again, you should be developing and debugging code on a system that has php's error_reporting/display_errors set so that php will help you.) the example code i am posting below uses another mysqlnd specific statement, ->fetch_all(), that may not work either. if these two statements produce undefined method php errors, the code using them will need to be rewritten or more simply, if it is an option available to you, use the PDO database statements as they are much easier to use. 3) in general, the code producing or containing any of your your html/css/javascript (client-side) markup should be separate from the portion of your code that knows how to retrieve data from the database. the code producing the html should have no database specific statements in it. this will allow you to more easily change the type of database statements being used or to delegate and divide the work among others. you would retrieve the data from your database and store it in a php array variable, then simply loop over that variable in place of the while(){} loop you have now that's making use of the msyqli fetch statement. 4) your code producing the table output can and should be written to be general purpose as well, so that it can display any amount of columns and rows that the query retrieves. a rearrangement of your code that demonstrates (untested) these points (and while i was doing this i noticed an ->execute() method statement that wasn't, which would have been producing another php run time error) - <?php $mysqli = new mysqli("localhost", "guestuser", "guestuser", "SMQ"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } $validScott = $_GET['scott']; $query = 'SELECT Scott, Den, Color, Cond, 70, 70J, 75, 75J, 80, 80J, 85, 85J, 90, 90J, 95, 95J, P98, 98J, 100 FROM SMQSQL WHERE Scott = ?'; $stmt = $mysqli->prepare($query); $stmt->bind_param('s',$validScott); $stmt->execute(); $result = $stmt->get_result(); $results = $result->fetch_all(MYSQLI_ASSOC); // if the ->get_result() method is present, the ->fetch_all() method is also available, otherwise you will need to bind the result from the query and fetch it or use the more friendly PDO database library $stmt->close(); // get data for table heading $finfo = $result->fetch_fields(); $fields = array(); foreach ($finfo as $val){ $fields[] = $val->name; } // the above php code is the business logic, that knows what to do on the page and how to get data from the database // the following code, is the presentation logic, that knows how to produce the output on the page $heading = "<tr><td>".implode("</td><td>",$fields)."</td></tr>"; $queryResult = ''; foreach($results as $row){ $queryResult .= "<tr><td>".implode("</td><td>",$row)."</td></tr>"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/url] <html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml">[/url] <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Online SMQ</title> </head> <body> <form name="searchForm" method="GET" action="#"> <input type="text" name="scott"> <input type="submit" name="submit" value="Search"> </form> <p> <table> <?php echo $heading; ?> <?php echo $queryResult; ?> </table> </body> </html>
  7. @subhomoy, the following paypal link describes the process you will need to use for the IPN information - https://www.paypal.com/in/cgi-bin/webscr?cmd=p/acc/ipn-info-outside as the last step, to finally record the payment as being successful/complete for a user, for a specific order he has made, you need to check the payment_status value, which is something that fastsol included in his post. in fact, since you are not using or storing that value, it's possible that your duplicate data in the payment table has two different statuses. you may want to log each set of data your ipn script receives so that you can detect nefarious activity. next, just because the data your ipn script receives is coming from paypal, doesn't mean it is safe. since you appear to be using the PDO database class, you should be using prepared queries. lastly, your code appears to be making a database connection for each query you are running - $pdo->connect()->query(...). if that is the case, you should only make ONE database connection and use that connection throughout your script.
  8. your page is being requested twice. you would need to do some debugging to find out way. some causes are url rewriting you are doing for your site or even how your web hosting is passing the request to the server where your web site is hosted. however, you cannot prevent duplicate requests in all cases and you need to enforce uniqueness within your application to filter out duplicates. your payment table should be setup with a unique composite key that prevents duplicate transition id/user id combinations. next, when dealing with real money or any sort of data that you need to have the ability to audit the data, you should not simply add the amount to a sum in a column. you should treat this as a deposit/debit account, where you use a query to sum up the transactions to determine the current amount in the account each time you need the current total.
  9. the second thread you started for this in the ajax forum section has been removed. there's no evidence the problem is in any of the client-side ajax code and if debugging this should show that's where the problem is at, this thread can be moved to the appropriate forum section.
  10. this is actually about the same logic as in your last post, but eliminates the extra code at the end to finish the last day of the week - <?php $fd = array(); $fd[0] = array('f'=>"8:00 AM",'t'=>"4:30 PM"); $fd[1] = array('f'=>"8:00 AM",'t'=>"4:30 PM"); $fd[2] = array('f'=>"",'t'=>""); $fd[3] = array('f'=>"9:00 AM",'t'=>"1:00 PM"); $fd[4] = array('f'=>"",'t'=>""); $fd[5] = array('f'=>"9:00 AM",'t'=>"1:00 PM"); $fd[6] = array('f'=>"",'t'=>""); $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",''); // the extra value on the end processes the last day without repeating any logic $last_from = null; $last_to = null; $output = ''; $last = count($WeekDays)-1; foreach($WeekDays as $key=>$day){ if($key == $last || $last_from !== $fd[$key]['f'] || $last_to !== $fd[$key]['t']){ // it's past the end or the from/to is not-equal to last values if($last_from !== null){ // not the first section, build the section that just ended $end_key = $key-1; $op = ($fd[$end_key]['f'] != '') ? "{$fd[$end_key]['f']} to {$fd[$end_key]['t']}" : 'Closed'; $dy = ($start_day == $WeekDays[$end_key]) ? $start_day : "$start_day - {$WeekDays[$end_key]}"; $output .= "$dy $op<br>"; } // start a new section $last_from = isset($fd[$key]) ? $fd[$key]['f'] : ''; $last_to = isset($fd[$key]) ? $fd[$key]['t'] : ''; // remember the new values $start_day = $day; } } echo $output; the data array is organized differently to make the references clearer. you can change the form field names to submit the data as shown or change the references in the code to match your current form field names.
  11. this thread is also the third time the OP posted this. merging with the other thread that has replies. post #5 and down is from the later thread.
  12. another advantage of the method mentioned by Psycho, is you can just create a view to your table that only shows the non-deleted rows, then just use the view name as the table name in any query where you want to exclude the deleted rows.
  13. please see the pinned/sticky post at the top of the forum section you posted this in.
  14. okay, what's your code that attempts to do this? you started the thread with a general fishing question. you got replies mentioning ways you could catch a fish. we are not here to do the fishing for you, especially since the only specific information you have posted is a table name and one column name.
  15. if the tables have a defined relationship (we/i don't visit unknown links) that you are trying to join together to return the correct related data for each row, you need to get the joined query to work correctly first before you try to add any conditions to filter the results. i also recommend putting the join conditions with the join terms, not in the where clause. this a rearrangement only of the first posted query (doesn't attempt to fix anything about the logic) - FROM `activepropertylist` A JOIN `RegionEANHotelIDMapping` RM ON A.EANHotelID = RM.EANHotelID JOIN `ParentRegionList` R ON RM.RegionID = R.RegionID WHERE MATCH(City, RegionName) AGAINST ('hervey bay' IN BOOLEAN MODE) you would only use a UNION query for similar, not related, data in multiple tables (you must select the same number and type of columns in each query and the column names from the first query is what is used for all the data.) showing some sample data from each table, what relationship there is between the tables, what column(s) from each table you want to filter, and what result you expect from that sample data would be the quickest way of solving the puzzle.
  16. afai can determine, to make this work, using both an exact phrase and a wild-card ending, you could use either of the following methods - 1) all but the last word entered, even if there is only one word, are split from the submitted search string and become the exact phrase, then the last/partial word, if there's more than one word, would be added to the search term as +partialwordhere*. for your example, the search $string would be - "Newcastle upon" +ty* edit: if there is only one word/partial word, this should not be used as an exact phrase, only as the +partialwordhere*. this however will match things where the partial word match exists anywhere, not just immediately following the exact phrase. the suggestion found on the web is to add a HAVING clause with a LIKE comparison that matches the complete phrase that was entered - HAVING City LIKE 'Newcastle upon ty%' 2) this is a variation on #1, without using the exact phrase at all. you would split the words and make each one required, with the last one adding the wild card. for your example, the search $string would be - +Newcastle +upon +ty*. you would still also use the HAVING clause as described above to filter the resultant rows to those that only have the complete phrase in them.
  17. the rows per page would apply to how many gameweeks to display on one page. if set to a one, only one gameweek would be displayed per page and the pagination links would become gameweek selectors rather than page selectors. next, do you want to display all information for the games on the selected gameweek or do you want to paginate that information too (assuming there are a large enough number of games in any gameweek to require pagination)?
  18. how do you know which queries are to use the second database connection and if possible can you add some unique table prefix to indicate this? one way would be to write a function/class to abstract the database access, that a simple search/replace can change all the msyql_query() statements to use, that would run the query using the correct connection based on something unique in the query statement. are any of your existing mysql_query() statements inside of your own user functions/classes? edit: answer you probably don't want to hear - is a better way of going about implementing it. yes, if you have a design that has hundreds of files, where database queries exist in a majority of those files, it might be time to rewrite the code to use one common set of code that dynamically produces the pages of the site.
  19. using pagination, with a 'rows per page' value of one, and ordering the rows in the query by gameweek, would give the result you need, especially for the previous/next links, and would end up working for any number of games stored in the table.
  20. of the list of things that have been mentioned, which one(s) are you stuck on when you tried to do them? both of our replies mentioned calling your cal class? do you have code that does that? the code you posted only contains the definition of your cal class.
  21. in addition to what has already been mentioned, your code contains both the mysqli_ and mysql_ (no i) database functions (these cannot be mixed together on one database connection), so of course the code using the mysql_ (no i) functions is not working. you need to use all mysqli_ functions.
  22. the $pagenum variable doesn't exist. the ?pagenum parameter in the url would be available to the php code as $_GET['pagenum']
  23. in general, you wouldn't put derived values into a database, but assuming your code is just an example/exercise, you didn't show us the code that's making an instance of your cal class and calling the ->insert() method. also, you should not be using the msyql_ database functions because they are obsolete and will be removed in a future php version, which is interesting because at least one of your earlier threads in this forum was using the mysqli_ database functions.
  24. for your auto predict, it sounds like are asking about a wild card search, that starts with whatever has been entered upto that point, but should match anything after whatever has been entered. if so, you would add an * on the end of the search term. btw - this is all covered in the documentation, which jazzman posted a link to.
  25. the MATCH(city,Countryname) AGAINST ('South shields*' IN BOOLEAN MODE) term produces a relevancy score (a positive (true) value for matches, a zero for non-matches). you need to include this term in your SELECT term (give it an alias name of score) and then use ORDER BY score DESC in your query.
×
×
  • 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.