/    Sign up×
Community /Pin to ProfileBookmark

filepath to images / php/mysql + html output

Hi all. Total newbie here, so please forgive my naivete..
I have a site with posters and their descriptions stored in a MySql database. There are several fields, all VARCHAR, and the script I’m quoting below works fine, but it shows broken image icons.

While I know that I should upload jpegs to a folder on the server and
only store filename in a database field (which I did), I’m confused with the
following :

  • 1.

    Where exactly should the picture folder “images” be on the server ?
    Anywhere in the “www” folder ? Within the folder that contains the
    “post-query.php” file ?

  • 2.

    Which of the following should be in the database field :

  • a. [url]http://www.mysite.com/images/123.jpeg[/url]
    b. [url]www.mysite.com/images/123.jpeg[/url]
    c. /images/123.jpeg
    d. images/123.jpeg
    e. /123.jpeg
    f. 123.jpeg

  • 3. Correspondingly, should the php code read (field name in mysql table is called ‘Code’):
  • a. if($line

    [Code] !=””){
    echo “<img
    src=”http://www.mysite.com/images/”.$row[‘fileName’].””>”;
    }else{
    $pic=” – “;
    }

    b. if($line[Code] !=””){
    echo “<img
    src=”www.mysite.com/images/”.$row[‘fileName’].””>”;
    }else{
    $pic=” – “;
    }

    c. if($line[Code] !=””){
    echo “<img
    src=”images/”.$row[‘fileName’].””>”;
    }else{
    $pic=” – “;
    }

    4. The html I have reads as follows (all fields before <img src> are text fields and work fine) :
    [code=html]
    PRINT(“<TR BGCOLOR=$bgcolor><TD>$num.</TD><TD>$auth</td><TD>$title</TD><TD>$original_title</TD><TD>$country</TD><TD>$director</TD><TD>$cast</TD><TD>$year</TD><TD>$original_year</TD><TD>$producer</TD><TD>$circ</TD><TD>$size</TD><TD>$print</TD><TD><img src=”=$row{[‘fileName’]
    }”></TD><TD>$remarks</TD></TR>”);
    [/code]

    Begging for help ! I’ve spent hours on Google and while everyone agrees that storing urls in mysql is the way to go, no one gives a single example !!!
    Thanx
    Tom ?

    to post a comment
    PHP

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @NogDogJul 08.2006 — I usually just put just the filename in the database ("image.jpg") and then let my script specify the full URL or directory as needed. Or, if desired, you can specify the directory in a separate, generally static table in the DB if you don't want it hard-coded in the script. Either way if you change your site layout, move to another host, etc., all you have to do is change the value in the script or that one database table/row, rather than all the entries in your database.

    Normally the images will be in a directory within your public_html (www) directory hierarchy. If you wanted them outside of that hierarchy, then you would need to write an "image server" script to display them, but there's probably no reason to consider doing that unless you want to enforce some sort of access-control of the images.
    Copy linkTweet thisAlerts:
    @aussie_girlJul 08.2006 — I agree with NogDog....

    And if I only have a couple of field names that I need I use the list function..

    [code=php]
    //Or create a path to your pics something like this (not tested)
    $folder = "images/"
    $path = $folder.$pic
    $query = "SELECT show_name, show_image FROM shows WHERE shows.show_id = $type";
    $result = mysql_query($query);
    list($show, $pic) = mysql_fetch_array($result, MYSQL_NUM);
    echo "<table align="center"><tr><td>$show</td>
    <td><img src=[B]"$pic or $path"[/B] height="150" width="200"></td>
    </tr></table>";[/code]
    Copy linkTweet thisAlerts:
    @tomkzauthorJul 08.2006 — Thanx guys, will try it 1st thing in the morning ?
    ×

    Success!

    Help @tomkz spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...