Help with php gallery code

Discussion in 'PHP' started by Alibaba143, Nov 15, 2012.

  1. #1
    hi guys, i m trying to create a php site for images, i m new in php, all i want is to show the name or title of the picture under the photo in a box, and also want to add number of views. can anyone help me with the db structure for number of views and showing image title from db. here is my code.

    <?php
    include('config.php');
    echo"<div class='imageRow'>
    <div class='set'>";
    $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC LIMIT 5;");
    while($row = mysql_fetch_array($result))
    {

    echo '<div class="single"><div class="wrap">
    <a href="'.$row['location'].'" title="'.$row['caption'].'" details="'.$row['details'].'"><img src="'.$row['location'].'" /></a>
    </div></div>';
    }
    ?>
     
    Alibaba143, Nov 15, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    Freebie from today:

    
    echo '<div class="single"><div class="wrap">
    <a href="'.$row['location'].'" title="'.$row['caption'].'" details="'.$row['details'].'"><img src="'.$row['location'].'" /></a><br />' . $row['caption'] . '
    </div></div>';
    
    Code (markup):
    ps next time, put scripting/programming code between [ code ] tags!!!
     
    EricBruggema, Nov 16, 2012 IP
  3. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help :) any idea how to show that how many times the image has been viewed??
     
    Alibaba143, Nov 16, 2012 IP
  4. bluebenz

    bluebenz Well-Known Member

    Messages:
    876
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    138
    #4
    
    echo $row['viewed'];
    
    Code (markup):
    simple, right ?
     
    bluebenz, Nov 16, 2012 IP
  5. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks for the reply, but i need to know the database structure, and how it wil increase automatically each time the image is viewed
     
    Alibaba143, Nov 16, 2012 IP
  6. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #6
    then you need to learn PHP, you ask questions wich answers can be found in the source code. We can't look tru our glass ball and see what code you are using! ;)
     
    EricBruggema, Nov 16, 2012 IP
  7. Alibaba143

    Alibaba143 Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    asd.jpg
    this is my database

    index.php
    
    <html>
    
    
    <head>
    <link href='http://fonts.googleapis.com/css?family=Fredoka+One|Open+Sans:400,700' rel='stylesheet' type='text/css'>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
    <meta name="description" content="description"/> 
    <link rel="stylesheet" type="text/css" href="style.css" media="screen"/>
    <title>EntroPhobia</title>
    </head>
    <body style="margin: 0 12%;">
    
    
    <div class="container">
    
    
        <div class="header">
            <a href="index.php"><span>EntroPhobia</span></a>
    </div>
    
    
        <div class="stripes"><span></span></div>
        
        <div class="nav">
            <a href="index.php">Home</a>
            <a href="recent.php">Recent Pics</a>
            <a href="popular.php">Popular Pics</a>
            <a href="cat.php">Categories</a>
            <a href="follow.php">Follow Us On FB</a>
            <div class="clearer"><span></span></div>
        </div>
    
    
        <div class="stripes"><span></span></div>
    
    
        <div class="main">
        <div class="content">
        <h1><a href="recent.php">Recent Pics</a></h1>
        <?php
        
        include('config.php');
        echo"<div class='imageRow'>
          <div class='set'>";
        $query="select * FROM photos";
    $result = mysql_query("SELECT * FROM photos ORDER BY id DESC LIMIT 5;");
    while($row = mysql_fetch_array($result))
    {
           echo '<div class="single"><div class="wrap">
         <div class="details">
         <div class="views">
    <a href="'.$row['location'].'" title="'.$row['caption'].'"><img src="'.$row['location'].'" /></a>' . $row['details'] . $row['hits'] . '
    </div></div></div></div>';
    }                
    ?>
        </div>    
        </div>
    <h1>Popular Pictures</h1>    
    
    
    </body>
    
    
    </html> `    
    
    Code (markup):
    CSS:

    
    a img {
      border: none;
    }
    
    
    /* header */
    .header {
        background: #111;
        border-bottom: 1px solid #333;
        font: normal 2em sans-serif;
        height: 100px;
        
    }
    .header a {
        color: #888;
        display: block;
        line-height: 120px;
        text-decoration: none;
        width: 100%;
    }
    
    
    .header a:hover {
        background: #191919;
        color: #BBB;
    }
    
    
    /* content elements */
    .content h1 {
        background: url(img/bgh1.gif) repeat-x left bottom;
        color: #EEE;
        margin-bottom: 10px;
        padding: 6px 0 4px;
    }
    .content a {
        color: #999;
        text-decoration: underline;
    }
    .content a:hover {color: #CCC;}
    .content .descr {margin-bottom: 5px;}
    
    
    /* navigation */
    .nav {background: #191919 url(img/nav.gif);}
    .nav a {
        background: #191919 url(img/nav.gif);
        border-right: 1px solid #161616;
        color: #CCC;
        float: left;
        font: bold 1em Verdana,sans-serif;
        line-height: 51px;
        padding: 0 20px;
    }
    .nav a:hover {
        background: #191919 url(img/nav_hover.gif);
    }
    
    
    /* misc */
    .clearer {clear: both;}
    .stripes {
        background: #333 url(img/stripe.gif);
        height: 6px;
    }
    .left {float: left;}
    .right {float: right;}
    
    
    /* sub-navigation */
    .subnav {
        background: #2A2A2A;
        border: 1px solid #1E1E1E;
        border-top-color: #444;    
        padding: 12px;
    }
    .subnav h1 {padding-top: 8px;}
    .subnav ul {margin: 0;}
    .subnav li {
        background: url(img/li.gif) no-repeat left bottom;
        list-style: none;
        margin: 0;
    }
    .subnav li a {
        color: #777;
        line-height: 2.4em;
        padding-left: 18px;
        text-decoration: none;
    }
    .subnav li a:hover {color: #BBB;}
    
    
    .content {
      margin:0 auto;
      width:909px;
      margin-top:20px;
    }
    
    
    body {
      background: #222222 url(../images/bg-checker.png);
    }
    
    
    body, input, textarea {
      color: white;
      text-shadow: 0 -1px 0 black;
      font-size: 16px;
      line-height: 1.625em;
      font-family: "Open Sans", "lucida grande", tahoma, sans-serif;
      font-weight: 600;
      -webkit-font-smoothing: antialiased;
    }
    
    
    
    
    #lightbox {
      text-shadow: none;
    }
    
    
    h1, h2, h3, h4, h5, h6 {
      font-family: "Fredoka One", "lucida grande", tahoma, sans-serif;
      font-weight: 400;
      letter-spacing: 0.03em;
      line-height: 1.625em;
      margin: 0;
      color: #d0eb6a;
    }
    
    
    
    
    h1 {
      font-size: 40px;
      line-height: 1.2em;
    }
    
    
    h2 {
      font-size: 34px;
      line-height: 1.45em;
      margin-bottom: 0.2em;
    }
    
    
    /* line 65, ../sass/screen.sass */
    h3 {
      font-size: 16px;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: #88a616;
    }
    
    
    /* line 71, ../sass/screen.sass */
    h4 {
      font-size: 16px;
    }
    
    
    /* Text elements */
    /* line 77, ../sass/screen.sass */
    p {
      margin: 0 0 1.25em 0;
      line-height: 1.625em;
    }
    
    
    /* line 81, ../sass/screen.sass */
    ul, ol {
      margin: 0 0 1.25em 0;
    }
    
    
    /* line 84, ../sass/screen.sass */
    dt {
      font-weight: bold;
    }
    
    
    /* line 87, ../sass/screen.sass */
    dd {
      margin-bottom: 1.625em;
    }
    
    
    /* line 90, ../sass/screen.sass */
    strong {
      font-weight: bold;
    }
    
    
    /* line 93, ../sass/screen.sass */
    
    
    
    
    /* line 96, ../sass/screen.sass */
    pre {
      background: rgba(0, 0, 0, 0.4);
      color: #e7931a;
      font: 14px Monaco, Consolas, "Andale Mono", "DejaVu Sans Mono", monospace;
      line-height: 1.5;
      margin: 20px 0 20px 0;
      overflow: auto;
      padding: 1em;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      -ms-border-radius: 4px;
      -o-border-radius: 4px;
      border-radius: 4px;
      -webkit-box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1), inset 0 2px 6px 2px black;
      -moz-box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1), inset 0 2px 6px 2px black;
      box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1), inset 0 2px 6px 2px black;
    }
    
    
    
    
    a {
      color: #8ad459;
      text-decoration: none;
    }
    /* line 125, ../sass/screen.sass */
    a:hover {
      color: #589e29;
    }
    
    
    .imageRow:after {
      content: "";
      display: table;
      clear: both;
    }
    /* line 320, ../sass/screen.sass */
    .imageRow .single {
    -moz-transition-duration: 0.5s;
        -moz-transition-timing-function: ease-out;
        -webkit-transition-duration: 0.5s;
        -webkit-transition-timing-function: ease-out;
      float: left;
      height:220px;
      width:150px;
      padding:5px;
      margin:0 5px;
      border:1px solid gray;
    }
    .imageRow .single:hover {
    background-color:#D0EB6A;
    }
    .wrap{
      height:100%;
      width:100%;
      overflow:hidden;
    }
    .details{padding:0px 0px;
    text-align:center;}
    .views{font-size:0.9em;}
    
    
    /* line 332, ../sass/screen.sass */
    .imageRow .single a img {
      max-width:150px;
      min-height:150px;
      border-radius: 4px;
    }
    
    
    .imageRow .set {
      float: left;
      background: rgba(255, 255, 255, 0.1);
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      -ms-border-radius: 4px;
      -o-border-radius: 4px;
      border-radius: 4px;
      -webkit-box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
      -moz-box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
      box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.5);
      -webkit-transition: all 0.2s ease-out;
      -moz-transition: all 0.2s ease-out;
      -ms-transition: all 0.2s ease-out;
      -o-transition: all 0.2s ease-out;
      transition: all 0.2s ease-out;
      padding:10px;
    }
    /* line 343, ../sass/screen.sass */
    .imageRow .set:hover {
      background: rgba(255, 255, 255, 0.2);
    }
    /* line 346, ../sass/screen.sass */
    .imageRow .set .single a {
      background: none;
      -webkit-border-radius: 0;
      -moz-border-radius: 0;
      -ms-border-radius: 0;
      -o-border-radius: 0;
      border-radius: 0;
      -webkit-box-shadow: none;
      -moz-box-shadow: none;
      box-shadow: none;
      margin-right: 0;
    }
    
    Code (markup):
    NOTE: I am just trying to learn Php, CSS is copied from another template, trying to create a gallery, i hope now u can help.
     
    Alibaba143, Nov 17, 2012 IP
  8. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #8
    No views available as current script and database doesn't. You can alter the script, but it will be for a beginner a long but fun job to do.

    If you don't want to put your time and energy in this i can alter the script so it does count the views and or more if you wish, pm me for more info.
     
    EricBruggema, Nov 17, 2012 IP