Jump to content

Print code problem PHP


wwfc_barmy_army

Recommended Posts

Seems like it works.

Try this:

[code=php:0]
//$id = $_GET['id'];

while($qry_rating = mysql_query("SELECT rating FROM site"))
{       
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

print "Vistor Rating: " . $new_rating2 . " ";

//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png';   
//Display user's rating image2
print "<img src=\"images/{$image2}\" />";
}
[/code]
Link to comment
Share on other sites

Looks fine to me.

You're using:

[code=php:0]
while($qry_rating = mysql_query("SELECT rating FROM site"))
{     
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

print "Vistor Rating: " . $new_rating2 . " ";

//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png'; 
//Display user's rating image2
print "<img src=\"images/{$image2}\" />";
}
[/code]

Right?
Link to comment
Share on other sites

Yup using:

<?php include("includes/dbconnect.php");

while($qry_rating = mysql_query("SELECT rating FROM site"))
{     
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

print "Vistor Rating: " . $new_rating2 . " ";








//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png'; 
//Display user's rating image2
print "<img src=\"images/{$image2}\" />";
}
?>
Link to comment
Share on other sites

Ok, so ID = 10 displays has a 1.25 rating right?

[code=php:0]
$id = $_GET['id'];
$id = 10;

while($qry_rating = mysql_query("SELECT rating FROM site WHERE id = '$id'"))
{     
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

print "Visitor Rating: " . $new_rating2 . " ";

//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png'; 
//Display user's rating image2
print "<img src=\"images/{$image2}\" />";
}
[/code]

And the image path is correct, right?
Link to comment
Share on other sites

For my test script above, did you try that one?

$id = $_GET['id'];
$id = 10;

You're saying my test script above thousands of:

"Visitor Rating: 1.25 (Correct image for 1.25 also shown next to each one)"

but all ID are unique right?

Try taking the while loop out:

[code=php:0]
$id = $_GET['id'];
$id = 10;

$qry_rating = mysql_query("SELECT rating FROM site WHERE id = '$id'");   
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

print "Visitor Rating: " . $new_rating2 . " ";

//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png'; 
//Display user's rating image2
print "<img src=\"images/{$image2}\" />";
[/code]

And if the display is correct for ID 10, then you can try to implement that code portion in your full script (removing the "$id = 10;" of course)
Link to comment
Share on other sites

I think I see another problem, which I fixed.

You were using $_GET['id'], shouldn't it be $qry['id'] ???

Here's the revised version:

[code=php:0]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php include("includes/dbconnect.php"); ?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>View Sites</title>
</head>

<body>
<?php
print "<table border=1 class=list>";
echo("<thead><tr><td>Site Name</td><td>Editor Rating</td><td>Visitor Rating</td><td>Date Added</td><td>Publisher</td></tr></thead><tbody>");
$result = mysql_query('SELECT * FROM site ORDER BY name DESC');
while ($qry = mysql_fetch_array($result))
{
print "<tr>";
print "<td><a href=site.php?id=$qry[id]>$qry[name]</td>";

//Assuming each editorrating correpsonding an image name w/ that rating
$image = $qry['editorrating'] . '.png';

//Display user's rating image
echo "<td><img src=\"images/{$image}\" /></td>";


//Get User's ID rating and display rating image based on that rating
$id = $qry['id'];
$qry_rating = mysql_query("SELECT rating FROM site where id='$id'");           
list($rating) = mysql_fetch_row($qry_rating);
$new_rating2 = (string)$rating;

//gets the average rating from the database and put into an image variable
$rateA = explode(".", $new_rating2);
$rateA[1] = ((int)$rateA[1] <= 49) ? NULL : $rateA[1];
$rateA[1] = ((int)$rateA[1] >= 50 && (int)$rateA[1] <= 99) ? "5" : $rateA[1];

//store rating in image2 variable
$image2 = $rateA[0] . $rateA[1] . '.png';
   
//Display user's rating image2
echo "<td><img src=\"images/{$image2}\" /></td>";

//Display dateadded
print "<td>$qry[dateadded]</td>";
//Display publisher
print "<td>$qry[publisher]</td>";
print "</tr>";
}

print "</tbody></table>";
?>

<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.