cK Posted May 26, 2003 Share Posted May 26, 2003 $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.... Link to comment https://forums.phpfreaks.com/topic/514-join-on-in-combinattion-with-fetch_object/ Share on other sites More sharing options...
pallevillesen Posted May 27, 2003 Share Posted May 27, 2003 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. Link to comment https://forums.phpfreaks.com/topic/514-join-on-in-combinattion-with-fetch_object/#findComment-1723 Share on other sites More sharing options...
cK Posted May 27, 2003 Author Share Posted May 27, 2003 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\"; (...) Link to comment https://forums.phpfreaks.com/topic/514-join-on-in-combinattion-with-fetch_object/#findComment-1733 Share on other sites More sharing options...
pallevillesen Posted May 28, 2003 Share Posted May 28, 2003 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\" (?) Link to comment https://forums.phpfreaks.com/topic/514-join-on-in-combinattion-with-fetch_object/#findComment-1746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.