Login     Sign up
user error
Thakim (@thakim83)
Join date: Oct 8th 2010
Community posts: 87
View Profile
Send Message

Could someone tell me what I did wrong because if you search for a member before you login, you get the following error. Could someone please help?

SQL query error!
Error infomation:[SQL]
SELECT u.* FROM jcow_friends as f1 inner join jcow_friends as f2 on f1.fid = f2.fid left join jcow_accounts as u on f1.fid=u.id where f1.uid=22 and f2.uid= ORDER BY f1.created DESC LIMIT 30

[Error]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY f1.created DESC LIMIT 30' at line 1

You can get help by sending this infomation to us: [url]http://jcow.net[/url]

You can try what I mean by checking the following:
[url]http://www.chaved.com/u/mutuk04[/url]

173 months ago
Jcow Master (@falcone)
Join date: Sep 2nd 2010
Community posts: 917
View Profile
Send Message

did you check this

[url]http://community.jcow.net/forums/viewthread/783?page=2[/url]

there was an error in the original code

173 months ago
Thakim (@thakim83)
Join date: Oct 8th 2010
Community posts: 87
View Profile
Send Message

I got the error after adding the 2 codes on that thread. What could I do?

173 months ago
Jcow Master (@falcone)
Join date: Sep 2nd 2010
Community posts: 917
View Profile
Send Message

this is in u.module.php, function show_sidebar

[code]
// Mutual friends
if ( ($client['id']) && ($client['id'] != ($owner['id']) )) {

    $res = sql_query("SELECT u.* FROM `".tb()."friends` as f1 inner join `".tb()."friends` as f2 on f1.fid = f2.fid left join `".tb()."accounts` as u  on f1.fid=u.id where f1.uid={$owner['id']} and f2.uid={$client['id']} ".dbhold('f1')." ORDER BY f1.created DESC LIMIT 30");
    $mfs = sql_counts($res);
    $output = '';
    while ($row = sql_fetch_array($res)) {
        $output .= avatar($row);
    }
    if ($mfs > 0) {
    $mfstext = ($mfs == 1)?t(' friend in common'):t(' friends in common');  
    ass(array('title'=>t('Mutual Friends'), 'content' => '<div class="toolbar"><span style="float:left">'.$mfs.$mfstext.'</span><span style="float:right">'.url('u/'.$owner['username'] .'/mutualfriends',t('See all')).'</span></div><div style="clear:both;"></div>'.$output));
    }

}
[/code]

and this is the new function

[code]
function mutualfriends($url = 0) {
global $client, $apps, $uhome,$ubase, $current_sub_menu, $offset, $num_per_page, $page;
need_login();
$profile = $this->settabmenu($url, 1,'u');
$current_sub_menu['href'] = 'u/'.$url.'/friends';

    // Mutual friends
    $output = '<ul class="small_avatars">';
    $res = sql_query("SELECT u.* FROM `".tb()."friends` as f1 inner join `".tb()."friends` as f2 on f1.fid = f2.fid left join `".tb()."accounts` as u on f1.fid=u.id where f1.uid={$profile['id']} and f2.uid={$client['id']}  ORDER BY f1.created DESC LIMIT $offset, $num_per_page");
    while ($row = sql_fetch_array($res)) {
        $output .= '<li>';
        $output .= '<span>'.url('u/'.$row['username'], $row['username']).'</span> '.avatar($row);
        $output .= '</li>';
    }
    $output .= '</ul>';

    // pager
    $res = sql_query("select count(*) as total from `".tb()."friends` as f1 inner join `".tb()."friends` as f2 on f1.fid = f2.fid where f1.uid={$profile['id']} and f2.uid={$client['id']} ".dbhold() );
    $row = sql_fetch_array($res);
    $total = $row['total'];
    $pb       = new PageBar($total, $num_per_page, $page);
    $pb->paras = $ubase.'u/'.$profile['username'].'/friends';
    $pagebar  = $pb->whole_num_bar();
    $output .= $pagebar;

    section(
        array('title'=>t('Mutual Friends'),
        'content'=>$output)
        );
}   

[/code]

173 months ago
Thakim (@thakim83)
Join date: Oct 8th 2010
Community posts: 87
View Profile
Send Message

I have replaced the first code with the second but the error is still there

173 months ago
Jcow Master (@falcone)
Join date: Sep 2nd 2010
Community posts: 917
View Profile
Send Message

are you sure that you copied the code in the right way and the file on the server is updated?

your problem is that $client['id'] is empty (means not logged in), but in that case the sql query shouldn't be executed, that is why the if ($client['id']) && ...... is for.

173 months ago
Thakim (@thakim83)
Join date: Oct 8th 2010
Community posts: 87
View Profile
Send Message

I have made sure the file is updated in the server but the error is still there

173 months ago
Thakim (@thakim83)
Join date: Oct 8th 2010
Community posts: 87
View Profile
Send Message

Could you please check my u. modul that I have attached?

173 months ago