I am trying to fetch rows from the following query but it is not working and I am not getting an error message so I am realy in the dark. The query is returning results when I run it in the mysql terminl. Anyone know what the *&%$ is going on?
$sql = "select jobs.job_id from orders,jobs where job_name = '$job' "
$query = mysql_query($sql,$conn) or die(mysql_error());
$r = mysql_fetch_row($query) or die(mysql_error());
this die on the last line but with no message
please help
mysql fetch row is empty
Moderator: General Moderators
Re: mysql fetch row is empty
I am not for sure if it is a type-o or not, but after you did not put the semi-colon.
Code: Select all
$sql = "select jobs.job_id from orders,jobs where job_name = '$job' "- trollll
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 10, 2003 11:56 pm
- Location: Round Rock, TX
- Contact:
Oh! Just realized... For a left join you need to change the query to something like:
Or however you have your tables set up to match records. This will give you all job ids for jobs named '$job' with a record in orders as well.
Code: Select all
select jobs.job_id from orders,jobs where jobs.job_name = '$job' and jobs.job_id = orders.job_id$sql = "select jobs.job_id from orders,jobs where orders.job_id = jobs.job_id and job_name = '$job' " ;
$query = mysql_query($sql,$conn) or die(mysql_error());
$r = mysql_fetch_row($query) or die(mysql_error());
I am still having problems with this and here are some of the things I have noticed
$job is a variable that gets initialized from a html form i.e. ($job = HTTP_POST_VARS['jname'];)
I can print its value however when I include it (the varialbe) in $sql the query does not return results. If I hard code that same value I do get results. None of this is making any sense to me because this does not seem any different from several other queries I have done elsewhere on my site
$query = mysql_query($sql,$conn) or die(mysql_error());
$r = mysql_fetch_row($query) or die(mysql_error());
I am still having problems with this and here are some of the things I have noticed
$job is a variable that gets initialized from a html form i.e. ($job = HTTP_POST_VARS['jname'];)
I can print its value however when I include it (the varialbe) in $sql the query does not return results. If I hard code that same value I do get results. None of this is making any sense to me because this does not seem any different from several other queries I have done elsewhere on my site