sylesia Posted December 10, 2006 Share Posted December 10, 2006 Ok, first off, thanks for all the help you guys have been giving me, I truely appreciate it. Now I have a question I really cannot see what went wrong with it...[code] if ($var <10) { $request = "SELECT $try FROM bluecard WHERE UserName = '$userName' AND CardNumber = $cardNumber"; $eval = mysql_query($request, $conn); while($row = mysql_fetch_assoc($eval)){ $$try = $row[$try]."\n"; } } else{ //echo $var . $try . " "; $request = "SELECT $try FROM dimensions WHERE UserName = '$userName' AND CardNumber = $cardNumber"; $eval = mysql_query($request, $conn); // echo $request; while($row = mysql_fetch_assoc($eval)){ $$try = $row[$try]."\n"; echo $$try; } }[/code]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in http://localhost/srh/bluecardreview.html on line 141Thing is, it seems to just hate the dimensions table, and I cannot figure out why. The if works fine, and when I output the parts in the else, everything is what I expect and want, yet that error shows. No idea whats going on or why...Oh, and to note, the variable $try is simply a string where the value is the new variable. IE... $try = 'Loyalty', than $$try is actually $Loyalty. Saves me alot of redundant coding. Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/ Share on other sites More sharing options...
fert Posted December 10, 2006 Share Posted December 10, 2006 change[code]$eval = mysql_query($request, $conn); [/code]to[code]$eval = mysql_query($request, $conn) or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138244 Share on other sites More sharing options...
sylesia Posted December 10, 2006 Author Share Posted December 10, 2006 You gotta be kidding me...You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS FROM dimensions WHERE UserName = '1' AND CardNumber = 3' at line 1Is there anyway around that? I need the AS title if at all possible since its the accepted value Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138246 Share on other sites More sharing options...
fert Posted December 10, 2006 Share Posted December 10, 2006 change this [code]$request = "SELECT $try FROM dimensions WHERE UserName = '$userName' AND CardNumber = $cardNumber";[/code]to this[code]$request = "SELECT $try FROM dimensions WHERE UserName = '$userName' AND CardNumber = '$cardNumber'";[/code]and this[code]$request = "SELECT $try FROM bluecard WHERE UserName = '$userName' AND CardNumber = $cardNumber";[/code]to this[code]$request = "SELECT $try FROM bluecard WHERE UserName = '$userName' AND CardNumber = '$cardNumber'";[/code] Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138248 Share on other sites More sharing options...
sylesia Posted December 10, 2006 Author Share Posted December 10, 2006 ok, actually all I had to do was put ' ' around $try and it worked. But now another issue, seems it only will use the else statement twice.[code]<? $conn = mysql_connect("localhost", "zzz", "xxx"); mysql_select_db("evaluation", $conn); $var = 0; while ($var < 40) { switch($var){ case 0: $try = 'UserName'; break; case 1: $try = 'CardNumber'; break; case 2: $try = 'Date'; break; case 3: $try = 'UnitPosition'; break; case 4: $try = 'Spot'; break; case 5: $try = 'Unit'; break; case 6: $try = 'SummarySeen'; break; case 7: $try = 'Sustain'; break; case 8: $try = 'Improve'; break; case 9: $try = 'EvaluateeName'; break; case 10: $try = 'UserName'; break; case 11: $try = 'CardNumber'; break; case 12: $try = 'Loyalty'; break; case 13: $try = 'Duty'; break; case 14: $try = 'Respect'; break; case 15: $try = 'SelflessService'; break; case 16: $try = 'Honor'; break; case 17: $try = 'Integrity'; break; case 18: $try = 'PersonalCourage'; break; case 19: $try = 'ME'; break; case 20: $try = 'PH'; break; case 21: $try = 'EM'; break; case 22: $try = 'CO'; break; case 23: $try = 'IP'; break; case 24: $try = 'TE'; break; case 25: $try = 'TA'; break; case 26: $try = 'CM'; break; case 27: $try = 'DM'; break; case 28: $try = 'MO'; break; case 29: $try = 'PL'; break; case 30: $try = 'EX'; break; case 31: $try = 'AS'; break; case 32: $try = 'DE'; break; case 33: $try = 'BD'; break; case 34: $try = 'LN'; break; case 35: $try = 'Overall'; break; } if ($var < 10) { $request = "SELECT '$try' FROM bluecard WHERE UserName = '$userName' AND CardNumber = $cardNumber"; $eval = mysql_query($request, $conn) or die(mysql_error()); while($row = mysql_fetch_assoc($eval)){ $$try = $row[$try]."\n"; } } if ($var > 9) { echo $$try; $request = "SELECT '$try' FROM dimensions WHERE UserName = '$userName' AND CardNumber = $cardNumber"; $eval = mysql_query($request, $conn) or die(mysql_error()); while($row = mysql_fetch_assoc($eval)){ $$try = $row[$try]."\n"; } echo $$try; } $var = $var + 1; } print $loyalty;?>[/code]It prints out $$try properly the first two times, than it never does again, and it does keep going thru the loop. The problem arrises in the If If tree at the bottom, I just wanted to show all my code. I have tried If-Else tree and even the If-Else If, but none of them work Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138253 Share on other sites More sharing options...
sylesia Posted December 10, 2006 Author Share Posted December 10, 2006 And a note onto that. It does actually run thru the second if, but for some reason the $row is apparently always false after the second time, and I am not sure why. Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138261 Share on other sites More sharing options...
trq Posted December 10, 2006 Share Posted December 10, 2006 You should actually have backticks ` around your $try variable as it may contain the sql reserved word [i]date[/i]. You should also take notice of what fert said and place quotes around $cardNumber. Link to comment https://forums.phpfreaks.com/topic/30078-warning-mysql_fetch_assoc/#findComment-138265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.