Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,448
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. SELECT Name, SUM(Amount) as amt FROM your_table GROUP BY Name
  2. rather than adding your search/sort get parameters explicitly in each link, you should build a variable that contains the search/sort get parameters in one place and add that variable into each link (DRY - Don't Repeat Yourself), or even better yet, since the search/sort are already $_GET parameters (or they should be), just use http_build_query() to add your pn=x get parameter in the pagination logic into any existing get parameters without caring what any other code in your application might be setting as get parameters.
  3. register_globals have been removed in php5.4. so, time to start fixing your code to use the $_GET, $_POST, $_FILES, $_COOKIE, and $_SESSION superglobal arrays, that were introduced in php4.2 (in the year 2002) as replacements for what the register_globals hack did to php.
  4. if the page is being displayed at all, but the data is missing, it's something to do with the code on the page or with the GET parameters in the links you are producing. what have you done to pin down at what point your code and data are doing what you expect and at what point they are not? are the links correct? are there any php detected errors when you turn php's error reporting full on? what does your error checking logic in your code tell you? if you want us to help. you will need to post the relevant code needed to reproduce the problem so that someone could see what it is supposed to be doing to be able to suggest possible things to try to determine why it isn't working.
  5. presumably your names are strings. you must enclose string data by single-quotes inside the query statement so that is treated as a string instead of a mysql keyword or column name. if you had error checking logic in your code, it would be reporting an undefined column name that is the same as the first name's value. in your hard-coded query - Name = 'ruth'" you have single-quotes around the string value. the query syntax you build where the value comes from a php variable must have the same query syntax.
  6. the error(s) you are getting are very common, probably the first or second most common php/mysql error. if you search for the body of that error message, you will find what it means and how to determine what is causing it.
  7. the code you have posted is inefficient. you are evaluating the array string index multiple times and you are looping over 10 elements even if they don't exist. if the code building the $_SESSION variable is similar to what you have posted, i can see why there might be a noticeable lag due to the menus. you need to make the $_SESSION['id_d'] into an array. then you can simply loop over that array using a foreach loop. the LINK part of the code you posted would become something like - <!------------LINK_START--------------> <?php foreach($_SESSION['id_d'] as $id_division_menu){ if($id_division_menu !== 'd'){ include $_SERVER['DOCUMENT_ROOT'].'/pwf/data/sp_services_content_navigation_division.inc'; if ($total > 0) { echo "<ul>"; include $_SERVER['DOCUMENT_ROOT'].'/pwf/data/sp_services_content_navigation_module.inc'; echo "</ul>"; } } echo "</li>"; } ?> <!------------LINK_END--------------> including the same file multiple times is also inefficient. you should include each of them once (as a template into a php variable), then simply evaluate the template each time through the loop.
  8. for the versions you listed, i would start with the php installation instructions for Apache 1.3 in the php.net documentation. also, don't copy files around to different locations. leave all files in their original locations. you may need to add the php installation folder to your window's PATH statement (restart your computer afterwards.) lastly, after restarting your web server to get any changes made to the configuration to take effect, check the web server error log to see if it provides any helpful information.
  9. if you are getting the data for the tool tip display using ajax, you would submit the category_id value and use it in a WHERE clause in the query. if you are producing all the tool tips and outputting the information all when the page is requested, you would use a JOIN query to get the relevant data you need from both tables at one time.
  10. i had actually typed a line, but removed it before posting the reply above - if you are trying to retrieve a specific row from a database table, you would retrieve that row using its id or using some other identifying means. how do you know you want to retrieve the row that has the Cost3 value in it? what input does your code have that determines what row and what column you want to find?
  11. as a continuation of the above replay, there's another (good) reason to NOT use mysql_result() at all. the mysql_ database library is depreciated in php5.5 and should no longer be used and there's no equivalent for the mysql_result() statement in the the mysqli or PDO database libraries that are the replacement for the mysql_ library.
  12. you should not be trying to access a specific row number in a result set, because it might not exist (your current error, rows start at zero) and there's no guarantee that any row number will always be the data you expect (deleting rows from a table and not using any ORDER BY in your query will result in different data being in any row number in a result set.) your database loop code, wherever you learned it, is inefficient for three reasons - 1) mysql_result() is the slowest way of accessing data because it performs a dataseek followed by a read operation, 2) you are already fetching the row into a variable, using mysql_result() on top of that isn't necessary. just use the fetched data. 3) using a do/while loop takes more code because you must pre-fetch the first row from the result set and you must also add more logic to test if there are any rows at all to avoid errors when accessing non-existent data. you need to (always) use a while(){} loop to iterate over multiple rows from a query - $query = " your query statement here ..."; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)){ code that uses the fetched data in $row .. } i can guarantee that this method won't ever attempt to access rows that don't exist in the result set. it will loop over only the rows that do exist, even if there are zero rows in the result set (in which case it will skip over the loop.)
  13. in programming, AND is a logical operator. name AND value produces the boolean result of the column value in name AND'ed with the column value in value. to make a list of columns to SELECT, you would separate them with commas ,
  14. you would use a BLOB data type for binary data.
  15. you seem to be randomly changing your code without any reason. when you do make a change to your code, you must know why you are changing it. up until post #10, the values ( ... ) part of your query had the correct syntax. in post #10, you removed that part of your query and in all the posts since then, you have left off the closing ). you must actually know the meaning of each line of code you are writing. the most commonly used syntax for an insert query is - INSERT INTO your_table_name (your_column1, your_column2, your_column3, ...) VALUES ('your_string_value1','your_string_value2','your_string_value3',...) it's your job as a programmer to make sure that your php code is producing a database query that has the correct syntax. also, since you are not using prepared query statements to protect against sql injection, you must use your database library's escape function on each piece of string data (the values enclosed by single-quotes in the query) in the query. for the mysql_ database library, this would be the mysql_real_escape_string() function. for numerical values (int, decimal, float,...) that would not be used as a piece of string data in the query (these would not enclosed by single-quotes), you need to validate/cast them as the appropriate numerical data type. lastly, the mysql_ database library is depreciated starting in php 5.5 and any new code should be written using either the mysqli_ or PDO database libraries.
  16. is there a (good) reason you are trying to use versions of all three of those programs that are so far out of date that no one likely even remembers the ins and outs of getting them to work together? you should be using the latest versions of all of those programs. there are also all-in-one WAMP packages that will install apache/mysql/php for you.
  17. when a query doesn't match any rows (the code branch in post #9) it isn't an error and mysql_error() won't contain anything. if that's the code branch that is returning the false value, then the username is likely empty. see AbraCadaver's post above for the most likely reason why. if you set php's error_reporting to E_ALL and display_errors to ON, you will get php to help you by pointing out things like variables that don't exist.
  18. your code/server may be buffering output then redirecting, thereby discarding any output. add a die; statement after the echo mysql_error(); to stop the code from running at that point.
  19. you need to modify the database class to use mysqli statements, not replace the database class with an instance of the mysqli class. what was the original code for the database class? perhaps it is already using mysqli or pdo and you don't need to do anything?
  20. the bit of code you pinpointed - if (!$result) ... means that the query failed due to an error. for debugging purposes, echo mysql_error() to find out why it failed.
  21. assuming your array of data is in $data, a solution using a table rowspan attribute and a little math/array indexing - $rowspan = 1; $output = array(); // where to build the output at $heading = ''; foreach($data as $round=>$arr){ $heading .= "<th>Round $round</th>"; // make some headings for each round if($round !=1){ // do only after the first round $rowspan *= 2; // double the rowspan - 1,2,4,8, } foreach($arr as $key=>$value){ // loop over all the data within each round $index = $key * $rowspan; // line number to add the output at if(!isset($output[$index])){$output[$index] = '<tr>';} // start each line $output[$index] .= "<td rowspan='$rowspan'>{$value['c1']} - {$value['s1']}<br>{$value['c2']} - {$value['s2']}</td>"; } } // display the result echo "<table border='1'>\n"; // no css for example purposes only echo "<tr>$heading</tr>\n"; // the heading row echo implode("</tr>\n",$output); // terminate each line and implode into a string echo "</tr>\n"; // terminate last line echo "</table>";
  22. your PassHash::hash() method is used to hash the initial password. to test if an entered password matches the stored hashed value, you need to use the check_password() method (kind of why the comment says // this will be used to compare a password against a hash) to do this, your code must run a query that matches the username, then retrieve the `password` column for that username, and use the `password` column value and the entered password as parameters to the check_password() method.
  23. you already posted this question on this forum, about three minutes ago
  24. the third paragraph were suggestions on how to simplify the logic. you have to fix the problems mentioned in the first two paragraphs to even get the code to retrieve the data from a table and loop over it.
  25. your ->getRow() method returns one row from the result set each time it is called. you are then looping over that one row in the foreach($result as $row){} loop. $row is not each row, but it is each column value in a row. your for($j=0; $j<$num_fields; $j++){} loop is looping over each character of each column value from the first row in the result set. your code is also looping over the number of columns (the first for(){} loop), then looping over the rows (the foreach(){} loop, assuming it was actually rows your were looping over), then looping over the number of columns again (the second for(){} loop.) once you have your code looping over each row from the result set, you don't need most of the code you have posted. you can use array_map() to operated on each column/field in the $row array and you don't need to get a count of the columns in order to loop over the columns because you don't need to loop over the columns at all. you can simply implode() the data to make the values ( ... ) statement.
×
×
  • 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.