Jump to content

Archived

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

wwfc_barmy_army

Print code problem PHP

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]

Share this post


Link to post
Share on other sites
Parse error: parse error, unexpected T_STRING in C:\public_html\RPG\test.php on line 11


Line 11 being:
print "Vistor Rating: " . $new_rating2 . " ";

Thanks.

Peter.

Share this post


Link to post
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?

Share this post


Link to post
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}\" />";
}
?>

Share this post


Link to post
Share on other sites
ahh, didn't save it properly.

But it crashed my IE, just kept on coming up with the image for number 4 and some writing next to it saying something like visitor number 4  ???

Peter.

Share this post


Link to post
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?

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
*sighs*, it worked fine in the test script then when i put it in the list.php code, it just shows the broken image /images/.png.

Is another bit of the code messing it up?

Thanks.

Peter,

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.