Jump to content

why doesnt this work? im a beginner


flemingmike

Recommended Posts

$compare=mysql_query("SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}'");
$compare=mysql_fetch_array($compare);

$totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'");
$totalchall=mysql_fetch_array($totalchall);
$totalchall="$totalchall[0]";

Link to comment
https://forums.phpfreaks.com/topic/149766-why-doesnt-this-work-im-a-beginner/
Share on other sites

$totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'"); // $compare is still an array at this point

 

so,

 

$compare=mysql_query("SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}'");
$compare=mysql_fetch_array($compare);
$compare=$compare[0]; // now $compare is the teamid field

$totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'");
$totalchall=mysql_fetch_array($totalchall);
$totalchall=$totalchall[0];

so here is my complete code that i have now....

 

$out[body].="
</table><br>
<script type='text/javascript'>
  <!--
    function Challenge( id, login ) {
      window.open('./scheduler.php?chall_id='+id + 'login[id2]='+login, '_details', 'width=600,height=500,toolbar=0,statusbar=0,scrollbars=0,menubar=0');
    }
  //-->
  </script>
<table width='95%' border='0' cellspacing='1' cellpadding='2' bgcolor='#000000'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center'  background='$config[bg]' align='left' colspan='5'><b>  Challenges</b></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='5%' valign='center'  background='$config[bg2]' align='center'><b>ID</b></td>
<td width='5%' valign='center'  background='$config[bg2]' align='center'><b></b></td>
<td width='30%' valign='center' background='$config[bg2]' align='center'><b>Challenger</b></td>
<td width='30%' valign='center'  background='$config[bg2]' align='center'><b>Challenged</b></td>
<td width='30%' valign='center'  background='$config[bg2]' align='center'><b>Date</b></td>
</tr>";

$compare=mysql_query("SELECT teamid FROM membersteams WHERE memberid='{$_COOKIE['user']}'");
$compare=mysql_fetch_array($compare);
$compare=$compare[0]; // now $compare is the teamid field

$totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid='$compare' OR challgdid='$compare'");
$totalchall=mysql_fetch_array($totalchall);
$totalchall=$totalchall[0];

if($totalchall == 0){
$out[body].="<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='center' colspan='5' background='$config[cellbg]'>No outstandings challenges.</td></tr>";
}else{
$challenges=mysql_query("SELECT challid,ladderid,challgrid,challgdid,challgrname,challgdname,DATE_FORMAT(created,'%M %d at %l:%i %p') FROM challenges WHERE challgrid='$compare' OR challgdid='$compare' ORDER BY created DESC");
while(list($challid,$ladderid,$challgrid,$challgdid,$challgrname,$challgdname,$created)=mysql_fetch_row($challenges)){



$check=mysql_query("SELECT * FROM chall_chat WHERE chall_id='$challid'");
$check=mysql_fetch_array($check);

if ($check[ed_status]==Accepted OR $check[er_status]==Accepted){
$msg = "<span style=\'color:red\'><center><strong>Both Teams have Accepted the Match Date!</strong></center></span><br /> <span style=\'color:black;font-weight:bold;\'>Match Details:</span><br />        <strong>Date:</strong> $check[month] $check[day], $check[year]<br />        <strong>Time:</strong> $check[hour]:$check[min] $check[ampm] $check[zone] <br />        <strong>Server:</strong> $check[server]<br />        <strong>Game Name:</strong> $check[game]";
$hover = "<a href='javascript: void Challenge($challid,$team[id])' onmouseover=\"return overlib('$msg', HEIGHT, 60, WIDTH, 260, CAPTION, '<span style=\'color:blue;\'>Current Challenge Status</span>');\" onmouseout=\"return nd();\">";
$calendarimg = "$hover<img src='./images/calendar2.gif' border='0'></a>";
}elseif ($check[ed_status]==Declined OR $check[er_status]==Declined){
$msg = "<center>The Challenge has been Declined.</center>";
$hover = "<a href='javascript: void Challenge($challid,$team[id])' onmouseover=\"return overlib('$msg', CAPTION, '<span style=\'color:blue;\'>Current Challenge Status</span>');\" onmouseout=\"return nd();\">";
$calendarimg = "$hover<img src='./images/calendar3.gif' border='0'></a>";
}elseif ($check[ed_status]==Pending OR $check[er_status]==Pending){
$msg = "<center>This Challenge is Pending Approval.</center>";
$hover = "<a href='javascript: void Challenge($challid,$team[id])' onmouseover=\"return overlib('$msg', CAPTION, '<span style=\'color:blue;\'>Current Challenge Status</span>');\" onmouseout=\"return nd();\">";
$calendarimg = "$hover<img src='./images/calendar.gif' border='0'></a>";
}else{
$msg = "<center>No Suggestions have been made.</center>";
$hover = "<a href='javascript: void Challenge($challid,$team[id])' onmouseover=\"return overlib('$msg', CAPTION, '<span style=\'color:blue;\'>Current Challenge Status</span>');\" onmouseout=\"return nd();\">";
$calendarimg = "$hover<img src='./images/calendar1.gif' border='0'></a>"; }

if($config[altcolorx]==$config[altcolora]){
$config[altcolorx]="$config[altcolorb]";
}else{
$config[altcolorx]="$config[altcolora]";
}
if($config[cellbgx]==$config[cellbg]){$config[cellbgx]="$config[cellbg2]";}else{$config[cellbgx]="$config[cellbg]";}

Hi

 

You have a query that will just bring back a single team id. For your original query to work you would need to loop round the results of the first query and call the 2nd query for each result.

 

I think what you want could be done like this:-

 

<?php
$totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid IN (SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}') OR challgdid IN (SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}')");
$totalchall=mysql_fetch_array($totalchall);
$totalchall=$totalchall[0];
?>

 

All the best

 

Keith

thanks keith, but:

 

Warning: include(./theme/default/html.php) [function.include]: failed to open stream: No such file or directory in /home/mash905/public_html/betting/index.php on line 467

 

Warning: include(./theme/default/html.php) [function.include]: failed to open stream: No such file or directory in /home/mash905/public_html/betting/index.php on line 467

 

Warning: include() [function.include]: Failed opening './theme/default/html.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/mash905/public_html/betting/index.php on line 467

 

 

line 467 consists of:

 

LINE 466 - $totalchall=mysql_query("SELECT COUNT(*) FROM challenges WHERE challgrid IN (SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}') OR challgdid IN (SELECT teamid FROM membersteam WHERE memberid='{$_COOKIE['user']}')");

LINE 467 - $totalchall=mysql_fetch_array($totalchall);

LINE 468 - $totalchall=$totalchall[0];

line 467 consists of:

 

Thats not what the error suggests. You have an include that can't be found, I don't see any calls to include int he code you have posted.

 

You do however have allot of errors in the code you posted. For instance, unless Accepted is a constant this line....

 

if ($check[ed_status]==Accepted OR $check[er_status]==Accepted){

 

should be....

 

if ($check['ed_status']=='Accepted' || $check['er_status']=='Accepted'){

 

Notice also that associative arrays are indexed by strings. That means they need to be surrounded by quotes.

this is getting to be a bit too complex for me.  im getting errors on line 1047 now form the page i put the code into and the code on line 1047 is ?>

 

if there is a simple answer, ill give it a shot, if not please let me know so i can scrap the idea.

 

thanks in advance.

Hi

 

The problem probably is simple, but it takes a bit to go through and solve lots of small simple errors.

 

I would guess that as it is finding an error on a line that only has "?>" that the problem is something like a missing semi colon on a previous line.

 

As thorpe mentions there are quite a few minor errors in that code fragment above.

 

All the best

 

Keith

Hi

 

If you use a half decent editor then it can probably highlight syntax, and match up brackets. I use Notepad++ which is simple to use.

 

But at the end of the day you pretty much do have to go through the code.

 

If you want message me the full code and I will have a quick look.

 

All the best

 

Keith

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.