1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

PHP I need sql help

Discussion in 'Web Development' started by bmcoll3278, Aug 13, 2009.

  1. bmcoll3278

    bmcoll3278 New Member

    hey guys here is my query string
    mysql_query("SELECT * FROM names WHERE name like '%A%';ORDER BY name ASC");

    This Table row contains a single word name My query works but it will pull all names with a (a) in them. Can someone tell me how to match only the first letter of the name so I can display all names with a or b or c you get the idea.

    Thanks in advance
     
  2. ishkey

    ishkey Moderator, Logos, Sports Crests Staff Member Verified Member

    "ORDER BY Keyword"
    The ORDER BY keyword sort the records in ascending order by default.
    If you want to sort the records in a descending order, you can use the DESC keyword.

    SELECT column_name(s)
    FROM table_name
    ORDER BY column_name(s) ASC|DESC
     
  3. bradstyris

    bradstyris New Member

    I have a little problem given below.

    Select student.name, from student, staff where student.name= staff.name

    The result of this query gives only common name of both table student and staff table names but i want to common name of student and staff as well as all staff member name. So help me to write such a query.
     
  4. bmcoll3278

    bmcoll3278 New Member

    easy to do But i need your table structure to do it.
    If you want to send me a copy of the sql file so I can see how the table is built I will help.
     
  5. enigma1

    enigma1 New Member

    Or if you want to extract just the records where names begin with a you remove the % character from the beginning of the query. Something like:
    Code:
    mysql_query("SELECT * FROM names WHERE name like 'A%' ORDER BY name");
    PS: whats the semicolon doing before the order by with the original query. That should give an sql error.
     
  6. warden26

    warden26 New Member

    No semicolon.