Psycho
Moderators-
Posts
12,159 -
Joined
-
Last visited
-
Days Won
130
Everything posted by Psycho
-
Is the page you linked to in your original post "THE" document you are getting the data from or is there a different document which you used to create the HTML page? If it's a different document, please attach the file. Also, there are two different tables - do you need the data from both tables or only one?
-
A better question is how to get your data into a better format to begin with. Instead of having allt he folders/files in a signle array and having to use string manipulation the data shoud be in a multidimensional array. Edit: I posted a function, but had to withdraw as I need to review it.
-
And you are from England?! If you want help at least take the time to write a comprehendable sentence and actually explain what you want. Don't make people who are volunteering their time have to figure out what you want. You could have at least stated that you want to separate the applicable address parts with a comma and space. It was not obvious from just looking at the two lists. As for your problem there are some things that you may be able to do, but nothing you create will be 100% accurate because of the variability of addresses. Your first option should be to go to the source to get better formatted data. Where are you getting this data? Are you extracting it from a file or web page? There might be a better method to preserve whatever delimiters exist. Assuming there is no better method of getting the data, here are some of the rules I would start with (again this will not be 100% accurate): 1. Split the Name and street address based upon the first numeric character (of course if the business name has a number in it you're screwed) 2. Then working from the back get the last 13 characters (11 numbers and two spaces) as the last code 3. Again working from the back, Check the characters that are 2-3 from the end to see if they are "RG", if so take the last three as the next code. If not, check characters 6-7 from the end to see if they are "RG". If so, take the last 7 characters. If both of those fail - I don't know what you should do. 4. Working fro the end again, take the last 'word' as the city. I base this on the examples you gave, but I'm sure you will have cities that are two words which will break this logic. 5. Whatever remains is the street address I would write some code for this, but because of the issues I noted above this is most likely not worthwhile endeavor
-
What do you mean you want to "order them in my mysql database"? You do not order records in a database - at least not how I think you mean. Is there a specific value you want the records ordered on (e.g. Pts, SH% or some other value in the database)? If so, you can always have the records ordered dynamically based upon the query you use to get the data. However, if you need the records ordered in some specific order that is not related to any data, then you would have to add a column to indicate the "order by" value. And then create new functionality for you to manually reorder as needed. I'm thinking you can go with the first option. Just show the query you currently use and specify how you want the records ordered. A simple change to the query should be all you need.
-
What does that mean, exactly? Based on the title of your post I "assume" it means that the user does not even receive the email, but I never like to assume. Or do they received the email but it only shows the plain text version? PLease be specific. Assuming they do not receive the email, have you had the user check their "Spam" folder in Gmail? If it is marked as spam the user can configure Gmail to always allow those messages.
-
[SOLVED] Drop down option box not displaying items
Psycho replied to peachsnapple's topic in PHP Coding Help
1. You don't have any error handling on your queries. Have you verified that they are not failing and are returning results. For a quick and dirty verification and an "or die(mysql_error())" to your query calls like so: $r = mysql_query($q) or die(mysql_error()); 2. You are using PHP short tags to "write" your options to the page. These are discouraged. You should use full PHP tags: <select name="prodid"><?php echo $prod_options; ?></select> Also, did you even check the generated html code to see what was created? -
Well, the first script is using 'short' php tags which is not good practice, but that shouldn't create the type of error you are reporting. Based upon your explanation I am assuming it is the connect script that is failing. Have you tried just running those two connection scripts independantly to ensure the first one succeeds? If not, then you only need to concern yourself with that one. If yes, then the problem lies elsewhere. Also, have you considered this may be a caching issue? If you had incorrectly set up the file to use the wrong credentials initially and the error occured. You may still see that error after correcting the problem if your browser has cached the response. Try pressing Ctrl-F5 on the page to ensure the browser gets a frsh copy.
-
[SOLVED] Help combo box posting all values instead of selected
Psycho replied to aussie's topic in PHP Coding Help
Have you checked the HTML output of your form? I'm guessing that all the options may be set as selected. Also, in your loop that creates the options, have you verified the values of $attribute_id and $pdId which are used to determine if the fields default to selected? Have you verified the actual POST data on the receiving page? Run a print_r($_POST) to verifiy the data is what you expect. When something doesn't work you need to use critical thinking skills to find the problem. Determine where an error could be occuring and find a way to validate/investigate that particular scenario. Then once you find where the problem is occuring you can determine why it is occuring and, lastly, determine how to fix it. -
<?php while ($row = mssql_fetch_assoc($qq)) { $ccc[] = array( 'machine' => $row['MACHINE'], 'devid' => $row['DEVID'], 'inputdevid' => $row['INPUTDEVID'], 'eventtype' => $row['EVENTTYPE'], 'eventid' => $row['EVENTID'] ); $machines[] = $row['MACHINE']; $devid[] = $row['DEVID']; $inputdevid[] = $row['INPUTDEVID']; $eventtype[] = $row['EVENTTYPE']; $eventid[] = $row['EVENTID']; } $machinesCount = array_count_values($machines); $devidCount = array_count_values($devid); $inputdevidCount = array_count_values($inputdevid); $eventtypeCount = array_count_values($eventtype); $eventidCount = array_count_values($eventid); //The count arrays will be in this format //array ( // 'value1' => 4, // <-- the number will be how many times // 'value2' => 1, // that value appears in the array // 'value3' => 6, // 'value4' => 3, //) ?>
-
[SOLVED] trying 3 days - splitting multiple array values with same key
Psycho replied to oocuz's topic in PHP Coding Help
OK, based on this explanation, I'm guessing that the additional brackets aren't needed? Three's only one textarea assoaciated with each text field, right? If so, remove the additional empty brackets from the textarea names. OK, now that the objective is clear, we can find a solution. I created a test page (at the end) that should be replicating your form and which also processes the post data how I believe you want it. If the user inputs the following (bold items are the field labels, Keyword is a text field, add'l spellings is a text area with multi-line input) The script processes the data into a multidimensional array as follow: Array ( [0] => Array ( [keyword] => First Keyword [spelling] => Array ( [0] => Keyword Number 1 [1] => 1st Keyword ) ) [1] => Array ( [keyword] => Second Keyword [spelling] => Array ( [0] => Sec. Keyword [1] => 2nd Keyword ) ) [2] => Array ( [keyword] => Third Keyword [spelling] => Array ( [0] => 3rd Keyword [1] => Keyword Number 3 ) ) ) I think this is what you want. Here is the code: <?php //Process the post data if (isset($_POST['keyword'])) { $result = array(); foreach ($_POST['keyword'] as $keywordIdx => $keyword) { $keyword = trim($keyword); if (!empty($keyword)) { $addlSpellingPost = trim($_POST['additionalSpelling'][$keywordIdx]); $spellingAry = explode("\n", $addlSpellingPost); $spellingResult = array(); foreach ($spellingAry as $spelling) { $spelling = trim($spelling); if (!empty($spelling)) { $spellingResult[] = $spelling; } } $result[] = array( 'keyword' => $keyword, 'spelling' => $spellingResult ); } } } ?> <html> <head> <title>Members Credits</title> </head> <body> <form name="updateCredits" action="" method="POST"> <?php for ($i=1; $i<=3; $i++) { echo "Keyword {$i}: <input type=\"text\" name=\"keyword[{$i}]\"><br />\n"; echo "Additional Spellings:<br />\n"; echo "<textarea cols=\"27\" rows=\"3\" name=\"additionalSpelling[{$i}]\" id=\"additionalSpelling_{$i}\"></textarea><br /><br />\n"; } ?> <button type="submit">Submit</button> </form> <pre> <?php print_r($result); ?> </pre> </body> </html> -
[SOLVED] trying 3 days - splitting multiple array values with same key
Psycho replied to oocuz's topic in PHP Coding Help
You are really confusing the issue here. Your "example" arrays above are not valid so I have no idea what the expected input is supposed to be to determine what you are wanting to do with the input. The fact that you are sending the data as an aray has absoltely no bearing on the issue. POST data is always sent as an array. The method I gave you only makes it a multidimensional array to "group" the data logically and I showed you how to access those values. So, the only issue is what you want to "do" with that data. So, let's forget about the fact that the data is sent as an array. Provide a "real word" example of what the data for one text area will look like and explain/show how you want it processed. -
A couple things: 1, You are "throwing out" the first records from each of the first two queries. You do a mysql_fetch_array() and do a print_r() on the first record, then you do a while loop with a mysql_fetch_array() for each record after that - in other words the while loop starts on the second record. If either of the first two queries return only one record then the while loops will not run. 2. Why three queries when you could do it with one? What really makes no sense is that these are all within loops and the third query is exactly the same as the first. Edit: One other thing, you are not referencing your query array results correctly, so all of your values are probably 0. WRONG: $regen_time=$row[regen_time]; RIGHT: $regen_time=$row['regen_time']; (notice the quote marks) Unless you had defined 'regen_time' as a constant with a value the same as a field name then you are referencing any arary index that does not exist.
-
[SOLVED] trying 3 days - splitting multiple array values with same key
Psycho replied to oocuz's topic in PHP Coding Help
It is already separated - the values are in a sub array. $_POST['additionalSpelling'][1] - this would be an array of all the values that belong to the category with an ID of 1. So... $_POST['additionalSpelling'][1][0] is the first value $_POST['additionalSpelling'][1][1] is the second value etc... Try running this on your post data to see all the values categorized foreach ($_POST['additionalSpelling'] as $cat_id => $value_ary) { echo "<h3>Category ID: ($cat_id}</h3>\n"; echo "<ul>\n"; foreach ($value_ary as $value) { echo "<li>{$value}</li>\n"; } echo "</ul>\n"; } -
[SOLVED] trying 3 days - splitting multiple array values with same key
Psycho replied to oocuz's topic in PHP Coding Help
Just add an additional set of empty brackets after the field names and the data will be received as a multidimensional array: <textarea cols="27" rows="3" name="additionalSpelling[<?php echo $category_id; ?>][]" id="additionalSpelling_<?php echo $i; ?>"></textarea> Something like this: array( "1" => array ( 0 => "textarea1_entry1", 1 => "textarea1_entry2", 2 => "etc." ), "2" => array ( 0 => "textarea1_entry1", 1 => "textarea1_entry2", 2 => "etc." ), "3" => array ( 0 => "textarea1_entry1", 1 => "textarea1_entry2", 2 => "etc." ) ) -
How is that different or even "more advanced" than "...to run an automated process on all POST data".
-
Did you take a look at any tutorials regardng JOINs? That is kind of the point of a tutorial - to eplain how something works. I could give you a very "gneral" statement of what it is doing, but to really give you enough to understand I'd basically have to write a tutorial. Generally speaking, when you JOIN two tables you create a result set that includes every combination of records from table 1 to records in table 2. So, for the first record in table 1 you would get multiple results where that record is joined to each record from table 2. This is almost never what you want. You only want the records from table 1 to be joined to the records that it is related to in table 2. So, your JOIN will include some instruction for doing this such as stating that a value in table 1 must equal a value in table to (e.g. the id must be the same as the foreign key). Anyway, I could go on explaining, but honestly I don't have the time and there are plenty of good turorials out there that will do a better job than I could in a forum post. http://www.tizag.com/mysqlTutorial/mysqljoins.php http://www.keithjbrown.co.uk/vworks/mysql/mysql_p5.php http://www.webdesign.org/web/web-programming/php/mysql-join-tutorial.14876.html http://www.tutorialized.com/tutorial/MySQL-Table-Joins/482 http://www.wellho.net/mouth/158_MySQL-LEFT-JOIN-and-RIGHT-JOIN-INNER-JOIN-and-OUTER-JOIN.html
-
I'd say it depends on what you are doing. Typically, I prefer to explicitly define variables from my post data as in your first example. I'd stay away from using something such as extract(0 to convert all the POST data into variables automatically because you can never trust user data. However, it is sometimes useful to run an automated process on all POST data, such as stripslashes() when magic quotes is on rather than checking/striping each value one at a time.
-
yeah, sorry, it is a pet peeve of mine when people use variable names that offer absolutely no value to identifying what the variable is. It may seem more efficient when initially writing the code, but it creates problems when having to edit the code later or if someone else needs to edit the code. So, I will sometimes go a little too far when editing peoples code on forums.
-
<?php mysql_connect("localhost","root","password"); mysql_select_db("artists"); $query = "SELECT id, CONCAT(artist_firstname, ' ', artist_lastname) as name FROM `artists` ORDER BY artist_lastname ASC"; $result = mysql_query($query); $artist_options = ''; while($row = mysql_fetch_assoc($r)) { $artist_options .= "<option value=\"{$row['id']}\">{$row['name']}</option>\n"; } ?> <label for="artist">Artists</label> <SELECT NAME="artist"> <?php echo $artist_options; ?> </SELECT>
-
if ($cur_post['group_id'] == '1') { $user_info[] = '<br>Group'.': Admin'; } else if ($cur_post['group_id'] == '2') { $user_info[] = '<br>Group'.': Members'; } However, if you are doing more than just two options, you should be using a switch() statement switch ($cur_post['group_id']) { case '1': $user_info[] = '<br>Group'.': Admin'; break; case '2': $user_info[] = '<br>Group'.': Members'; break; case '3': default: $user_info[] = '<br>Group'.': Somethign Else'; break; }
-
OK, I went ahead and created a couple of test tables and debugged the code. The following should work for you. <?php /// - Database Information $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $dbname = 'cdcol'; // Make database connection $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $status = ' '; // Member Updated if (isset($_POST['credits']) && is_array($_POST['credits']) && count($_POST['credits'])>0) { $success = 0; $fail = 0; foreach ($_POST['credits'] as $user_id => $new_credits) { if ($new_credits!='') { $user_id = mysql_real_escape_string(trim($user_id)); $new_credits = mysql_real_escape_string(trim($new_credits)); $query = "UPDATE credits SET total_credits={$new_credits} WHERE user_id = {$user_id}"; //$result = mysql_query($query); if (mysql_query($query)) { $success++; } else { $fail++; } } if (($success+$fail)>0) { $status = "A total of " . ($success+$fail) . " records were processed with {$fail} failures."; } } } //Query for list of members $query = "SELECT c.user_id, c.total_credits, mp.user_name FROM credits c JOIN member_profile mp ON c.user_id = mp.user_id ORDER BY mp.user_name"; $result = mysql_query($query, $conn) or DIE(mysql_error()); $records = ''; while($row = mysql_fetch_array($result)) { $records .= "<tr>\n"; $records .= " <td>{$row['user_name']}</td>\n"; $records .= " <td align=\"center\">{$row['total_credits']}</td>\n"; $records .= " <td align=\"center\"><input type=\"text\" name=\"credits[{$row['user_id']}]\" style=\"width:50px;\" /></td>\n"; $records .= "</tr>\n"; } ?> <html> <head> <title>Members Credits</title> </head> <body> <center> <div><?php echo $status; ?></div> <br /> <H1>Members Credits</h1> <form name="updateCredits" action="" method="POST"> <table border="1" bordercolor="#000000"> <tr> <th><b>user</b></th> <th align="center"><b>credits</b></th> <th align="center"><b>new credits</b></th> </tr> <?php echo $records; ?> </table> <button type="submit">Update Credits</button> </form> </center> </body> </html> <? mysql_close($conn); ?>
-
Did you at least try it? There might not be any errors and it might work fine. Or, if there are errors we can help resolve them. Right, wildteen88 and I both thought that the name was in that same table. You would need to do a JOIN of that query. But, if you do a JOIN you would also want to "fix" the code which displays the results since it does a query for each record to get the name which wouldn't be needed any more. Give the code I posted a try and respond back with the results.
-
Give the following a try. This should display the records in order of the user name, let you update multiple records at a time, and does not use DIE to create invalid pages. Not tested, so there may be some syntax errors. <?php /// - Database Information $dbhost = 'localhost'; $dbuser = 'dbase_user'; $dbpass = 'xxxxx'; $dbname = 'dbase_name'; // Make database connection $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); // Member Updated if (isset($_POST)) { $success = 0; $fail = 0; foreach ($_POST['credits'] as $user_id => $new_credits) { if ($new_credits!='') { $user_id = mysql_real_escape_string(trim($_POST['user_id'])); $new_credits = mysql_real_escape_string(trim($_POST['new_credits'])); $query = "UPDATE credits SET total_credits={$new_credits} WHERE user_id = {$user_id}"; $result = mysql_query($query); if (mysql_query($query)) { $success++; } else { $fail++; } } } $status = "A total of " . ($success+$fail) . " records were processed with {$fail} failures."; } //Query for list of members $query = "SELECT c.user_id, c.total_credits, mp.user_name FROM credits c JOIN member_profile mp ON c.user_id = mp.user_id ORDER BY mp.user_name"; $result = mysql_query($query, $conn) or DIE(mysql_error()); ?> <html> <head> <title>Members Credits</title> </head> <body> <center> <div><?php echo $status; ?></div> <br /> <H1>Members Credits</h1> <form name="updateCredits" action="" method="POST"> <table border="1" bordercolor="#000000"> <tr> <th><b>user</b></th> <th><b>credits</b></th> <th><b>new credits</b></th> </tr> <?php while($row = mysql_fetch_array($result)) { echo "<tr>\n"; echo " <td>{$row['user_name']}</td>\n"; echo " <td>{$row['total_credits']}</td>\n"; echo " <td><input type=\"text\' name=\"credits['{$row['user_id']}']\" value=\"\" /></td>\n"; echo "</tr>\n"; } ?> </table> <button type="submit">Update Credits</button> </form> </center> </body> </html> <? mysql_close($conn); ?>
-
Ok, my mistake, the data is coming from two different tables. Still, only one query is needed. I will post some code in a moment.
-
Looks like we have a failure to communicate. Wildteen gave you the answer. There is nothing for you to do in phpmyadmin. Just change the query in your script as he suggested and the records will be ordered accordingly. The query currently orders by the ID which - surprise, surprise - is the order in which they were added. You just need to change that to order the results by the name field. But, there is another issue as well which is absolute terrrible programming. The script first does a query of the user table to get all the data for all users. Then when displaying the results another query is run for each and every record to get the user name from the same table that the original records were retrieved from (which, by the way, queries all the data, but only uses one field). You already have all the data from the first query, why on earth would you want to run another query for each and every record?! Run ONE query and only request the data you will actually use.