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
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
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
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
Share on other sites

Sigh.  "None of these are working" really doesn't help anyone at all because we can't tell what's supposed to happen with your testing

 

echo the value of $q immediately after defining it.  Post exactly what it says.

 

 

Link to comment
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
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
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
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
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.