I need some help with a function that does the following:
It selects 12 rows from a table with many rows. The selected all have in common one value: ArticleNr which is between 1-12. None have the same.
I want a function that rearranges these articleNr so that the one with articlenr 2 becomes maybe 12 for example. All random.
The other values on the rows are not to be changed!
Can someone help me with this? I'm clueless!

    This was my first thought:

    $cur = array ();
    $new = array ();
    
    $query = 'select * from `table` limit 12';
    $result = mysql_query ($query);
    
    while (($row = mysql_fetch_assoc ($result)) !== false) {
    	$cur[] = $row['ArticleNR'];
    	$new[] = $row['ArticleNR'];
    }
    
    shuffle ($cur);
    shuffle ($new);
    
    for ($i = 1; $i < count ($cur); $i++) {
    	$query = 'update `table` set `ArticleNR` = "' . $new[$i] . '" where `ArticleNR` = "' . $cur[$i] . '" limit 1';
    	$result = mysql_query ($query);
    }

    But I can tell you already that it doesn't work, haha. I posted it here so that others could see it and maybe think of a way to fix it. 😃 Because I don't know how. 🙁

      Write a Reply...