Page 1 of 1
mysql fetch row is empty
Posted: Wed Aug 20, 2003 9:58 am
by famman
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
Posted: Wed Aug 20, 2003 10:02 am
by trollll
Try echo-ing $sql to make sure that the value of $job gets correctly put into the string. Also, you can try mysql_num_rows($query); just after $query gets set to see if it returns any records...
Re: mysql fetch row is empty
Posted: Wed Aug 20, 2003 11:40 am
by brewmiser
I am not for sure if it is a type-o or not, but after
Code: Select all
$sql = "select jobs.job_id from orders,jobs where job_name = '$job' "
you did not put the semi-colon.
Posted: Wed Aug 20, 2003 12:52 pm
by nigma
Well, if it wans't a typo I am pretty sure an error would have been visible inside the browser window UNLESS you have like turned error reporting off ?
Posted: Wed Aug 20, 2003 1:09 pm
by trollll
Oh! Just realized... For a left join you need to change the query to something like:
Code: Select all
select jobs.job_id from orders,jobs where jobs.job_name = '$job' and jobs.job_id = orders.job_id
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.
Posted: Wed Aug 20, 2003 2:50 pm
by famman
thanks
I think you are right about the query, but for some reason it is still not working.
Posted: Fri Aug 22, 2003 5:08 am
by famman
$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