Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. either your php script is doing some processing that is taking a huge amount of memory or you have a logic error that is causing a loop to create variables/array data that consumes all available memory. for us to be able to help, you would need to post your script, from the first line (less any database credentials) up through the point where the error is occurring at and if the error is inside of a loop, post the code through to the end of that loop.
  2. @priyankagound - perhaps you missed this - NOTE: This topic is marked as solved and might not require further action
  3. @priyankagound, again, if you look at the thread, the OP already is doing that, and your reply has nothing to do with the problem of a database connection error.
  4. @priyankagound if you look at post #7 in this thread, you will see that the OP already did that. marking this thread as solved...
  5. if the only php error is the Notice: Undefined variable: dataString ..., that means you found and fixed whatever was causing the query to fail with an error, but now there are no rows in your database table.
  6. it was already mentioned where -
  7. unless you post the errors you got, no one here can help you with what the code might be doing on your server, with your data.
  8. given that your $fruitvegi array contains entries that have multiple words in them, your assignment isn't as simple as exploding the $sentence on the spaces and finding if any single word is in the $fruitvegi array. what is the actual statement of your assignment?
  9. that's because the query in your code in reply #5 doesn't contain the correct table name. the or die(mysql_error()) logic that you do have in the code in reply #5 on the end of the mysql_query() statement, needs to be in your current code to get your code to tell you why the query is failing.
  10. 1) you know, using the first letter of the word, which main element in $fruitvegi you need to look in. there's no need to scan through the entire array each time. 2) see Psycho's reply above about case-insensitive 3) what exact output are you trying to get (an example would be nice) and are you trying to get it for all words that are found or only the first one that is found?
  11. what does a sample of your data look like? without knowing what you are trying to find, baring an obvious error in your logic, we cannot possibly help you with the problem. btw - the problems you are having doing this (writing a bunch of code to accomplish finding a value) is why data is usually stored in a database and all you have to do is write and execute a query statement to find it.
  12. your goal is to create an INSERT INTO table_name (list of column names) VALUES (corresponding list of values) query for any table/data. the basic logic would be - function db_insert($table_name, $data){ $columns = array(); $values = array(); foreach($data as $key=>$value){ $columns[] = "`$key`"; $values[] = "'$value'"; // for simplicity, treat all data as a string (numerical data should not be handled this way, actual code left as a programming exercise for you to do) - string values need to be escaped using a method appropriate to the database library you are using } $query = "INSERT INTO `$table_name` (".implode(',',$columns).") VALUES (".implode(',',$values).")"; // run the query here using a method appropriate to the database library you are using } // example usage $some_data = array('column_name_a'=>'abc','column_name_b'=>123); // repeat for all columns you want in any INSERT query db_insert('some_table_name',$some_data);
  13. you can SELECT just about anything you want in a query.
  14. you didn't state if you are getting the echo "not set"; output? depending on that output, the troubleshooting is different - if you are getting the 'not set' message, it means your session id likely didn't match (most likely because the host-name/sub-doman in the url's changed.) if you are not getting the 'not set' message and nothing is displayed from the echo $_SESSION['pusername']; statement, it likely means that your code is accidentally overwriting the session variable.
  15. probably not back in June 2011 when this thread was started
  16. you have posted your series of questions on at least two php help sites, that i know of. you haven't gotten a solution yet because you have been throwing away the threads and starting new ones, rather than to stick with one thread and provide asked for, and needed information, that only you are aware of. i'm with Barand, bye, you have been repeatedly told the relationship between the tables is important, yet you specifically won't provide that information. for all we know, there's isn't anything that ties the data from one table to any other. you are just wasting your own and our time.
  17. a) STOP creating new threads for this problem. continue the same problem in your existing thread. b) you have been asked, repeatedly, to provide information about the relationship between your tables and to provide sample data and the result you expect from that data. if you cannot provide this information, no one can show you how to write the JOIN query using those tables. c) had you stuck with your very first thread, and provided the information in b), you would have solved this by now.
  18. or use echo $row[0]; since fetch_array() is being used.
  19. you are joining every row in each table to every row in all the other tables, because you are not specifying any relationship between the tables in the query. in one of your previous threads for this task, the relationship between the tables was mentioned. do you actually have any columns in the tables that relate a row in one table to a row in another table? if so, you must use that relationship in the JOIN's to match up the related information. if not, these tables don't belong in the same query, especially a query using JOINs. i also recommend that you clean up your column names/query (there's no need for you to type a wall of code like that) by doing two things - 1) in any table, your columns don't need a prefix with a portion of the table name. you know what table you are using at any time in any query. this would require that you rename your table columns, but will reduce the amount of typing and clutter in all your queries. 2) use table alias names in your query. here's the same query with these two changes (with the existing joins/conditions) - $sql="SELECT c.ID, c.Forename, c.Surname, c.Email, c.Mobile, c.HomeNum, c.AddressL1, c.AddressL2, c.AddressL3, c.Postcode, j.RefNum, m.Name as m_Name, j.Model, os.Name as os_Name, j.ReceivedBy, j.DateRec, j.FaultDesc, j.PassWinAdmin, j.DataRecYN, j.PowerSuppYN, js.Status FROM Customers c, Jobs j, Manufacturers m, OperatingSystems os, JobStatus js WHERE (c.ID LIKE '%$criteria%') OR ( c.Forename LIKE '%$criteria%') OR (c.Surname LIKE '%$criteria%') OR (c.Email LIKE '%$criteria%') OR (c.Mobile LIKE '%$criteria%') OR (c.HomeNum LIKE '%$criteria%') OR (c.AddressL1 LIKE '%$criteria%') OR (c.AddressL2 LIKE '%$criteria%') OR (c.AddressL3 LIKE '%$criteria%') OR (c.Postcode LIKE '%$criteria%') OR (j.RefNum LIKE '%$criteria%') OR (m.Name LIKE '%$criteria%') OR (j.Model LIKE '%$criteria%') OR (os.Name LIKE '%$criteria%') OR (j.ReceivedBy LIKE '%$criteria%') OR (j.DateRec LIKE '%$criteria%') OR (j.FaultDesc LIKE '%$criteria%') OR (j.PassWinAdmin LIKE '%$criteria%') OR (j.DataRecYN LIKE '%$criteria%') OR (j.PowerSuppYN LIKE '%$criteria%') ";
  20. there's nothing about the code you posted that would cause incorrectly repeated data to be output. its just looping over the rows from the result set. therefore, either your query is returning repeated data, some of your data stored in the database table actually contains the repeated data, the code you posted is inside of a loop, or the code you posted actually contains more code that what you showed. we are not you, nor are we standing right next to you. we only see the information you supply in your post. we don't know what your data is, what you saw that leads you to belove believe there's repeated output, or what the actual expected output is. if you want someone in a forum to help, you must supply information that they would need to be able to help you.
  21. your error reporting logic (the die() statement) needs to also display the query statement, in $sql, so that you can see what the query actually is (the id is likely empty.) you should not run queries inside of loops. your UPDATE query should update all the supplied columns/values in one query. also, once you fix the current problem, you should NOT be creating an instance of your db class every time you call one of your news methods. you are figuratively killing your database server by opening a connection on each method call and closing it when that method call ends. since your news class is dependent on the database class to function at all, you should create one instance of your database class in your main code and use dependency injection to make that one instance of the database class available inside the news class.
  22. wouldn't you just use conditional logic to test if each of those values is not an empty string to decide if you need to output each line?
  23. if you post an example showing what you want, i'm pretty sure someone might be able to figure out what you are asking. i for one don't see anything having to do with "labels", nor do i have any idea what you want to do based on which fields were filled in?
  24. @Irate any database close() statement just closes the database connection. that will have little affect on memory usage. any result sets that may have been retrieved and any follow on data produced from processing the result set(s) will still exist. as to your second statement, untyped variables have nothing at all to do with memory usage or how memory is managed. until the OP provides specific information about what his code is really doing leading up to the point where the memory error is occurring at, this thread is just for bumping up post counts. for all we know, he's dynamically producing images/graphs from the data.
  25. forget you ever saw the mysql_result() statement. it's the only database function that throws an error when there are zero rows in a result set. it also doesn't have any direct replacement in the database libraries that replace the mysql_ library, which is now depreciated and should not be used when writing new code. you should also never nest function calls, when any of the inner functions can fail due to an error. you must always test if a function worked or not before trying to use the data that function is expected to return. your code needs to - 1) use either the mysqli or PDO database libraries. 2) test if the query worked or failed before attempting to use the result from that query. also, what action do you want the code to take when the query fails due to an error? 3) test if the query actually matched any row(s) and take an appropriate action when it doesn't. what value do you want to return when the username doesn't exist, so that the calling code doesn't attempt to use a non-existent id value? 4) only after you have determined that the query ran without any errors and that it matched the one expected row, should you fetch (using an actual database _fetch_ statement) and return the id that the query found. edit: summery - the error you are getting could be due to the query failing or the query matching zero rows (the username variable doesn't contain anything or the value it does contain doesn't exist in the table), but the code is the minimal amount that just barely works when everything is perfect and doesn't tell you when, where, or why it didn't produce the expected result.
×
×
  • 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.