Jump to content

PFMaBiSmAd

Staff Alumni
  • Posts

    16,734
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by PFMaBiSmAd

  1. Age isn't a column. It is a calculated value assigned to an alias name. Use - HAVING age = 50
  2. There would not be a separate my account table for each person. That would indicate a bad database design.
  3. Yes. It would be a debit (-) amount for the source account and a deposit (+) amount for the destination account. @jtm62, having a second table that duplicates the balance from the account table is redundant information and is not necessary (do you keep track of your checking account by keeping track of the deposits/debits in one place and keeping track of the balance in another place?)
  4. http://dev.mysql.com/doc/refman/5.0/en/date-calculations.html
  5. It's a fairly safe bet that your code is doing something that isn't working on the two servers. Without enough of your code that reproduces the problem, from the form through to the point where the data doesn't make it, it's not possible to eliminate your code as the cause.
  6. http://swfupload.org/
  7. ^^^ Given that safe mode is depreciated and soon to be removed from php, I'm wondering why your host has turned it on, assuming they know that they have turned it on. Safe mode doesn't check the file/folder permission settings, it checks the user id of the file/folder owner and that of the currently running script.
  8. The line before that line is missing the the ; You also don't have any mysql_query statement to execute the query.
  9. Most types of form fields are set, even if they are empty. As to your weight field, you either have another field in the form by that same name later in the form or the markup of your actual form is invalid thereby making the weight field invalid or you have some javascript in the form that is overwriting the field value or you have some php code in your form processing code that is overwriting the value. The sql error is because your weight value is missing from the query (you should not execute the query if the validation of the values being put into the query has failed with an empty value.)
  10. You need to first find out why the function is failing. Use both of the following lines to set the error_reporting/display_errors settings (assuming your host has not disabled ini_set or the error_reporting statements) - ini_set("display_errors", "1"); error_reporting(-1);
  11. You cannot sort using your existing date format because in order to be able to sort something, you must be able to compare the values by magnitude. A mmm month abbreviation has no magnitude to compare and the fields making up the format must be arranged from left to right, highest significant part (year) to least significant part (day). This is why the YYYY-MM-DD format is used for the DATE data type in the database. It can be sorted because the fields making up the value meet the requirements needed to sort values. Your first step to solving your problem would be to add a column with a DATE data type and copy/update your existing values into that column with the correct format (you can use the mysql STR_TO_DATE() function.) Once you do this, you can sort using dates and you can retrieve the values in any format that you want using the mysql DATE_FORMAT() function in your query.
  12. I'm going to guess that the id mentioned in the latest post by the OP referred to the $_GET['id'] in/from the URL (not the id that was missing in the HTML that was preventing the wysiwyg code from working and that produce the original error message.) Nothing you posted in the code in this thread shows where the $_GET['id'] value is originally coming from. You likely had an error in the originating code (edit links perhaps?) or you are redirecting to the page you showed us but not carrying the get parameters on the end of the URL or you have some URL rewriting that is being done incorrectly that doesn't carry the get parameter through on the end of the URL.
  13. The inadvertent variable variable probably overwrote one of your actual program variables, created an empty variable, or referenced a nonexistent variable and caused your logic to skip executing the code where the query is at. Without the actual code showing the mis-typed variable and how it relates to the the query or to the execution of the query, this is just a game of 20 guesses. As to variable variables, they are undesirable for several reasons - they are three times slower than using an array variable (most people use them to create a series of named/numbered variables for a SET of related data and you should be using an array in this case anyway), they allow program variables to be overwritten (either accidentally by the programmer or intentionally by a hacker feeding all kinds of external data to your code via $_POST/$_GET data), they make your code difficult to read a few months after you have written it (or by someone who did not write it) because you don't know exactly what variables there are, where they got set, or what they got set to (see if you can easily tell what the code at the following link is looping over so that you could debug it when it does not work - http://www.phpfreaks.com/forums/index.php?topic=335615.msg1581068#msg1581068).
  14. The error is occurring on the line right before the originally posted line of code. You are using an array as an index to the $_SESSION variable.
  15. The last query error you posted is because $_SESSION['ID'] is empty. Putting quotes around it is just hiding the problem by making it an empty string instead of an empty numerical value. In reply #21 in this thread, Pikachu2000 posted a suggestion for forming your query in a php variable and then using some error checking and error reporting logic that would display the query when a query error occurs. You should do this for every query in your code. As to why the session variable is empty, you are likely missing a session_start() statement or are getting a session_start() error on either one or both the page that is setting the session variable or on the page that is using the session variable. If you were developing and debugging your php code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors get reported and displayed, php will help you. You will also save a TON of time.
  16. String (character) data must be enclosed in single-quotes so that it is treated as string data, instead of as a mysql keyword or identifier. If you were using mysql_error() as part of your error reporting logic, you would probably get an error something like - unknown column V, because mysql it treating the unquoted $mt data as a column name instead of a string.
  17. Assuming that all the assumptions that have been made are correct, the following code should (it's tested using dummy data) help you to convert your data - <?php // existing columns and type array (array lookup to get type is faster than using substr, repeatedly, inside of the processing loop, plus this made creating dummy test data easy)- $columns = array('avi_0'=>'avi','avi_1'=>'avi','avi_2'=>'avi','avi_3'=>'avi','avi_4'=>'avi','avi_5'=>'avi','avi_6'=>'avi', 'avi_7'=>'avi','avi_8'=>'avi','avi_9'=>'avi','mkv_0'=>'mkv','mkv_1'=>'mkv','mkv_2'=>'mkv','mkv_3'=>'mkv','mkv_4'=>'mkv', 'ogm_0'=>'ogm','ogm_1'=>'ogm','ogm_2'=>'ogm','ogm_3'=>'ogm','ogm_4'=>'ogm','mp4_0'=>'ogm','mp4_1'=>'mp4','mp4_2'=>'mp4', 'mp4_3'=>'mp4','mp4_4'=>'mp4'); $query = "SELECT * FROM sources ORDER BY cat_id,id"; // query for all the data with some ordering to it $result = mysql_query($query) or die("Query failed: $query<br />Error: " . mysql_error()); while($row = mysql_fetch_assoc($result)){ $data = array(); foreach($columns as $index => $type){ if(!empty($row[$index])){ $data[] = "{$row['cat_id']},{$row['id']},'$type','$row[$index]'"; } } // make a multi-value insert query if(!empty($data)){ $query = "INSERT INTO new_table (cat_id,id,type,name) VALUES (".implode("),(",$data).")"; //echo "$query<br />"; // look at the resulting query mysql_query($query) or die("Query failed: $query<br />Error: " . mysql_error()); echo "One row processed - cat_id: {$row['cat_id']}, id: {$row['id']}<br />"; } else { echo "A row with no files was skipped - cat_id: {$row['cat_id']}, id: {$row['id']}<br />"; } } ?> The new table should have an auto-increment column - file_id (or similar name) so that each row (which corresponds directly to a file now) has a unique identifier. Depending on the amount of data you have, you probably need to extend or disable the php max runtime setting. You will find that the suggested database structure will simplify ALL your code and queries. To insert a new file, you don't need to find an empty column of the correct type, you just insert a new row. To update/replace a file (assuming it would have a new filename) you don't need to carry along which column it is in, you just update the row with the old filename (having the suggest file_id column would make this even simpler.) To delete a file, you simply delete the row, you don't need to keep track of or find the column it is in or form a query to clear just that column. To retrieve and display the results, you just query for the rows with the cat_id and id that you want (and if you only want one specific file type, you would include a condition to do that in the WHERE clause), in the order that you want them (assuming you want each type of file to be together in the result set), and then just loop over the rows you get. Each row gives you all the information you need to form each link you are making now. You don't need all that extra code to set intermediate variables or to later loop over those intermediate variables. And I almost forgot, you apparently ran into performance problems when using the variable variable code (though it was more likely a logic error somewhere in using the resulting values or you accidentally overwrote one of your program variables by using variable variables), using variable variables are three times slower than using an array variable and are undesirable for processing large amounts of data or using inside of a loop.
  18. The most straight-forward way of converting the data would be to write a script to populate a new differently named table with the data by reading through all the current rows and form the new individual rows for any non-empty data. You can then convert your code and test it off line using the new table before you make any changes to the actual live site code and database. The only apparent problem I see with simply converting the data is if the id column is a key/index in the table, in which case the query you posted only needs to use WHERE id = '$id' because that would uniquely identify the row you want. However, if the id column is not a key/index in the table and you have for example, several different id's for any cat_id (the cat_id/id combination is what identifies the current row to match), then you could convert the data into a table like what I showed with no problem.
  19. <?php $lines = file("news.txt",FILE_IGNORE_NEW_LINES); for($i = count($lines) -1; $i >= 0; $i--){ list($title,$long_text,$short_text,$date) = explode("|", $lines[$i]); echo "<a href='read.php?a=read&id=$i'><strong>$title</strong></a> (<span class='day'>$date</span>)<br>\n"; } ?>
  20. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=335636.0
  21. The following quotes are from the pcre and preg_replace sections of the php manual - http://us2.php.net/manual/en/pcre.pattern.php and http://us2.php.net/manual/en/function.preg-replace.php Vertical | - Not so random i - $1 - The | forms a regular expression to match any of your search keywords - keyword1|keyword2|keyword3 The i causes the preg_replace to match both upper and lower case so that for example keyword1 will match KeYwOrD1 in the text. The $1 is a variable/reference to the actual value (which ever keyword out of the possible choices) that was actually matched so you can let the preg_ statement do the work instead of you needing to cycle through each choice, one at a time.
  22. There's absolutely no difference. The point of using a variable at all is so you can write code that does something to the contents of that variable. It does not matter if that variable gets set from a literal string assignment in some code to demonstrate how to do something or if that variable gets set by fetching a value from a database query. <?php //Display replies if ($count_4 > 0) { $keywords = str_replace(" ", "|", $string); while ($row_4 = mysql_fetch_array($result_4)) { $new_string = preg_replace("/($keywords)/i", "<b>$1</b>", $row_4["reply"]); echo $new_string; } } ?>
  23. You are adding columns to your table every time you are adding another category or possible choice. That is bad database design, which is mainly why your code to retrieve the data and then make use of the data is overly complicated. Your database design should have ONE row for each piece of data. For what you appear to be doing, I would have a type column that indicates avi, mkv, ogm, or mp4, and any future types you choose to add and a name column that holds the actual file name. You would then retrieve all the row(s) you are interested in, in the order that you want them. Then SIMPLY iterate over the row(s) that your query returns and output the information the way you want. For what appears to be some of your data, this would look like - id cat_id type name 34234 1334234 avi 3AT38DXD0WG08KVO 34234 1334234 avi 0WG08KVO0WG08KVO 34234 1334234 avi 0WG08KVO 34234 1334234 avi K0WG0YP5XGKYP5XGLYL34234Y 34234 1334234 avi KYP0WG0KYP5XGLY5XGLY34234 34234 1334234 mkv LXRPWCTD9EQOCK3V2FZGIO24 34234 1334234 mkv 2FZGID9EQOCK3O24 34234 1334234 mkv 0WG08KVO2D9EQOCK3FZGIO24 34234 1334234 mkv D9EQOCK334234 34234 1334234 mkv KYP5XGLY You only have row(s) for actual data and you can add an unlimited number of files for any type simply by inserting a row with the information in it.
  24. Your php code is probably fetching and discarding one row or your query is doing something to cause one row to not be matched. If you want help with something you are doing that does not work, you must post the query and code responsible for the symptoms.
  25. Once you change your table so that it has a proper DATETIME column, all your code can be replaced by - <?php include("connect.php"); // date_format: 8th June 2011 - 10:32 am $query = "SELECT *, DATE_FORMAT(date,'%D %M %Y - %l:%i %p') as fdate FROM new_news ORDER BY date DESC"; $result = mysql_query($query); if (mysql_num_rows($result)){ while ($row = mysql_fetch_assoc($result)){ echo $row['fdate'] . "<br />"; echo $row['new_news'] . "<br /><br />"; } } else { echo "No News"; } ?> You (or the code generator) have prefixed each column name and variable names with new_. That just makes the code more cluttered and makes reading, finding things, and understanding the code harder. Also, mysql_result() is the slowest way of accessing any data and it should only really be used when you are getting one piece of data from a result set that has one row or when you need to randomly access the data in a result set.
×
×
  • 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.