Jump to content

is there a code problem here?


davieboy

Recommended Posts

no still not working

 

http://www.fsimages.net/tests/tophits.php

 

i have hits in the DB with 141 and its only showing ones with 9

 

all code

 

// Make a MySQL Connection
include("config.php"); 
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());

$query = "SELECT * FROM `photos` WHERE `STATUS` = 'accepted' ORDER BY `hits` DESC LIMIT 5"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['hits'] ." ". $row['id'] ."";
echo "<br />";
}

 

 

// Make a MySQL Connection
include("config.php"); 
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die (mysql_error());

$query = "SELECT * FROM photos WHERE STATUS = 'accepted' ORDER BY `hits` LIMIT 5"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['hits'] ." ". $row['id'] ."";
echo "<br />";
}

 

Would show the five highest hits. If you want it from lowest to highest then you include DESC (descending) (smallest to highest) which is why its showing the 9's instead of the 140's

 

Unless of course you want it in that order in which case increase the limit?

Try this

<?php
// Make a MySQL Connection
include("config.php"); 
$conn = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name, $conn) or die (mysql_error());

$query = "SELECT * FROM photos WHERE STATUS = 'accepted' ORDER BY `hits` LIMIT 5"; 

$result = mysql_query($query, $conn) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['hits'] ." ". $row['id'] ."";
echo "<br />";
}
?>

You Can also try this http://zigmoyd.sourceforge.net/man/db.php#browse

its still not working

 

http://fsimages.net/tests/tophits.php

 

its grouping everything with the first number of the hits

 

ie

 

5 and 55 are in the same line etc...(see above link)

 

And I bet that's because you have the hits field defined in the database as a VARCHAR instead of an integer!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.