Jump to content

Recommended Posts


$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

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.

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\";



(...)

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\" (?)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.