Jump to content

quick sql question


willwill100

Recommended Posts

thanx for the debugging help guyys but ive worked out that the problem was much earlier in the program!

i keep getting the error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Will\My Documents\xampp\htdocs\sailing\rescalc.php on line 34

with this code below:

[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];

$result = mysql_fetch_array("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");
[/code]

i would ideally like to stick the first name and last name into separate variables, how can i do this??
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17855
Share on other sites

[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];

$result = mysql_fetch_array("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");[/code]

Can you run the query straight inside the fetch array??? try this

[code]$comp = $_REQUEST['comp'];
$snum = $_REQUEST['sailnum'];
$time = $_REQUEST['time'];
$query=mysql_query("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'");
$result = mysql_fetch_array($query);[/code]


That work better?
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17860
Share on other sites

well i *think* you could run...

$result = mysql_fetch_array(mysql_query("SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'"));

The reason it wasn't working the way you did it is because you had not rean a query you was masicaly just doin mysql_fetch_array on the text/string "SELECT `First Name` , `Last Name` FROM members WHERE `Sail Number` = '$snum'" instead of on the query results.
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-17875
Share on other sites

im having a similar problem again:

this is the code concerned:
[code]
$q= "SELECT * FROM `temp` ORDER BY `score` ASC";
$result = mysql_query ($q) or die('Problem with query: ' . $q . '<br />' . mysql_error());
$count = 1;
while ($row = mysql_fetch_assoc($result)){
$nom=$row['Name'];     

$query = "UPDATE `temp` SET `Position` = '$count' WHERE `name`='$nom'";
$result = mysql_query($query);

$count = $count + 1;
}
[/code]

i get the error message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\Will\My Documents\xampp\htdocs\sailing\handicapcalc.php on line 30

i would have thought that because i was calling the "fetch_array" from a query this time it would have worked but obviously not. Any help!?!?!
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18095
Share on other sites

Actually, in this case:
[code]<?php $query = "UPDATE `temp` SET `Position` = '$count' WHERE `name`='$nom'"; ?>[/code]
the variable is really inside the double quotes and do get translated.
You can prove it for yourself bu putting an [code]<?php echo $query; ?>[/code] on the next line.

Ken
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18264
Share on other sites

[!--quoteo(post=355702:date=Mar 16 2006, 10:17 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 16 2006, 10:17 PM) [snapback]355702[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Is the line quoted in the error message (line 30) the line you showed in your code snippet?

Ken
[/quote]

As the error message concerns "mysql_fetch_array" and the snippet uses "mysql_fetch_assoc" then I think ken's question is very relevant.
Link to comment
https://forums.phpfreaks.com/topic/4945-quick-sql-question/#findComment-18302
Share on other sites

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.