[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 12-19-2006, 06:37 AM   #1 (permalink)
New Member
 
Join Date: Dec 2006
Posts: 10
0.00 NP$ (Donate)

Catie is an unknown quantity at this point


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 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
Catie is offline  
Old 12-19-2006, 06:55 AM   #2 (permalink)
NamePros Regular
 
baxter's Avatar
 
Join Date: Apr 2006
Posts: 289
1,990.00 NP$ (Donate)

baxter is a jewel in the roughbaxter is a jewel in the roughbaxter is a jewel in the rough

Ethan Allen Fund Save The Children
should this

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

PHP Code:
$preview=$row["preview"];
$dcounter=$row["dcounter"];
$pcounter=$row["pcounter"];
__________________
Chimps.ca - Swans.ca - Snails.ca
baxter is offline  
Old 12-19-2006, 08:16 AM   #3 (permalink)
NamePros Regular
 
Noobie's Avatar
 
Join Date: Feb 2006
Location: Montreal, Quebec, Canada
Posts: 324
66.75 NP$ (Donate)

Noobie is on a distinguished road


Quote:
Originally Posted by baxter
should this

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

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

give him some rep
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline  
Old 12-27-2006, 06:29 PM   #4 (permalink)
NamePros Regular
 
Alex.'s Avatar
 
Join Date: Nov 2006
Location: Uk
Posts: 601
133.80 NP$ (Donate)

Alex. is on a distinguished road

Ethan Allen Fund Third World Education
doesnt his script only print out 1 result?

sorry, i am novice and im very confused
__________________
_\|/_ _\|/_ _\|/_ _\|/_ _\|/_ :confused:
Alex. is offline  
Old 12-27-2006, 06:43 PM   #5 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future

Autism Autism Autism Autism Autism Autism Autism
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.
Dan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 03:14 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85