1. Are you ready for the Galaxy S20? Here is everything we know so far!

Meme App: Almost there just need a little help

Discussion in 'Android Development' started by bobdole2281, Jun 26, 2013.

  1. bobdole2281

    bobdole2281 Lurker
    Thread Starter

    Hi everybody, I love this site btw.

    I am working on a "Superhero meme App" from MarvelDCForum.

    I run the website Marvel DC Forum and I have made a mysql database there that I use php to run. The website works fine, but I am trying to make an app to grow the company.

    I'm in this alone and a little over my head. I have eclipse and the basics setup to make apps, and I can make very simple ones so far. I am currently connecting to a php page and performing "Select *" from my database using
    PHP:
    1. connection = ( HttpURLConnection ) new URL( "http://marveldcforum.com/android/testpage.php" ).openConnection();  
    2.  
    It all actually works fine, I'm just looking for some direction on where to go next. I need a way to display images.



    Here is my code: (Just a rough draft)
    PHP:
    1. package connecttoasite;
    2.  
    3. import java.io.BufferedReader;
    4. import java.io.IOException;
    5. import java.io.InputStreamReader;
    6. import java.io.PrintWriter;
    7. import java.net.HttpURLConnection;
    8. import java.net.MalformedURLException;
    9. import java.net.URL;
    10. import java.net.URLEncoder;
    11.  
    12. /**
    13.  *
    14.  * @author BobDole
    15.  */
    16. public class Connecttoasite {
    17.  
    18.     /**
    19.      * @param args the command line arguments
    20.      */
    21.     public static void main(String[] args) throws IOException {
    22.         //This is a single line comment
    23.         /*This is a multiple line comment*/
    24.         HttpURLConnection connection = null;  
    25.         PrintWriter outWriter = null;  
    26.         BufferedReader serverResponse = null;  
    27.         StringBuffer buff = new StringBuffer();  
    28.         try
    29.         {  
    30.         //OPEN CONNECTION  
    31.         connection = ( HttpURLConnection ) new URL( "http://marveldcforum.com/android/testpage.php" ).openConnection();  
    32.  
    33.         //SET REQUEST INFO  
    34.         connection.setRequestMethod( "POST" );  
    35.         connection.setDoOutput( true );  
    36.  
    37.         //CREATE A WRITER FOR OUTPUT  
    38.         outWriter = new PrintWriter( connection.getOutputStream() );  
    39.  
    40.         //PARAMETERS  
    41.         buff.append( "param1=" );  
    42.         buff.append( URLEncoder.encode( "Param 1 Value", "UTF-8" ) );  
    43.         buff.append( "&" );  
    44.         buff.append( "param2=" );  
    45.         buff.append( URLEncoder.encode( "Param 2 Value", "UTF-8" ) );  
    46.  
    47.         //SEND PARAMETERS  
    48.         outWriter.println( buff.toString() );  
    49.         outWriter.flush();  
    50.         outWriter.close();  
    51.  
    52.         //RESPONSE STREAM  
    53.         serverResponse = new BufferedReader( new InputStreamReader( connection.getInputStream() ) );  
    54.  
    55.         //READ THE RESPOSNE  
    56.         String line;  
    57.         while ( (line = serverResponse.readLine() ) != null )  
    58.         {  
    59.         System.out.println( line );  
    60.         }  
    61.         }  
    62.         catch (MalformedURLException mue)  
    63.         {  
    64.         mue.printStackTrace();  
    65.         }  
    66.         catch (IOException ioe)  
    67.         {  
    68.         ioe.printStackTrace();  
    69.         }  
    70.         finally
    71.         {  
    72.         if ( connection != null )  
    73.         connection.disconnect();  
    74.  
    75.         if ( serverResponse != null )  
    76.         {  
    77.         try { serverResponse.close(); } catch (Exception ex) {}  
    78.         }  
    79.         }  
    80.     }
    81. }
    So basically it just connects to http://marveldcforum.com/android/testpage.php and shows the php database statement.

    Here is my php code currently online:
    PHP:
    1. <?php
    2.  
    3.  
    4.                 $hostname =              "bobdole2.db.10289428.hostedresource.com"; //I changed this
    5.                 $username = "bobdole2"; //I changed this
    6.                 $password = "Datapassblah"; //I changed this
    7.                 $dbname = "bobdole2";  //I changed this
    8.  
    9.                 $con = mysqli_connect($hostname, $username, $password, $dbname) or DIE ('Unable to connect to databasessssssss');
    10.  
    11.                
    12.                 //File Properties
    13.                 $file = $_FILES['image']['tmp_name'];
    14.                
    15.                 //Set comments variable
    16.                 $commentslink = "http://marveldcforum.com/index.php?board=22.0";
    17.                
    18.                 /************************************************
    19.                             THIS SETS THE VARIABLES
    20.                 ************************************************/
    21.                 $i = 0; //Loop counter
    22.                 //total array
    23.                 $result = mysqli_query($con, "SELECT ID, Date, Likes, Dislikes, Name, Filename FROM meme ORDER BY Date DESC;");
    24.                 while ($row = mysqli_fetch_array($result))
    25.                 {
    26.  
    27.                 if ($i == 0)
    28.                 {
    29.                 echo "Meme ".$i.""; echo "\r\n";
    30.                 echo $row['Name']; echo "\r\n";
    31.                 echo $row['Filename']; echo "\r\n";
    32.                 echo "Likes: "; echo $row['Likes']; echo "\r\n";
    33.                 echo "Dislikes: "; echo $row['Dislikes']; echo "\r\n";
    34.                
    35.                 echo "\r\n";
    36.                 }
    37.                 $i=$i+1;
    38.                 }
    39. ?>
    So it all works so far. The output is:

    It shows the first meme up right now. I will have them click next to show the second meme eventually and so on.

    I need the filepath: marveldcforum.com/images/powerglove (1).jpg to actually show an image somehow instead of the filepath. I have no idea how to do this.

    Please, any help would be amazing! :smokingsomb:
     



    1. Download the Forums for Android™ app!


      Download

       
  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    I moved this to the application development forum to get some better eyes on it.:)
     
  3. bobdole2281

    bobdole2281 Lurker
    Thread Starter

    Alright, thanks. I just need to figure out how to turn a filepath of an image into an image on my XML page. I have the connection to the database set.
     
  4. shredcode

    shredcode Newbie

    To better understand what you are looking to do, so we can help direct more appropriately
    ...

    How are you wanting to show the image to the user within your android app? Are you looking to use a webView and view your web page, or are you looking to load the image from the site and then populate an ImageView with it?

    Depending on how you are wanting the user interface to be, it will direct your solution.
     
Loading...
Similar Threads - Meme App Almost
  1. Frank H
    Replies:
    1
    Views:
    38
  2. dorlow
    Replies:
    2
    Views:
    137
  3. App Update
    Replies:
    0
    Views:
    76
  4. TechExec001
    Replies:
    2
    Views:
    350
  5. 1987jjc
    Replies:
    1
    Views:
    207
  6. CARL BIRT
    Replies:
    5
    Views:
    277
  7. Anonymous54321
    Replies:
    2
    Views:
    209
  8. Annabelle iris
    Replies:
    0
    Views:
    313
  9. sullencab
    Replies:
    2
    Views:
    717
  10. rootabaga
    Replies:
    4
    Views:
    956

Share This Page

Loading...