Welcome our webmaster and SEO forum
Please enjoy the forum, contribute what you can, and wind up the Moderators!
Results 1 to 8 of 8

Thread: MYSQL ordered table

  1. #1
    komrad's Avatar
    komrad is offline Junior Member
    Join Date
    Aug 2008
    Posts
    8

    Default MYSQL ordered table

    Hello all,

    I'd like to know if there is a way to insert into a MYSQL table data in an ordered way?
    Right now as a workaround I've literally made a table of questions with questionID as primary key, nextQuestion and prevQuestion pointing to other questionIDs. Basically I've made a two way linked list from scratch. Is there anything built into MYSQL that implements this?

    Thanks in advance.

  2. #2
    BurtyB is offline Member
    Join Date
    Aug 2008
    Location
    Newark, UK
    Posts
    36

    Default

    How about using a "priority" column so you can easily switch entries around and allow you to order the questions quickly within the SQL SELECT statement?

    ChrisB.
    Chris Burton
    8086 Limited (Company No.: 06336617 VAT No.: 920 5102 75)
    Ever wanted to know who uses a DNS or MX server ? with DNS History you can find out.

  3. #3
    paulgascoigne is offline Junior Member
    Join Date
    Jan 2009
    Posts
    10

    Default

    You are clearly not making the best use of a relational database. Relational databases have built in indexes that let you quickly list records ordered by certain field.
    You have to:
    1) Create an indexed field . The primary key is automatically indexed. If you want to sort using a different field than you have to create an index using the keyword "index"
    2) Then try a query like
    select * from employees order by age

    If you want descending order
    select * from employees order by age desc

  4. #4
    surreypcsupport's Avatar
    surreypcsupport is offline Senior Member
    Join Date
    Nov 2008
    Location
    surrey
    Posts
    565

    Default

    You could create a column called 'sequence_id' which will be an integer. Then you can give all the rows in the table a sequence of whatever you want so when you write your query to retrieve the rows just add 'ORDER BY Sequence_ID to the end.

  5. #5
    Mckee is offline Member
    Join Date
    Mar 2009
    Posts
    50

    Default

    Hi, how can you connect to database or the relation of your database?..D

  6. #6
    surreypcsupport's Avatar
    surreypcsupport is offline Senior Member
    Join Date
    Nov 2008
    Location
    surrey
    Posts
    565

    Default

    Quote Originally Posted by Mckee View Post
    Hi, how can you connect to database or the relation of your database?..D
    Create a function like this:

    function DBConnect()
    {
    $dbh=mysql_connect ("localhost", "USER NAME", "PASSWORD") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("DATABASE NAME");
    }

    Swap 'localhost' for an IP address if the DB is located elsewhere.

    Call it like this.

    DBConnect();

    If you place the DBConnect function in an inc file and then use the 'include' command to refer to it in your pages then if you change the DB creds you only have to change it in one place.
    Last edited by surreypcsupport; 03-06-2009 at 08:46 AM.

  7. #7
    alex28's Avatar
    alex28 is offline Junior Member
    Join Date
    Jun 2010
    Posts
    6

    Default

    you can ordered the sequence of data in the column by alphabatically as ascending or decending order you have need to use the order by desc or asec

  8. #8
    norbertwarne is offline Junior Member
    Join Date
    Oct 2010
    Posts
    17

    Default

    you can dictated the sequence of data in the column by alphabatically as ascending or decending order you have want to apply the order by desc or asec.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124