I have a user editable list like bullet points. Points are being deleted and added(to the end or middle of the list) frequently. Is there any more efficient way of maintaining this list’s ORDER than having each bullet have an id and keeping a SQL entry of the order split by commas? Example:
$result = mysql_query("SELECT order FROM users WHERE user = '$userId'"); //Get order for logged in user. returns id1,id2,id3,id4
$row = mysql_fetch_array($result);
$order = explode(',', $row['order']); //make the order an array
$result = mysql_query("SELECT id, data FROM bullets"); //get all the bullets
$bullets = array();
while($row = mysql_fetch_array($result)){
$project[$row['id']] = $row['data'];
}
Then run:
foreach($order as $k => $v){
echo '<li id="'.$k.'">'.$v.'</li>';
}
You can add an
ordinalfield to the bullets table.Then your select looks like this:
Also, you shouldn’t store denormalized data like you’re doing with order in your users table.
Also, you shouldn’t name a field
orderbecause it is a reserved word.