Jump to content

Need Help - MySQL Fetching question


InABoxPr

Recommended Posts

Heres my code:

$var = "";
$bip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']);
$sql = mysql_query("SELECT * FROM `bots` WHERE ip='$bip'") or die(mysql_error());
$fetch = mysql_fetch_assoc($sql);
$bid = $fetch['id'];
$sql = mysql_query("SELECT Tasks.Task as Task from Tasks WHERE Tasks.ID NOT IN (SELECT complete.TaskID FROM complete WHERE complete.UserID = '1')") or
    die(mysql_error());
while ($fetch = mysql_fetch_array($sql))
{
    $var = $var . $fetch['Task'] . ">>";
    $var2 = $fetch['id'];
    $sql = mysql_query("INSERT INTO `complete` (UserID, TaskID) VALUES('$bid','$var2')") or die(mysql_error());
    $var3 = $fetch['complete'];
    $var4 = $fetch['needed'];
    if($var3==$var4) {
        $sql = mysql_query("DELETE FROM `tasks` WHERE id='$var2'") or die(mysql_error()); //Or do DELETE FROM `tasks` WHERE needed=<$var3
    } else {
    $var3 = $var3 + 1;
    $sql = mysql_query("UPDATE `tasks` SET complete='$var3' WHERE id='$var2'") or die(mysql_error());
}
}

$var = substr($var, 0, -2);
echo ($var);

 

Im trying to make it select more then just "tasks" from the table Tasks, i tried making it say:

 

$sql = mysql_query("SELECT * FROM Tasks WHERE Tasks.ID NOT IN (SELECT complete.TaskID FROM complete WHERE complete.UserID = '1')") or
    die(mysql_error());

 

Insead of:

 

$sql = mysql_query("SELECT Tasks.Task as Task from Tasks WHERE Tasks.ID NOT IN (SELECT complete.TaskID FROM complete WHERE complete.UserID = '1')") or die(mysql_error());

 

But when i used that code i got this error:

 

 

Notice: Undefined index: Task in C:\wamp\www\FOLDER\getcom.php on line 20

 

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\FOLDER\getcom.php on line 18

 

 

Link to comment
Share on other sites

Alright, i know that. I'm bad in SQL. How can i fix the code to select all of them like im wanting to do. I tried changing it to * but i think i may of deleted the wrong part of the sql statement or put it in the wrong area. Thanks.

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.