Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Fetch Images From URLs in MYSQL

  1. #1
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Fetch Images From URLs in MYSQL

    I have a mysql database set up and have uploaded image paths and various text fields to it. The images are being sent and stored in a folder. What I need help with is how to code my php page correctly to display the images and working links.

    'log_filename' is the image field
    'bands_website' is the link field

    My code:

    Code:
    <?php
    // Make a MySQL Connection
    mysql_connect("") or die(mysql_error());
    mysql_select_db("") or die(mysql_error());
    
    // Insert a row of information into the table "_uploads_log"
    $result = mysql_query("SELECT * FROM _uploads_log WHERE genre LIKE 'Country' ") 
    or die(mysql_error());  
    
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row
    
    // Print out the contents of each row into a table 
    echo " Video: ".$row['log_filename'];echo "<br />";
    echo " Member Name: ".$row['login'];echo "<br />";
    echo " Band Name: ".$row['band_name'];echo "<br />";
    echo " Title: ".$row['title'];echo "<br />";
    echo " Description: ".$row['description'];echo "<br />";
    echo " Prior Artist: ".$row['prior_artist'];echo "<br />";
    echo " Home Town: ".$row['home_town'];echo "<br />";
    echo " Web Site: ".$row['bands_website'];echo "<br />";
    echo " State: ".$row['state'];echo "<br />";
    echo " Genre: ".$row['genre'];echo "<br />";
    echo " Posted: ".$row['date'];echo "<br />";echo "<br />";
    }
    
    ?>
    Thanks in advance for any help. EMT
    Last edited by djr33; 03-04-2010 at 07:11 AM. Reason: fixed [/code] tag

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't understand the difficulty.

    You just need to echo the URL to the image in an <img src="...."> tag and the URL to the website in an <a href="..."> tag.

    Is there something else that is not working?
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for answering so fast. I am going to use this on my site for the "Related Videos" section on my members pages. I wont know the addresses and that' s why I'm setting up a database to handle it. I have just started this and when I'm finished I want to have all files uploaded this way...EMT

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yes, I understand. You should be able to copy this line:
    echo " Posted: ".$row['date'];echo "<br />";echo "<br />";

    And do whatever HTML you need, such as:
    echo "<a href=\"".$row['URLFIELD']."\">LINKNAME</a>";

    If you need help with this formatting, then an introduction to PHP strings tutorial would be a good idea.

    In short:
    echo makes things print into the html.
    Quotes (either double or single) surround literal text.
    Variables can be output as well.
    You can combine any strings into one with a . between them.
    If you need to use quotes (double/single) within the same kind of quotes (double/single) surrounding the string, you must "escape" them like this:
    'can\'t' or "<a href=\"index.htm\">Home</a>"
    In both of those examples the inner quotes are disabled by the slashes.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I got those both to work.

    My Newest Code:

    [CODE]
    <?php
    // Make a MySQL Connection
    mysql_connect("localhost", "database", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());

    // Insert a row of information into the table "_uploads_log"
    $result = mysql_query("SELECT * FROM _uploads_log WHERE genre LIKE 'Country' ")
    or die(mysql_error());

    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row

    // Print out the contents of each row into a table
    echo "<img src=\"folderwhereimagesaresentto/".$row['log_filename']."\" width=92 height=62 hspace=0 vspace=0 border=0></a>";echo "<br />";
    echo " Member: ".$row['login'];echo "<br />";
    echo " Band: ".$row['band_name'];echo "<br />";
    echo " Title: ".$row['title'];echo "<br />";
    echo " Description: ".$row['description'];echo "<br />";
    echo " Prior Artist: ".$row['prior_artist'];echo "<br />";
    echo " Home Town: ".$row['home_town'];echo "<br />";
    echo "<a href=\"".$row['bands_website']."\">Web Site</a>";echo "<br />";
    echo " State: ".$row['state'];echo "<br />";
    echo " Genre: ".$row['genre'];echo "<br />";
    echo " Posted: ".$row['date'];echo "<br /><br />";
    }

    ?>
    [CODE]

    Thank You...ET

  6. #6
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hello again, I'm having a problem with displaying a link. I want my my 'login' data to display and link to my 'bands_website' data.

    My Code is:

    [CODE]
    <LINK REL=STYLESHEET TYPE="text/css" HREF="../../../../site.css">
    <?php
    // Make a MySQL Connection
    mysql_connect("host", "database", "password") or die(mysql_error());
    mysql_select_db("database") or die(mysql_error());

    // Get all the data from the "myydatabase" table
    $result = mysql_query("SELECT * FROM _uploads_log")
    or die(mysql_error());
    echo "<table border='0' cellspacing='6' cellpadding='0'>";
    echo "<tr align='left'></tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td>";
    echo "<img src=\"path/".$row['log_filename']."\" width=92 height=62 hspace=0 vspace=0 border=0></a>";echo "</td><td valign='middle'>";
    echo "Title: ";echo $row['title'];echo "<br />";
    echo "Band: ";echo $row['band_name'];echo "<br />";
    echo "Member: ";echo $row['login'];echo "<br />";
    echo "Description: ";echo $row['description'];echo "<br />";
    echo "Member: ";echo "<a href=\"".$row['bands_website']."\">I WANT THIS TO BE THE 'login' DATA NOT TEXT FOR A LINK</a>";echo "<br />";
    echo $row['date'];
    echo "</td><td>";

    }

    ?>
    [CODE]

    Thank You...EMT

  7. #7
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I looked around and pieced it together.

    [CODE]
    echo "Member: ";echo "<a href=".$row['bands_website'] . ">" .$row['login'] . "</a>";echo "<br />";
    [CODE]

    EMT

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ok, good. If you still have trouble with this, then an introductory PHP tutorial should cover the questions about strings (text output), and this is a good tutorial for learning how to use mysql:
    http://php-mysql-tutorial.com

    (The layout is confusing: the oldest tutorials are the most basic so go to the last page of tutorials and start with the "last" one, even though that's really the first. At the moment that's: http://www.php-mysql-tutorial.com/wi...px?PageIndex=2 )
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. #9
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, Thanks for your help. I will check out the links you provided. I'm now trying to link an image, then I will be done with this part and can use it on my site.

  10. #10
    Join Date
    Mar 2010
    Location
    Wisconsin
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    OK, this is driving me crazy. Can you help me with the above problem. I want to make the image that's displayed from the 'log_filename' field a link by using the data from the 'bands_website' (which is a url).

    [CODE]
    <LINK REL=STYLESHEET TYPE="text/css" HREF="../../../../site.css">
    <?php
    // Make a MySQL Connection
    mysql_connect("host", "database", "passwd") or die(mysql_error());
    mysql_select_db("myydatabase") or die(mysql_error());

    // Get all the data from the "myydatabase" table
    $result = mysql_query("SELECT * FROM _uploads_log")
    or die(mysql_error());
    echo "<table border='0' cellspacing='6' cellpadding='0'>";
    echo "<tr align='left'></tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td>";
    echo "<img src=\"path/".$row['log_filename']."\" width=92 height=62 hspace=0 vspace=0 border=0></a>";echo "</td><td valign='middle'>";
    echo "Title: ";echo "<a href=".$row['bands_website'] . ">" .$row['title'] . "</a>";echo "<br />";
    echo "Band: ";echo $row['band_name'];echo "<br />";
    echo "Description: ";echo $row['description'];echo "<br />";
    echo "Member: ";echo "<a href=".$row['bands_website'] . ">" .$row['login'] . "</a>";echo "<br />";
    echo "Posted: ";echo $row['date'];
    echo "</td><td>";

    }


    ?>
    [CODE]

    Thanks again in advance for any help...EMT

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •