Android Question (solved, thanks) Read db mySQL but not show all the db

Discussion in 'Android Questions' started by f0raster0, Mar 4, 2015.

  1. f0raster0

    f0raster0 Active Member Licensed User

    I am following the KMatle's tutorials

    my dbbase has three columns:

    ID contact shuttle
    1 person1 2
    2 person2 3
    3 person3 2
    4 person4 1

    How could I show in my App only the file where shuttle=2 ?
    I don't have idea how I could do it. Thanks in advance

    My code is same as the tutorials:
    Code:
    Sub Activity_Create(FirstTime As Boolean)
     
        
    Activity.LoadLayout("1")
        
    Activity.Title ="Playing with php/MySql"

    End Sub

    Sub JobDone(Job As HttpJob)
        
    ProgressDialogHide
        
    If Job.Success Then
            
    Dim res As String
            res = Job.GetString
            
    Log("Back from Job:" & Job.JobName )
            
    Log("Response from server: " & res)
                 
            
    Dim parser As JSONParser
            parser.Initialize(res)
         
            
    Select Job.JobName
                         
                
    Case "GetP"
                    
    Dim ListOfPersons As List
                    
    Dim PersonID As Int
                    
    Dim PersonContact As String
                    
    Dim PersonCar As String
                 
                    ListOfPersons = parser.NextArray 
    'returns a list with maps
                 
                    PersonsListview.Clear
                 
                    
    If ListOfPersons.Size=0 Then
                        PersonsListview.AddSingleLine (
    "No persons found...")
                    
    Else
                        
    For i = 0 To ListOfPersons.Size - 1
                            
    Dim Person As Map
                            Person = ListOfPersons.Get(i)                                         
                            PersonID = Person.Get(
    "ID")
                            PersonContact = Person.Get(
    "contact")
                            PersonCar = Person.Get(
    "car")
                          
                         
                            PersonsListview.AddSingleLine (PersonID & 
    ", " & PersonContact & ", " & ",Car: " & PersonCar)

                     
                     
                        
    Next
                    
    End If     
            
    End Select
         
         
         
        
    Else
            
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
        
    End If
        Job.Release
    End Sub

    Sub Button1_Click
        
    Dim GetPersons As HttpJob
        GetPersons.Initialize(
    "GetP", Me)
        GetPersons.download2(
    "http://androidatest.site88.net/Test4.php" , Array As String ("action""GetPersons"))
    End Sub
    Sub Button2_Click

    End Sub
    php:
    Code:
    <?php

    $databasehost=
    "mysql1.000webhost.com";
    $databaseusername=
    "x";
    $databasepassword=
    "x";
    $databasename=
    "x";

    $con = mysql_connect($databasehost,$databaseusername,$databasepassword) 
    or die(mysql_error());
    mysql_select_db($databasename) 
    or die(mysql_error());

    $action = $_GET[
    "action"];
    switch ($action)
    {
        
    Case "GetPersons":
            $q = mysql_query(
    "SELECT ID, contact, car FROM booking");
            $rows = 
    array();
            
    while($r = mysql_fetch_assoc($q))
            {
                $rows[] = $r;
            
    }
            print json_encode($rows);
        break;

    }
    ?>
     
    Last edited: Mar 15, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. f0raster0

    f0raster0 Active Member Licensed User

    ok Erel thanks, I will return to your example.. :oops:
    Edit: trying Erel's example

    I have an error here, line 78: NumberFormat2, because I have replaced "population" for "address"
    lblPopulation.Text = NumberFormat2(m.Get("address"),0, 0, 0, True) & " (K)"

    Code:
    <!-- Hosting24 Analytics Code -->

    <script 
    type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

    <!-- 
    End Of Analytics Code -->

    Response from 
    server: [{"address":"Larnach Castle Lodge"}]

    <!-- Hosting24 Analytics Code -->

    <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>

    <!-- End Of Analytics Code -->

    java.lang.NumberFormatException: Invalid double: "Larnach Castle Lodge"
        at java.lang.StringToReal.invalidReal(StringToReal.java:63)
        at java.lang.StringToReal.initialParse(StringToReal.java:114)
        at java.lang.StringToReal.parseDouble(StringToReal.java:263)
        at java.lang.Double.parseDouble(Double.java:295)
        at anywheresoftware.b4a.BA.ObjectToNumber(BA.java:610)
        at Antu.php.samples.mysql.main._jobdone(main.java:558)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
        at anywheresoftware.b4a.keywords.Common$5.run(Common.java:962)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5479)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)
    running waiting messages (2)
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = true **
     
    Last edited: Mar 4, 2015
  4. sorex

    sorex Expert Licensed User

    stick to what you already had, Erel's code is not safe to use.

    Code:
    GetPersons.download2("http://androidatest.site88.net/Test4.php" , Array As String ("action""GetPersons","shuttle"2))
    Code:
    Case "GetPersons":
     $shuttle=mysql_real_escape_string($_GET[
    "shuttle"]); 
     $q = mysql_query(
    "SELECT ID, contact, shuttle FROM booking where shuttle=".$shuttle;
     
    f0raster0 and Cableguy like this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    The php script posted in the MySQL tutorial is safe to use if you understand what it does and how the server should be configured.

    Otherwise I wouldn't have publicly run this script on this server.
     
    NJDude likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice