from php to python

Hi , my name luigi from italy english elementary.

How to convert code php from python:

if(isset($_GET["order"])) {
	$order  = explode(",",$_GET["order"]);
	for($i=0; $i < count($order);$i++) {
		$sql = "UPDATE reorder SET display_order='" . $i . "' WHERE id=". $order[$i];		
		mysqli_query($conn, $sql) or die("database error:". mysqli_error($conn));	

python for cicle and variables LIST .

How to convert?

If it helps, you can try writing your question in Italian and then use something like to convert it to English - maybe even posting both versions. (That’s been done a few times here - you can find other posts written in multiple languages on this forum. )

What I would suggest is that you don’t approach this by trying to translate the php code to Python directly.

Get an understanding of what the PHP is doing, and then write the appropriate Python code to perform the same function.

So, what is this code doing?

Hi, doing for now I did this:

class ModificaOrdineFotoUpdate(View):
    def get(self, request, album_slug):
        orgs = Album.objects.filter(slug__iexact = album_slug)
        if not orgs:
            return render(request, 'photo_404.html')
            order_list = request.GET.getlist('order')
            order_list = str(order_list)
            print(order_list.split(',', 1))
        return JsonResponse({'photo':'false'})  

But it generates me a strange list. Do you have any idea why?

["['4", "1,2,3,5,6,7,8,9,10,11']"]
[14/May/2023 19:52:30] "GET /photo/ModificaOrdineFotoUpdate/le-mie-foto-personali/?order=4,1,2,3,5,6,7,8,9,10,11&_=1684086741319 HTTP/1.1" 200 18

A thousand thanks.

togliendo l’1 dallo split ora mi fa cosi:

["['11", '1', '2', '3', '4', '5', '6', '7', '8', '9', "10']"]
[14/May/2023 20:04:29] "GET /photo/ModificaOrdineFotoUpdate/le-mie-foto-personali/?order=11,1,2,3,4,5,6,7,8,9,10&_=1684087465654 HTTP/1.1" 200 18
["['11", '3', '1', '2', '4', '5', '6', '7', '8', '9', "10']"]
[14/May/2023 20:04:35] "GET /photo/ModificaOrdineFotoUpdate/le-mie-foto-personali/?order=11,3,1,2,4,5,6,7,8,9,10&_=1684087465655 HTTP/1.1" 200 18

How to remove from list?

Keep in mind that the printed representation of an object doesn’t necessarily have anything to do with its internal structure.

What is the data type of order_list?

You really don’t want to do this. You’re undoing work that Django has already done for you. You should be working with the native data types and not the string representation of that data.

If you’re not comfortable with working with the native Python data types such as lists, tuples, and dicts, that’s a topic that you should focus on learning more of before trying to continue here.