bobdole2281

Lurker
Jun 26, 2013
3
1
26
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:
connection = ( HttpURLConnection ) new URL( "http://marveldcforum.com/android/testpage.php" ).openConnection();

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:
package connecttoasite;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 *
 * @author BobDole
 */
public class Connecttoasite {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        //This is a single line comment
        /*This is a multiple line comment*/
        HttpURLConnection connection = null;  
        PrintWriter outWriter = null;  
        BufferedReader serverResponse = null;  
        StringBuffer buff = new StringBuffer();  
        try 
        {  
        //OPEN CONNECTION  
        connection = ( HttpURLConnection ) new URL( "http://marveldcforum.com/android/testpage.php" ).openConnection();  
 
        //SET REQUEST INFO  
        connection.setRequestMethod( "POST" );  
        connection.setDoOutput( true );  
 
        //CREATE A WRITER FOR OUTPUT  
        outWriter = new PrintWriter( connection.getOutputStream() );  
 
        //PARAMETERS  
        buff.append( "param1=" );   
        buff.append( URLEncoder.encode( "Param 1 Value", "UTF-8" ) );  
        buff.append( "&" );  
        buff.append( "param2=" );   
        buff.append( URLEncoder.encode( "Param 2 Value", "UTF-8" ) );  
 
        //SEND PARAMETERS  
        outWriter.println( buff.toString() );  
        outWriter.flush();  
        outWriter.close();  
 
        //RESPONSE STREAM  
        serverResponse = new BufferedReader( new InputStreamReader( connection.getInputStream() ) );  
 
        //READ THE RESPOSNE  
        String line;  
        while ( (line = serverResponse.readLine() ) != null )   
        {  
        System.out.println( line );  
        }  
        }  
        catch (MalformedURLException mue)  
        {  
        mue.printStackTrace();  
        }  
        catch (IOException ioe)  
        {  
        ioe.printStackTrace();  
        }  
        finally 
        {  
        if ( connection != null )  
        connection.disconnect();  
 
        if ( serverResponse != null )  
        {  
        try { serverResponse.close(); } catch (Exception ex) {}  
        }  
        }  
    }
}

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:
<?php


				$hostname =              "bobdole2.db.10289428.hostedresource.com"; //I changed this
				$username = "bobdole2"; //I changed this
				$password = "Datapassblah"; //I changed this
				$dbname = "bobdole2";  //I changed this

				$con = mysqli_connect($hostname, $username, $password, $dbname) or DIE ('Unable to connect to databasessssssss');

				
				//File Properties
				$file = $_FILES['image']['tmp_name'];
				
				//Set comments variable
				$commentslink = "http://marveldcforum.com/index.php?board=22.0";
				
				/************************************************
							THIS SETS THE VARIABLES
				************************************************/
				$i = 0; //Loop counter
				//total array
				$result = mysqli_query($con, "SELECT ID, Date, Likes, Dislikes, Name, Filename FROM meme ORDER BY Date DESC;");
				while ($row = mysqli_fetch_array($result)) 
				{

				if ($i == 0)
				{
				echo "Meme ".$i.""; echo "\r\n";
				echo $row['Name']; echo "\r\n";
				echo $row['Filename']; echo "\r\n";
				echo "Likes: "; echo $row['Likes']; echo "\r\n";
				echo "Dislikes: "; echo $row['Dislikes']; echo "\r\n";
				
				echo "\r\n";
				}
				$i=$i+1;
				}
?>

So it all works so far. The output is:

Meme 0
Its so bad
powerglove (1).jpg
Likes: 5
Dislikes: 0

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:
 
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.
 
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.