PDA

View Full Version : [solved] php/mysql issue


Dr.CustUmz
03-24-2016, 06:29 PM
as my initial question in my previous issue was solved i decided to open a new thread to avoid hijacking my own thread.

this is only part of the code, but im having issues getting this to work with vbulletin
$query = $db->query_first( "select * from redirect order by hits desc");
$result = MYSQL_QUERY($query);
$number = MYSQL_NUMROWS($result) or die (mysql_error());

$i = 0;

IF ($number == 0) {
PRINT "<CENTER><P><b>No Links tracked yet!</b></CENTER>";
}

ELSEIF ($number >= 1) {
WHILE ($i < $number){
$hits = mysql_result($result,$i,hits);
$url = mysql_result($result,$i,url);
if ($hits < 10){

Dave
03-24-2016, 07:07 PM
Can't test it, but this should work:
$query = $db->query("SELECT * FROM redirect ORDER BY hits DESC");

if ($db->num_rows($query) == 0) {
print "Nothing here";
} else {
while($row = $db->fetch_array($query)){
if($row['hits'] < 100){
$color = $color100;
}
print "<div align=\"left\">";
print "<table COLS=3 border=\"0\" width=\"100%\"><tr><td ALIGN=LEFT with=\"400\"><b><a href=\"" . $row['url'] . "\">" . $row['url'] . "</a></b></td>";
print "<td align=right WIDTH=\"60\"><b>" . $row['hits'] . "</b></td>";
print "<td align=left WIDTH=\"" . $row['hits'] . "\" BGCOLOR=\"" . $color . "\">&nbsp;</td></tr>";
print "</table>\n";
}
}

Some tips:
- Look at the functions of the vB_Database class in /includes/class_core.php, you will see what all the functions do and what parameters they require.
- query_first only returns the first row of the query, so it can not be used in this case since you want to loop through all of the results.
- Always escape PHP variables outside of the quotes, makes it easier to debug and to overview code.
- Write SQL syntax with uppercase characters.
- Only set new variables if you absolutely have to, makes code cleaner. :)

Dr.CustUmz
03-24-2016, 07:39 PM
PERFECT!! and thanks for the tips, still learning so it all helps =)