Save pictures and display pictures in PHP database

Source: Internet
Author: User
Tags php database

Whether it is the website design or the Office system, the shopping mall, all need to display the picture on the webpage, the picture is extracts from the database, next we take a look through the picture path saves and displays the picture the way:

First, to save the path to the picture in the table, Note: The path is from the WWW directory instead of from the root of the disk,/on behalf of the WWW directory:

The table img is the stored picture path, that is, the path under the WWW directory, since the table is stored in the path, then we can use the PHP link database to obtain:

<?PHPrequire"DBDA.class.php";//calling the encapsulation class    $db=NewDbda (); $sql= "SELECT * FROM book"; $arr=$db->query ($sql); foreach($arr  as $v)//iterate through the contents of each column    {        //The image gets the path with an IMG tag, because the traversal of the IMG is $v[5], so the path is $v[5]        Echo"<div id= ' Hang ' ><a href= ' gouwu.php?bkid={$v[0]} ' >$v[5]} ' ></a> <div class= ' JG ' ><a href= ' gouwu.php?bkid={$v[0]} ' >{$v[1]}</a></div> <div class= ' JG ' style= ' color:red ' >{$v[3]} meta </div> </div>"; }?>

This way you can get the picture through the path, which is very convenient and efficient:

Save pictures and display pictures in PHP database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.