Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Cat
    Cat is offline
    Junior Member Cat's Avatar
    Join Date
    Jul 2006
    Location
    Finland
    Posts
    20
    Member #
    13537
    Hello again! I store my graphics in a MySQL database and this is the code I'm using to display them on my page:

    PHP Code:
     <?php 

    //MySQL connection variables 
    $user="blahblah";  
    $host="localhost";  
    $password="blahblah";  
    $database="blahblahblah";  
    $connection mysql_connect($host,$user,$password)  
    or die (
    "couldn't connect to server"); $db mysql_select_db($database,$connection)  
    or die (
    "Couldn't select database");  

    //Which mySQL table to select from and in what order 
    $query "select * from `layouts` order by id desc";  

    $result mysql_query($query$connection) or die ("Could not execute query : $query ." mysql_error());  
    $rows mysql_num_rows($result); 
    if (
    $rows=="0") { echo "No layouts found."; } 


    //Gets and assigns variables to array 
    while ($row=mysql_fetch_array($result)) {  
    $id=$row["id"];  
    $title=$row["title"];  
    $artist=$row["artist"];  
    $artisturl=$row["artisturl"];   
    $type=$row["type"];  
    $size=$row["size"];  
    $date=$row["date"];  
    $previewimage=$row["previewimage"]; 
    $download=$row["download"];  
    $preview=$row["preview"]; 
    $dcounter=$dcounter["dcounter"]; 
    $pcounter=$pcounter["pcounter"];  

    //Prints out results 
    echo "<table id=\"box_top\"><tr> 
    <tr><td> 
    <b>
    $title</b> 
    </td> 
    </tr> 
    </table> 
         
    <table id=\"box\"> 
    <tr> 
    <td valign=\"top\"> 
    <img src=\"
    $previewimage\" width=\"160\" height=\"110\" border=\"0\" alt=\"\"> 
    </td>  
    <td valign=\"top\" width=\"170\"> 
    <b>Added</b>: 
    $date 
    <br><b>Type</b>: 
    $type 
    <br><b>Size</b>: 
    $size 
    <br><b>Designer</b>: <a href=\"
    $artisturl\" target=\"_blank\">$artist</a> 
    <br><b>Previews</b>: 
    $pcounter 
    <br><b>Downloads</b>: 
    $dcounter 
    <br><br> 
    <a href=\"
    $preview\"><b>Preview</b></a> &nbsp; <a href=\"$download\"><b>Download</b></a> 
    </td> 
    </tr> 
    </table><br>"



    ?>
    $dcounter=$dcounter["dcounter"]; and $pcounter=$pcounter["pcounter"]; should count the downloads/previews and $pcounter and $dcounter should display them? So, the problem is it won't display the number of the downloads/previews. I know I'm doing something wrong, but I don't know what.

    Anyone knows?

    By the way, maybe I'm doing something wrong in phpMyAdmin? Both dcounter and pcounter are set to VARCHAR(5) not null Default: 0

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    $dcounter=$dcounter["dcounter"]; and $pcounter=$pcounter["pcounter"]; should count the downloads/previews and $pcounter and $dcounter should display them? So, the problem is it won't display the number of the downloads/previews. I know I'm doing something wrong, but I don't know what.
    Should it not be $row["dcounter"] and $row["pcounter"] ?

  4. #3
    Cat
    Cat is offline
    Junior Member Cat's Avatar
    Join Date
    Jul 2006
    Location
    Finland
    Posts
    20
    Member #
    13537
    Oh, my mistake, but even if I change it the code doesn't count the downloads/previews, it only displays a 0. Do you know how to fix it?

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Why have it as VARCHAR, if it is a whole number value. It should be int ?

    And, when a user requests to see an image, you will have to update that row, you will need to increment the columns by 1. You are not doing that, that is why they return 0.

  6. #5
    Cat
    Cat is offline
    Junior Member Cat's Avatar
    Join Date
    Jul 2006
    Location
    Finland
    Posts
    20
    Member #
    13537
    Thanks SO MUCH for your help! One more question please, I'm not very good at php can you please tell me how to update a row or what do I need to change in the code?
    Thanks!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:28 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com