PDA

View Full Version : first attempt at a join function is only returning one row result..



antonyf
05-08-2013, 11:55 AM
Hi
Im new to "join" function this is my first attempt.. My example below only outputs the first tab/row. I need all the data output.. the "rel" below seems correct to the one tab loaded..

// here is the join attempt:
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 = $q->fetch_assoc($q)) // same as mysql_fetch_assoc
{
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>';
}
}


here is the normal method i attempted without join.. The result i got here was: i got all the tabs but only the first tab had its "rel" settings.

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>';

}
}


if i can get either method to work would be great..

traq
05-08-2013, 03:23 PM
Can you show us your DB schema?