Jump to content

Recommended Posts

Hi.

I have this simple 2 queries that i am trying to get the output of two table queries syncronised..

 

 

if(isset($_GET['loadLists']))

{

    if($needAuth == 1 && !is_logged()) return 'you must be logged in to view this list.';

    else $sqlWhere = '';

    $current_user_id = (__isset('multiuser') == 1)?intval($_SESSION['userid']):0;    

    $q = $db->dq("SELECT * FROM todo_lists $sqlWhere ORDER BY ow ASC, id ASC");

    while($row = mysql_fetch_assoc($q))

    {

    $ncurconfig = $db->dq("SELECT * FROM todo_lists_setting WHERE list_id =? AND user_id=?", array($row['id'], $current_user_id));

    $sett = $mysql_fetch_assoc($ncurconfig);  

    echo '<li id="list_'.$row['id'].'" rel="'.$sett['notify'].'_'.$sett['showcompl'].'_'.$sett['sorting'].'_'.$sett['shownotes'].'_'.$sett['showdates'].'" class="tab"><a href="#list/'.$row['id'].'" rel="'.$row['id'].'" title="'.htmlarray($row['name']).'"><span>'.htmlarray($row['name']).'</span></a></li>';  

    

}

}

 

this should output 4 tabs with different names, and each with their own "rels" settings... Only the first rel is output the other tabs have only "____"..

I dont know how to join or union queries, but i dont think that they are relevant here?

 

thanks in advance..

Link to comment
https://forums.phpfreaks.com/topic/277759-2-queries-into-one-result/
Share on other sites

A JOIN is definitely relevant. YOu should never ever do queries in loops.

 

You want to do an INNER JOIN on your settings to the lists table.

 

Once you get that working (Try doing the query directly in mysql/phpmyadmin) we can help with any other issues.

Hi Jesica..

I see what you meaning. If i can here something like this:

 

$result = mysql_query("SELECT * FROM todo_lists INNER JOIN todo_lists_setting

ON todo_lists.id=todo_lists_setting.list_id WHERE todo_lists_setting.user_id = '$current_user_id'");

while($row=mysql_fetch_array($result))

{

echo '<li id="list_'.$row['id'].'" rel="'.$row['notify'].'_'.$row['showcompl'].'_'.$row['sorting'].'_'.$row['shownotes'].'_'.$row['showdates'].'" class="tab"><a href="#list/'.$row['id'].'" rel="'.$row['id'].'" title="'.htmlarray($row['name']).'"><span>'.htmlarray($row['name']).'</span></a></li>';

}

 

is this correct?

here is the full example:

it only outputs the first tab and its setting. The other tabs dont show..

 

 

if(isset($_GET['loadLists']))

{

if($needAuth == 1 && !is_logged()) return 'you must be logged in to view this list.';

$current_user_id = (__isset('multiuser') == 1)?intval($_SESSION['userid']):0;

$q = $db->dq("SELECT * FROM todo_lists INNER JOIN todo_lists_setting

ON todo_lists.id=todo_lists_setting.list_id WHERE todo_lists_setting.user_id = '$current_user_id'");

while($row = mysql_fetch_assoc($q))

{

echo '<li id="list_'.$row['id'].'" rel="'.$row['notify'].'_'.$row['showcompl'].'_'.$row['sorting'].'_'.$row['shownotes'].'_'.$row['showdates'].'" class="ytt-tabi"><a href="#list/'.$row['id'].'" rel="'.$row['id'].'" title="'.htmlarray($row['name']).'"><span>'.htmlarray($row['name']).'</span></a></li>';

}

}

My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself.

Your solution or hint does not work! and your method of teaching? is questionable.. Some of us learn by the solution and how it was achieved.. here you just threw me in another direction and waisted a day.. and left the scene..

 

Is there anybody else that can help!!!!!

Your solution or hint does not work! and your method of teaching? is questionable.. Some of us learn by the solution and how it was achieved.. here you just threw me in another direction and waisted a day.. and left the scene..

 

Is there anybody else that can help!!!!!

It's a signature dude.

 

I didn't leave because I wasn't willing to help. I left because I had work to do. You didn't "waste" (that's how it's spelled btw) anything because you learned how to do a JOIN which was what was needed.

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.