ninedoors Posted April 11, 2008 Share Posted April 11, 2008 I am stumped. Maybe I hsve been looking at this too long, who knows. Anyways I can't get this query to work. I keep getting this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Ergo\admin\training\training_delete.php on line 209 Which means there is something wrong with my query statement, here is the code I am using: <?php $query = "SELECT training.flienumber, training.date, training.title, trainingupload.name, trainingupload.size ". "FROM training t LEFT JOIN trainingupload ta ON t.filenumber = ta.filenumber"; $result = mysql_query($query); $row = mysql_fetch_array($result); ?> The two tables I am querying are training and trainingupload. And I want pull out all the training records and only the trainingupload records that have matching filenumbers to the training table. Not sure what I have wrong. Any help would be great. Quote Link to comment Share on other sites More sharing options...
friedemann_bach Posted April 11, 2008 Share Posted April 11, 2008 "SELECT training.flienumber" should read "SELECT training.filenumber", I think. Quote Link to comment Share on other sites More sharing options...
ninedoors Posted April 11, 2008 Author Share Posted April 11, 2008 You are correct, I changed that and still no luck. Any other thoughts. Nick Quote Link to comment Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 can u try this one ... <?php $query = "SELECT training.flienumber, training.date, training.title, trainingupload.name, trainingupload.size ". "FROM training LEFT JOIN trainingupload ON training.filenumber = trainingupload.filenumber"; $result = mysql_query($query); $row = mysql_fetch_array($result); ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted April 11, 2008 Share Posted April 11, 2008 Your query is failing, run it through MySQL command line, or phpMyAdmin and you should see it doesn't return any results and should point to your incorrect syntax. Also, use "echo mysql_error()" in your PHP to see why the query failed. Quote Link to comment Share on other sites More sharing options...
friedemann_bach Posted April 11, 2008 Share Posted April 11, 2008 Try a more simple query first (with less specified values): SELECT t.* FROM training t LEFT JOIN trainingupload tu ON t.filenumber = tu.filenumber If this does not work, reduce your query until it works, then extend it step by step, and as soon as an error occurs, you will know which element is wrong. Alternatively, arrange the same query without JOIN: SELECT t.* FROM training t, trainingupload tu WHERE t.filenumber=tu.filenumber Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted April 11, 2008 Share Posted April 11, 2008 Indeed - do some error checking! <?php $query = "SELECT training.filenumber, training.date, training.title, trainingupload.name, trainingupload.size ". "FROM training t LEFT JOIN trainingupload ta ON t.filenumber = ta.filenumber"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0){ $row = mysql_fetch_array($result); }else{ echo 'No results!'; } ?> Quote Link to comment 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.