Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

[Resolved] Downloads display thing..

SpaceshipSpaceship
SpaceshipSpaceship
NamecheapNamecheap
Watch

Catie

New Member
Impact
0
Downloads display thing..

Hello everyone! I store my graphics in a MySQL database and this is the code I'm using to display them on my page:

PHP:
<?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>   <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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
should this

PHP:
$preview=$row["preview"]; 
$dcounter=$dcounter["dcounter"]; 
$pcounter=$pcounter["pcounter"];

be

PHP:
$preview=$row["preview"]; 
$dcounter=$row["dcounter"]; 
$pcounter=$row["pcounter"];
 
0
•••
baxter said:
should this

PHP:
$preview=$row["preview"]; 
$dcounter=$dcounter["dcounter"]; 
$pcounter=$pcounter["pcounter"];

be

PHP:
$preview=$row["preview"]; 
$dcounter=$row["dcounter"]; 
$pcounter=$row["pcounter"];

Good eyes

give him some rep
 
0
•••
doesnt his script only print out 1 result?

sorry, i am novice and im very confused
 
0
•••
No:

while ($row=mysql_fetch_array($result)) {
That somehow works for looping, although PHP has another function made for looping through results: mysql_fetch_assoc.
 
0
•••
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

More data. Your data. See what is new
Major update
We have made a number of features available to provide sellers more data for their domains and inquiries, and greater access to the data...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back