Jump to content

[SOLVED] code help


jck

Recommended Posts

is this code correct????

$q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]";
$r2 = mysql_query($q);
if (mysql_num_rows($r2) = 0)
{
echo '<b><center>You have not yet rated this joke </center></b><br>';
}
else
{
echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br>
?>

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/
Share on other sites

$q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'";
$r2 = mysql_query($q);
if (mysql_num_rows($r2) == 0)
{
echo '<b><center>You have not yet rated this joke </center></b><br>';
}
else
{
echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br>
?>

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-296236
Share on other sites

try this

$q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'";
$r2 = mysql_query($q);
if (!mysql_num_rows($r2))
{
echo '<b><center>You have not yet rated this joke </center></b><br />';
}
else
{
while($row = mysql_fetch_arrray($r2))
{
echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] .' </center></b><br />';
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-296238
Share on other sites

Now this will help u,

 

$q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'";
$r2 = mysql_query($q);
if (!mysql_num_rows($r2))
{
echo '<b><center>You have not yet rated this joke </center></b><br />';
}
else
{
$row = mysql_fetch_arrray($r2))

echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] .' </center></b><br />';

}
?>

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-296243
Share on other sites

$q="SELECT * FROM dd_rating WHERE ItemID = ".$ItemID ." AND username = '".$_SESSION[username]."'";
$r2 = mysql_query($q);
if (!mysql_num_rows($r2))
{
echo '<b><center>You have not yet rated this joke </center></b><br />';
}
else
{
$row = mysql_fetch_array($r2))

echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating'] .' </center></b><br />';

}
?>

 

Two typos:

One too many "r"s in "mysql_fetch_array"

Missing a ' before ] in the last echo line.

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-296896
Share on other sites

this is the original code:

 

$q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]";
$r2 = mysql_query($q);
if (mysql_num_rows($r2) = 0)
{
echo '<b><center>You have not yet rated this joke </center></b><br>';
}
else
{
echo '<b><center>You have given this joke a rating of ' . $rate = $row['Rating] . </center></b><br>
?>

 

First mistake: $q="SELECT * FROM dd_rating WHERE ItemID = $ItemID AND username = '$_SESSION[username]";

Should be: $q="SELECT * FROM dd_rating WHERE ItemID = '$ItemID' AND username = '$_SESSION[username]'";

 

Second: if (mysql_num_rows($r2) = 0)

Should be: if (mysql_num_rows($r2) == 0)

 

third: what is $row?

I think what you meant was $rate = mysql_result($r2, 0, 'Rating');

 

I fogot you can use mysql_fetch_row too. (but I never use it and not sure how to excactly)

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-297050
Share on other sites

<?
$query="SELECT * FROM dd_rating WHERE ItemID = '114' AND username = 'jck'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0)
{
echo '<b><center>You have not yet rated this joke </center></b><br>';
}
else
{
$rate = mysql_result($result, 0, 'Rating');
echo '<b><center>You have given this joke a rating of ' . $rate . </center></b><br>
?>

 

i tested with this code and i get blank page

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-297570
Share on other sites

<?php
$query="SELECT * FROM dd_rating WHERE ItemID = '114' AND username = 'jck'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0)
{
    echo '<b><center>You have not yet rated this joke </center></b><br>';
}
else
{
    $rate = mysql_result($result, 0, 'Rating');
    echo '<b><center>You have given this joke a rating of ' . $rate . '</center></b><br>';// changed line
} // closed loop
?>

 

I can only assume your server does not have display errors active.

Link to comment
https://forums.phpfreaks.com/topic/59616-solved-code-help/#findComment-297899
Share on other sites

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.