This is wierd scripted is 100% rigth buth output not

I got a code that figurse out if the user have watched that movie already or not now the wierd thing about it it let see if he watched buth not if he didnt watched:

Code:
[php]$uid = $_COOKIE[“cookname”];
$tid = $torrent[“id”];
$con = mysql_connect(“localhost”,“jornherm_acbteam”,"*******");
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“jornherm_acbteam”, $con);
$query5 = “SELECT uid, tid FROM torrents_seen WHERE uid = ‘$uid’ AND tid = ‘$tid’”;
$gezien = mysql_query($query5);

while($row = mysql_fetch_assoc($gezien))
{
$uid2 = $row[‘uid’];
$tid2 = $row[‘tid’];
if (empty($tid2))
{
echo “<img src=”./images/notseen.png" border=“0”>";
} else {
echo “<img src=”./images/seen.png" border=“0”>";
}
}[/php]

DB Structure:

tid,uid

tid=the id of the movie
uid=the username

Hello,

in your query you are only fetching the rows that have a value of $uid and $tid:
[php]$query5 = “SELECT uid, tid FROM torrents_seen WHERE uid = ‘$uid’ AND tid = ‘$tid’”;[/php]

if the values in the database do not match, they will NOT be selected, so this will never be true:
[php]if (empty($tid2)) [/php] meaning this statement will never run:
[php]echo “<img src=”./images/notseen.png" border=“0”>";[/php]

I hope that helps
:wink:

How to solve it then ? thath they doe show ?

thsi is te output

Wich statement i should use to do this?

you need to call all the rows then sort them out into seen/not seen, i’d do something like this:
[php]// select ALL rows
$query = “SELECT * FROM torrents_seen”;
$result = mysql_query($query);

// run a loop to display the rows
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
// if tid has NO value
if ($row[‘tid’] == ‘’)
{
echo “<img src=”./images/notseen.png" border=“0”>";
}
else // show the rest
{
echo “<img src=”./images/seen.png" border=“0”>";
}
}
[/php]

Hope this helps,

Red :wink:

Oke i changed it a litle bit now i already see them buth now i get somthing totaly wierd heres the code:

[php]<?
$uid = $_COOKIE[“cookname”];
$tid = $torrent[“id”];
$con = mysql_connect(“localhost”,“jornherm_acbteam”,"*******");
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“jornherm_acbteam”, $con);
// select ALL rows
$query = “SELECT * FROM torrents_seen WHERE uid = ‘$uid’”;
$result = mysql_query($query);

// run a loop to display the rows
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{

if ($row[‘tid’] == $tid)

{

echo “<img src=”./images/seen.png" border=“0”>";

}

else

{

echo “<img src=”./images/notseen.png" border=“0”>";

}
}
?>[/php]

It does work an it does show me the one where he didnt find one buth he shows me 3 rows :s

check te screen:

Got i solved beceasu ther wasent always a resutl a loop could not started so i did this:

[php]<?
$uid = $_COOKIE[“cookname”];
$tid = $torrent[“id”];
$con = mysql_connect(“localhost”,“jornherm_acbteam”,"*******");
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“jornherm_acbteam”, $con);
// select ALL rows
$query = “SELECT * FROM torrents_seen WHERE uid = ‘$uid’ AND tid = ‘$tid’”;
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
if ($num_rows == 1)
{
echo “<img src=”./images/seen.png" border=“0”>";

}

else

{

echo “<img src=”./images/notseen.png" border=“0”>";

}

?>[/php]

buth still tnx

your welcome, glad you fixed it :smiley:

Sponsor our Newsletter | Privacy Policy | Terms of Service