mysql fetch row is empty

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
famman
Forum Newbie
Posts: 3
Joined: Wed Aug 20, 2003 9:58 am

mysql fetch row is empty

Post 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
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post 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...
User avatar
brewmiser
Forum Commoner
Posts: 74
Joined: Mon Aug 18, 2003 12:50 pm
Location: Dallas, TEXAS

Re: mysql fetch row is empty

Post 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.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post 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 ?
User avatar
trollll
Forum Contributor
Posts: 181
Joined: Tue Jun 10, 2003 11:56 pm
Location: Round Rock, TX
Contact:

Post 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.
famman
Forum Newbie
Posts: 3
Joined: Wed Aug 20, 2003 9:58 am

Post by famman »

thanks
I think you are right about the query, but for some reason it is still not working.
famman
Forum Newbie
Posts: 3
Joined: Wed Aug 20, 2003 9:58 am

Post 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
Post Reply