Jump to content


Photo

JOIN ON in combinattion with fetch_object


  • Please log in to reply
3 replies to this topic

#1 cK

cK
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 26 May 2003 - 10:16 PM


	$query = "SELECT test_jobs.id, test_jobs.title, test_jobcontacts.id FROM test_jobs LEFT JOIN test_jobcontacts ON test_jobs.contact_id = test_jobcontacts.id WHERE (test_jobs.category_id=\'$category[id]\' OR test_jobs.category_id=\'9\') AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) <= test_jobs.days_valid) AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) >= 0) ORDER BY test_jobs.timestamp DESC LIMIT $pager->offset,$pager->limit";


How does this (JOIN ON) work in combination with \"while($row = mysql_fetch_object($result))\"?

I used to take $row->id and so on... But do I know need to do $row->jobcontacts.id (what doesn\'t work) or....

#2 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 27 May 2003 - 07:13 AM

Your sql statement is carried out, so it will return a number of rows like always...

Then php will grab them one at a time as usual.

And your coloumn names will be (after carrying out the query!):

while ($row = mysql_fetch_object($result)) {
$row->test_jobs.id;
$row->test_jobs.title;
$row->test_jobcontacts.id;
}
mysql_free_result($result);


P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 cK

cK
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 27 May 2003 - 09:29 PM

Doesn\'t seem to work with me :x

I get \"titleresults\" with $title = $row->test_jobs.title . \"results\";




function show_detail_page($id)

{

	$query = \"SELECT test_jobs.id,test_jobs.title,test_jobs.description,test_jobcontacts.name FROM test_jobs LEFT JOIN test_jobcontacts ON test_jobs.contact_id = test_jobcontacts.id WHERE test_jobs.id=\'$id\' AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) <= test_jobs.days_valid) AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) >= 0)\";

	$result = mysql_query($query) or error (\"Unable to connect to SQL server. Try again later.\");

	$row = mysql_fetch_object($result);



	if ($row)

	{

  $title = $row->test_jobs.title . \"results\";



(...)



#4 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 28 May 2003 - 08:34 AM

Hmm.... I\'m not sure if the . is bad for OO code (?) anyone ?

Try the following:




function show_detail_page($id)

{

$query = "SELECT test_jobs.id AS id ,test_jobs.title AS title ,test_jobs.description AS description,test_jobcontacts.name AS name FROM test_jobs LEFT JOIN test_jobcontacts ON test_jobs.contact_id = test_jobcontacts.id WHERE test_jobs.id=\'$id\' AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) <= test_jobs.days_valid) AND ((TO_DAYS(NOW()) - TO_DAYS(test_jobs.timestamp)) >= 0)";

$result = mysql_query($query) or error ("Unable to connect to SQL server. Try again later.");

$row = mysql_fetch_object($result);



if ($row)

{

$title = $row->title . "results";



(...)


P.

I.e. renaming your result names... alternatively you MAY use $row->\"table.fieldname\" (?)
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users