Jump to content

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/100637-solved-query-help/
Share on other sites

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);
?>

Link to comment
https://forums.phpfreaks.com/topic/100637-solved-query-help/#findComment-514704
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/100637-solved-query-help/#findComment-514898
Share on other sites

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!';
}
?>

Link to comment
https://forums.phpfreaks.com/topic/100637-solved-query-help/#findComment-514955
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.