Jump to content
php.lv forumi

Mysql select


Recommended Posts

Posted

parastais sintex

where forum_id != 2 && forum_id != 3 && forum_id != 4

 

Šitā kaut kā nevar? Vai tikai pa vienam rakstot var?

where forum_id != 2,3,4

Posted (edited)

Vedu sunī ārā un tieši iedomājos par iekavām :) Bet kāpēc nevar lietot != obligāti jālieto vārdi?

Edited by Wuu
Posted

	$disable = '';
if (!empty($uSet['disabled_forums'])) {
		$disable = 'where t1.forum_id not in ('.$uSet['disabled_forums'].') ';
}
$result = mysql_query('select t1.tid,t1.title,t1.posts,t1.last_poster_name,t1.starter_name,t2.post from '.$INFO['sql_tbl_prefix'].'topics t1 join '.$INFO['sql_tbl_prefix'].'posts t2 on (t1.tid = t2.topic_id) '.$disable.'group by t1.tid order by t1.last_post desc, t2.post_date desc limit 10;');
if (!empty($result)) {
	$l = 0;
	while ($r = mysql_fetch_array($result)) {
		$u[++$l]['ntopic_id'] = $r[0];
		$u[$l]['ntopic_title'] = $r[1];
		$u[$l]['ntopic_posts'] = $r[2];
		$u[$l]['ntopic_l_name'] = $r[3];
		$u[$l]['ntopic_s_name'] = $r[4];
		$u[$l]['ntopic_post'] = $r[5];
	}
}

 

Vai nav kāda gatava funkcija kas izpildītu

 

			$u[++$l]['ntopic_id'] = $r[0];
		$u[$l]['ntopic_title'] = $r[1];
		$u[$l]['ntopic_posts'] = $r[2];
		$u[$l]['ntopic_l_name'] = $r[3];
		$u[$l]['ntopic_s_name'] = $r[4];
		$u[$l]['ntopic_post'] = $r[5];

 

Nu es domāju savāktu visus myql datus vienā arajā, lai lietotu vēlāk?

Posted

Iespējams... ;)

Ja gribi, lai indeksi atbilst kolonnu nosaukumiem, tad izmanto:

mysql_fetch_assoc

vai

mysql_fetch_array($result,MYSQL_ASSOC)

 

ja gribi nolasīt visu rezultātu uzreiz bez while... tad gan nezinu. Jāpameklē. :)

Posted

Viglāk jau ir manšķiet pēc Alekseja teiktā, jo izmantot " != " nebūtu skaisti, padomā cik gari tu daūtu rakstīts! un cik tas kods izskatītos nesmuks.

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...