InABoxPr Posted June 13, 2011 Share Posted June 13, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239213-need-help-mysql-fetching-question/ Share on other sites More sharing options...
gristoi Posted June 13, 2011 Share Posted June 13, 2011 It is beaqcuse the origional query is using an alias for one of the field names: "SELECT Tasks.Task as Task so when you are selecting all instead you are not returning a field with a name of task Quote Link to comment https://forums.phpfreaks.com/topic/239213-need-help-mysql-fetching-question/#findComment-1228992 Share on other sites More sharing options...
InABoxPr Posted June 13, 2011 Author Share Posted June 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239213-need-help-mysql-fetching-question/#findComment-1228996 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.