Note that there are some explanatory texts on larger screens.

plurals
  1. POMYSQL + PHP one record at a time in sorted order
    primarykey
    data
    text
    <p>So, I have a page <code>allocate.php?id=XXXXX</code>. It basically picks up data from various tables in the database based on the id value, and displays them accordingly. It also allows user to edit and work around with related data.</p> <p>Now, the main table to which the id value is associated, also has a field 'priority', which determines the order in which I need to traverse the table. Question is:</p> <ol> <li><p>Say I am on page 'allocate.php?id=10000'. It has 'priority' value 1.</p></li> <li><p>The next page, should display details for 'priority' value of 2. It is assigned to a course with id say '20001'. Basically, I wish to move to 'allocate.php?id=20001' next.</p></li> <li><p>So how do I provide a dynamic link on each allocate page which links to the next highest priority assigned id value?</p></li> </ol> <p>If you need more info, here is the exact table:</p> <pre><code>CREATE TABLE IF NOT EXISTS `course` ( `id` varchar(11) NOT NULL, `name` varchar(30) NOT NULL, `priority` int(2) NOT NULL, PRIMARY KEY (`id`) ) </code></pre> <p>Here are the values:</p> <pre><code>TUSCE100101 Course 101 1 TUSCE100102 Course 102 2 TUSCE100201 Course 201 2 NTUSCE100202 Course 202 3 TUSCE200301 Course 301 1 TUSCE200302 Course 302 4 </code></pre> <p>Thanks!</p> <p>EDIT: To those who downrated the question possibly thinking it's too simple or I ahven't researched enough, my problem is that when I check for priority greater than and equal to, and order the result, not counting the current page, then I might be in a situation where I toggle between courses on the same priority level. Eg:</p> <ol> <li><p>Course 101,102 and 103 have same priority.</p></li> <li><p>I am on 101, the query to search for next gives me 102 and 103 in random order. I pick first value, say 102.</p></li> <li><p>Now when on 102, the same search select query will give me 101 and 103, and the first row maybe 101. So I end up toggling back and forth.</p></li> </ol> <p>EDIT 2</p> <p>So, I worked it out eventually. Here it is for future reference.</p> <p>I defined an additional column called "visit", to indicate if the particular row has or has not been visited. It has default value of 0 when not visited.</p> <p>After visiting every row, I marked the visit value as 1, and picked the next value based on the query like "SELECT id FROM course WHERE priority >= $currentPriority AND id!=$currentId AND visit=0".</p> <p>At the last row, when the above select query would not return anything, I set all 'visit' to 0 again, and chose the first one simply based on an ordered query based on 'priority'. This allowed me to loop through the table infinitely.</p> <p>P.S. Thank you for all your help. I was honestly a little disappointed by the bizarre response from the community, though I believe I am at fault for not being very clear in my question. Feedback on my solution would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload