PHP - Moved: Mysql Order By First Letter Of Name
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=349226.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=347726.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=320026.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321906.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=345631.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=312690.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=328623.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350684.0 Hi!
I'm fairly new to PHP & MySQL (from a programmer's perspective) and have just started seriously building my own applications using PHP. I need some help bridging the gap with this MySQL query I have created that is to find only the organizations that have names that start with the letter 'A'. The initial query that I have written does work. However, I need to refine the query to "skip" over the first word -- example "The" so that I can get the complete correct results.
Here is my code:
include_once("dbconnect.php"); $linkA = "SELECT church_org FROM ics_data WHERE church_org LIKE 'A%' ORDER BY church_org ASC"; $queryA = mysql_query($linkA); $dataA = array(); while ($row = mysql_fetch_array($queryA) ) array_push ($dataA, array('church_org' => $row[0])); echo json_encode(array("dataA" => $dataA));This fetches every organization that starts with the letter 'A'. However, some organizations have St. or The in front of their names. So the query doesn't pick those up because it doesn't match what I have specified. I have tried the following: $linkA = "SELECT church_org FROM ics_data WHERE church_org LIKE 'A%' & TRIM('St. ', 'St ' church_org) ORDER BY church_org ASC";This doesn't do what I wanted it to do and after further research, I believe it is because TRIM only trims the words specified from the end-result string. I *think* I need to use REGEX to define a better pattern for the query but am still a little confused after reading the documentation on how to go about building that out. How would I accomplish this? I appreciate any help or guidance! Hopefully, I have posted this in the right forum. hello, im trying to see if there is a function that can get the value of the last row in mysql and see what is in field initial (this is letters A-Z) and make it one letter higher. then, when it reaches letter Z, wrap around to A again. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321790.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318036.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=355706.0 I'm currently trying to grab data from my database for my chatbox, which when displayed, displays in an ascending order, when I call it to descend, it shows the messages ONCE in descending order, then just repeats but in random order.. Code: [Select] $sql = "SELECT * FROM `message` WHERE `chat_id` = 1 AND `message_id` > $last ORDER BY `message_id` DESC"; Database: message_id | name 1 RSX 2 RSX 3 RSX 4 RSX Code: [Select] RSX: 4 RSX: 3 RSX: 2 RSX: 1 RSX: 4 RSX: 3 RSX: 2 RSX: 4 RSX: 3 RSX: 4 It is ordering it correctly, just repeats, I'm using Ajax, could that be the problem, or is it within the PHP code? Edit: I read it wrong, it displays as shown under "output". Lets say I have this query: $sql = mysql_query("SELECT * FROM Member ORDER BY posts DESC LIMIT 10"); while ($get = mysql_fetch_array($sql)){ $row .= $get['id']; $posts .= $get['posts']; echo "$row - $posts<br />"; } Lets say I have two of rows, with posts fields of 84 and 803. When it displays it, it grabs the 84 row first, when I want the bigger number 803 first. Is there a way to fix this? This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=326563.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=319167.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=328735.0 This topic's house has been seized by the bank and it now lives in MySQL Help until it can get back on its feet. http://www.phpfreaks.com/forums/index.php?topic=358035.0 ok so i want to order by high to low on the field price but i don't know how to do this. i can order low to high by using ORDER BY `Price` ASC but how can i order high to low? hello all. I have a list of records, which each have a comment button, just like any forum does. when I click on the comment button it brings up the current record at the top, and a blank form, to which you enter in information. When I submit this information, I want it to show up on the main page as a child of the parent record. I want it similar to the example I've shown below: Code: [Select] id name dob address email username 1 john smith 10/11/1986 124 Peermont Drive john.smith@yahoo.com john smith1 >> 2 Harry 15/12/1985 98 The Roundhay harry@gmail.com harry23 >>> 3 jhk 08/11/1976 65 dfgdfg gfdfg@ yahoo.com jhk345 4 john smith 10/11/1986 124 Peermont Drive john.smith@yahoo.com john smith1 >> 5 Harry 15/12/1985 98 The Roundhay harry@gmail.com harry23 >>>> 6 jhk 08/11/1976 65 dfgdfg gfdfg@ yahoo.com jhk345 I've been stuck on this for hours, and I haven't got anywhere. Any ideas? |