How to synchronize data between flutter app (SQFLite) and a MySQL server database?

1,372 views
Skip to first unread message

Mohamed Yanis

unread,
Aug 8, 2020, 7:26:16 AM8/8/20
to Flutter Development (flutter-dev)
Hello,
I have a backend server i.e. I have an external MySQL database (localhost) that contains a "questions" table characterized by their level (Easy, Medium, Hard) and their class(1st class, 2nd class, 3rd class).
I have an internal database (SQFLite) that contains a "students" table with level and class attributes that contain in the external MySQL database.
I want to post only the questions that correspond to the level and class of the student that is already added in the internal database "SQFLite".
I posted all the questions in the JSON form but did not match the level and class of the student currently added, But I want when I add a new student with their level and class in the internal database"SQFLite", the questions that are displayed must be matched to that of the student.


Suzuki Tomohiro

unread,
Aug 8, 2020, 8:35:46 AM8/8/20
to Mohamed Yanis, Flutter Development (flutter-dev)
I felt that you know what to do. Match student’s level (SQFLite) when fetching questions in MySQL.

What is the challenge for you?

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/6f4d4ed0-080b-4415-9eeb-9c0c0c5280b1o%40googlegroups.com.

Souvik Dutta

unread,
Aug 8, 2020, 10:23:21 AM8/8/20
to Mohamed Yanis, Flutter Development (flutter-dev)
Yes you can do a normal query and have the required data.

Souvik flutter dev

Message has been deleted

Mohamed Yanis

unread,
Aug 8, 2020, 12:02:16 PM8/8/20
to Flutter Development (flutter-dev)
I want to post only the questions that correspond to the level and class of the student that is already added in the internal database "SQFLite".
I posted all the questions in the JSON form but did not match the level and class of the student(Displaying all questions), But I want when I add a new student with their level and class in the internal database"SQFLite", the questions that are displayed must be matched to that of the student.

Le samedi 8 août 2020 14:35:46 UTC+2, Suzuki Tomohiro a écrit :
I felt that you know what to do. Match student’s level (SQFLite) when fetching questions in MySQL.

What is the challenge for you?
On Sat, Aug 8, 2020 at 07:26 Mohamed Yanis <mmoham...@gmail.com> wrote:
Hello,
I have a backend server i.e. I have an external MySQL database (localhost) that contains a "questions" table characterized by their level (Easy, Medium, Hard) and their class(1st class, 2nd class, 3rd class).
I have an internal database (SQFLite) that contains a "students" table with level and class attributes that contain in the external MySQL database.
I want to post only the questions that correspond to the level and class of the student that is already added in the internal database "SQFLite".
I posted all the questions in the JSON form but did not match the level and class of the student currently added, But I want when I add a new student with their level and class in the internal database"SQFLite", the questions that are displayed must be matched to that of the student.



--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Souvik Dutta

unread,
Aug 8, 2020, 12:26:31 PM8/8/20
to Mohamed Yanis, Flutter Development (flutter-dev)
You can query the questions, then extract the level and class info and use this extracted info to match with the students level and class. Then you can use this matched data to create a new list or json object that you can then show to the user. Hope this helps.

Souvik flutter dev

On Sat, Aug 8, 2020, 8:52 PM Mohamed Yanis <mmoham...@gmail.com> wrote:
I want to post only the questions that correspond to the level and class of the student that is already added in the internal database "SQFLite".
I posted all the questions in the JSON form but did not match the level and class of the student(Displaying all questions), But I want when I add a new student with their level and class in the internal database"SQFLite", the questions that are displayed must be matched to that of the student.


--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/fe48074f-0f7a-4a01-ad05-56e13c3f604bo%40googlegroups.com.

Mohamed Yanis

unread,
Aug 8, 2020, 1:30:24 PM8/8/20
to Flutter Development (flutter-dev)
I know the idea, but I don't know how he does it. Can You Help Me :)
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Suzuki Tomohiro

unread,
Aug 8, 2020, 4:20:57 PM8/8/20
to Mohamed Yanis, Flutter Development (flutter-dev)
Hi Mohamed,

Do you know how to query SQFLite?
Do you know how to query MySQL?
Do you know how to exchange data between Flutter app and your backend server using HTTP?

On Sat, Aug 8, 2020 at 11:22 Mohamed Yanis <mmoham...@gmail.com> wrote:
I want to post only the questions that correspond to the level and class of the student that is already added in the internal database "SQFLite".
I posted all the questions in the JSON form but did not match the level and class of the student(Displaying all questions), But I want when I add a new student with their level and class in the internal database"SQFLite", the questions that are displayed must be matched to that of the student.


Le samedi 8 août 2020 13:26:16 UTC+2, Mohamed Yanis a écrit :

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Mohamed Yanis

unread,
Aug 9, 2020, 4:02:32 AM8/9/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Yes, I know how to query SQFLite and MySQL, but I don't know how to exchange data between Flutter application and your backend server using HTTP?
My problem is in the display of the questions which are all displayed, and they are not dependent on the level and the class of the student

Souvik Dutta

unread,
Aug 9, 2020, 4:09:02 AM8/9/20
to Mohamed Yanis, Flutter Development (flutter-dev)
Suppose A contains the SQFlite data and B contains the level/class of the student
Then you can do

C = []; // container for the required data
for (var a = 0; a <length(A); a++){
    if (A[a].level == B.level){
        C.append(A[a]);
    }
}

Now you can show the data in C. I guess you can morph this to suite your requirement. 

Souvik flutter dev

Mohamed Yanis

unread,
Aug 9, 2020, 6:24:06 AM8/9/20
to Flutter Development (flutter-dev)
hi Souvik Dutta,
I did not understand where to put this code :)
To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Souvik Dutta

unread,
Aug 9, 2020, 6:41:31 AM8/9/20
to Mohamed Yanis, Flutter Development (flutter-dev)
Wherever you want to check for the level before adding the questions. Are you new to flutter?👋😀

Souvik flutter dev

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/c4260c70-ff83-41bb-be48-c58d7039e540o%40googlegroups.com.

Suzuki Tomohiro

unread,
Aug 9, 2020, 7:16:49 AM8/9/20
to Mohamed Yanis, Flutter Development (flutter-dev)
I don't know how to exchange data between Flutter application and your backend server using HTTP


Suzuki Tomohiro

unread,
Aug 9, 2020, 7:52:41 AM8/9/20
to Flutter Development (flutter-dev), Mohamed Yanis
Send SQFLite data to your backend server.
The backend server saves the data to MySQL.

On Sun, Aug 9, 2020 at 07:33 Mohamed Yanis <mmoham...@gmail.com> wrote:
Hi Suzuki ,
It's good I already did but the problem is not there,the problem is how to synchronize between the data of the student (their level, their class) "SQFLite" and the data of Mysql ( level, class)

Suzuki Tomohiro

unread,
Aug 9, 2020, 9:21:55 AM8/9/20
to Flutter Development (flutter-dev), Mohamed Yanis
How: use HTTP post method. JSON format is a nice choice to encode the data.

On Sun, Aug 9, 2020 at 09:10 Mohamed Yanis <mmoham...@gmail.com> wrote:
Please, Why and How to send QFlite data to the Mysql server?

Suzuki Tomohiro

unread,
Aug 9, 2020, 10:14:32 AM8/9/20
to Flutter Development (flutter-dev), Mohamed Yanis
Your Flutter code is using HTTP “GET”, not “POST”. You flutter code is not sending any data to your PHP backend server.
Learn “HTTP GET parameter” or “HTTP POST” to send data from your Flutter code to your server. Google the keywords.

Suzuki Tomohiro

unread,
Aug 9, 2020, 2:52:08 PM8/9/20
to Flutter Development (flutter-dev), Mohamed Yanis
Yes, I know. HTTP POST method can get data from the server.

On Sun, Aug 9, 2020 at 14:33 Mohamed Yanis <mmoham...@gmail.com> wrote:
But, I want to get data (questions) from MySQL database Not Post it!

Suzuki Tomohiro

unread,
Aug 11, 2020, 8:19:07 AM8/11/20
to Flutter Development (flutter-dev), Mohamed Yanis

On Tue, Aug 11, 2020 at 04:08 Mohamed Yanis <mmoham...@gmail.com> wrote:
unfortunately, I did not understand, and I do not know how to do it?

Suzuki Tomohiro

unread,
Aug 11, 2020, 9:48:01 AM8/11/20
to Flutter Development (flutter-dev), Mohamed Yanis
Specify an HTTP POST or GET parameter for the level of questions.

On Tue, Aug 11, 2020 at 09:26 Mohamed Yanis <mmoham...@gmail.com> wrote:
Hi, Suzuki
the user is a student. who must complete the form on the mobile app (SQFLite) which contains their name, level, and class. 
As soon as it is added, only the questions (Get it from MySQL) that correspond to their level should be displayed and their class is not the questions of all levels .
I edited the code in Stackoverflow 
THE PROBLEM :
display of all questions of all levels and classes without depending on the student added.

Suzuki Tomohiro

unread,
Aug 11, 2020, 12:09:36 PM8/11/20
to Flutter Development (flutter-dev), Mohamed Yanis
Nice, it’s getting closer. I’m expecting something like this for the URL:


On Tue, Aug 11, 2020 at 10:23 Mohamed Yanis <mmoham...@gmail.com> wrote:
do we specify a parameter for the level like this :

  getMethod()async{
    String theUrl = 'http://10.0.2.2/Try/Try.php/?idlevel';
    var res = await http.get(Uri.encodeFull(theUrl),headers:{"Accept":"application/json"});
    var responsBody = json.decode(res.body);
    return responsBody;
  }

if the parameter specification for the level is not like this tell me how to do it?

Mohamed Yanis

unread,
Aug 11, 2020, 12:49:17 PM8/11/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Thanks,but it doesn't work.
 it's my PHP code :
``` 
<?php
header("Content-type: application/json; charset=utf-8");
try{
$conn = new PDO('mysql:host=localhost;dbname=relations;charset=utf8','root','');
$conn ->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $exc){
    echo $exc->getMessage();
    die("could not connect");
}
?>
<?php
$makeQuery ="SELECT * FROM questions ";
$stamement = $conn-> prepare($makeQuery);
$stamement -> execute();
$myarray = array();
while ($resultsFrom = $stamement->fetch()){
    array_push(
        $myarray,array(
        "idques"=>intval($resultsFrom['idques']),
        "description"=>$resultsFrom['description']
        )
    );
}
echo json_encode($myarray);
?>
```

Suzuki Tomohiro

unread,
Aug 11, 2020, 2:32:53 PM8/11/20
to Mohamed Yanis, Flutter Development (flutter-dev)
Can you check why your PHP code does not work?

Suzuki Tomohiro

unread,
Aug 12, 2020, 12:33:09 PM8/12/20
to Flutter Development (flutter-dev), Mohamed Yanis
No, your PHP code have to return the questions that match the level.

On Wed, Aug 12, 2020 at 12:20 Mohamed Yanis <mmoham...@gmail.com> wrote:
my PHP code is working normally.
But it still displays all questions and does not display questions that match the level and class of the student.
what do I have to do?

Suzuki Tomohiro

unread,
Aug 12, 2020, 1:33:10 PM8/12/20
to Flutter Development (flutter-dev), Mohamed Yanis
Your PHP code is also responsible for  "display all questions"

On Wed, Aug 12, 2020 at 12:43 Mohamed Yanis <mmoham...@gmail.com> wrote:
I modified my request in the PHP code to this one:
"SELECT * FROM questions where level =? & class=?"
  instead of :

"SELECT * FROM questions",
but there remains the same problem "display all questions"?

Suzuki Tomohiro

unread,
Aug 13, 2020, 7:53:55 AM8/13/20
to Flutter Development (flutter-dev), Mohamed Yanis
Pass level parameter when you need questions of a specific level. When you need all questions, then your Flutter app do not need the parameter.

On Thu, Aug 13, 2020 at 03:29 Mohamed Yanis <mmoham...@gmail.com> wrote:
Hi, Is the problem in requesting PHP code? if yes tell me what should I change ?

Suzuki Tomohiro

unread,
Aug 13, 2020, 1:28:01 PM8/13/20
to Flutter Development (flutter-dev), Mohamed Yanis
Yes, you need to change the query.

On Thu, Aug 13, 2020 at 10:30 Mohamed Yanis <mmoham...@gmail.com> wrote:
I did, but it didn't work
here is the request which we write in the PHP file: "SELECT * FROM questions where level=?"
Is there a change in the query?

Suzuki Tomohiro

unread,
Aug 14, 2020, 10:03:44 AM8/14/20
to Flutter Development (flutter-dev), Mohamed Yanis
No, I don’t. Learn if-statement in PHP to change the query based on the presence of a parameter value.

On Fri, Aug 14, 2020 at 09:59 Mohamed Yanis <mmoham...@gmail.com> wrote:
Hi Suzuki,
Please, Can you correct my query?
 "SELECT * FROM questions where level=?"  

Mohamed Yanis

unread,
Aug 14, 2020, 10:05:44 AM8/14/20
to Suzuki Tomohiro, Flutter Development (flutter-dev)
Ok, thanks. 
Reply all
Reply to author
Forward
0 new messages