<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
	<channel>
				<title><![CDATA[랜덤 출력 쿼리 문의 드립니다.]]></title>
		<link>https://www.cosmosfarm.com/threads/rss/document/12436</link>
		<description><![CDATA[<p>books 라는 테이블만들어서 명언을 넣었습니다.</p>

<p>게시물 하단에 랜덤 명언을 출력하고자 하는데 오류만 나네요</p>

<p> </p>

<p>&lt;?<br />
$sql = " select * from books ORDER BY RAND() LIMIT 1";<br />
$result = sql_query($sql);<br />
for ($i=0; $row=sql_fetch_array($result); $i++) {<br />
echo $row['content'];<br />
}<br />
?&gt;</p>

<p> </p>

<p>그누보드에선 잘사용하던 소스인데 오류가 발생해 문의한결과 </p>

<p>그누보드는 sql_query 이지만 (그누보드는 함수를 재정의 되어 있습니다.)</p>

<p>mysql_query를 써야 합니다란 답변으로 아랴와같이 수정했으나 마찬가지로 오류가 납니다.</p>

<p> </p>

<p>&lt;?<br />
$sql = " select * from books ORDER BY RAND() LIMIT 1";<br />
$result = mysql_query($sql);<br />
for ($i=0; $row=mysql_fetch_array($result); $i++) { <br />
echo $row['content'];<br />
}<br />
?&gt;</p>

<p> </p>

<p>방법이 있다면 좀 알려주시면 감사겠습니다.</p>
]]></description>
		<copyright>Copyright 2026, 코스모스팜</copyright>
				<item>
			<title><![CDATA[말씀드렸다시피 $wpdb-&amp;gt;get_row() 이건 한 줄을 가져오는 방법입니다.

엑셀의 표로 비유를 하자...]]></title>
			<link>https://www.cosmosfarm.com/threads/document/12449</link>
			<description><![CDATA[<p>말씀드렸다시피 $wpdb-&gt;get_row() 이건 한 줄을 가져오는 방법입니다.</p>

<p>엑셀의 표로 비유를 하자면 엑셀 한 줄을 가져오는 거죠.</p>

<p>엑셀의 여러줄을 가져오려면 $wpdb-&gt;get_results() 이걸 사용해야 합니다.</p>

<p>응용하자면 아래 코드처럼요.</p>

<p>&lt;?php<br />
$books_list = $wpdb-&gt;get_results("select * from `books` ORDER BY RAND() LIMIT 3");</p>

<p>foreach($books_list as $book){<br />
    echo $book-&gt;content;<br />
}<br />
?&gt;</p>

<p>컬럼(column) 과 로우(row) 의 차이를 이해하시면 도움이 될 듯합니다.</p>
]]></description>
			<author>스레드봇</author>
			<pubDate>Mon, 20 Feb 2017 02:27:47 +0000</pubDate>
			<category>워드프레스</category>
		</item>
				<item>
			<title><![CDATA[정말 감사합니다.

근데 한가지 질문만 더드릴께요

가령 3개를 출력한다면 아래처럼 하면 될거 같은데 ...]]></title>
			<link>https://www.cosmosfarm.com/threads/document/12443</link>
			<description><![CDATA[<p>정말 감사합니다.</p>

<p>근데 한가지 질문만 더드릴께요</p>

<p>가령 3개를 출력한다면 아래처럼 하면 될거 같은데 안되네요.</p>

<p>완전 초보라 이해 바랍니다.ㅠㅠ</p>

<p>&lt;?php<br />
$book = $wpdb-&gt;<strong>get_row</strong>("select * from `books` ORDER BY RAND() LIMIT 3");<br />
echo $book-&gt;content;<br />
?&gt;</p>
]]></description>
			<author>망자</author>
			<pubDate>Sun, 19 Feb 2017 04:03:33 +0000</pubDate>
			<category>워드프레스</category>
		</item>
				<item>
			<title><![CDATA[워드프레스에서는 데이터베이스 쿼리 기능이 조금 다릅니다.

우선 아래처럼 하시면 될 듯합니다.

&amp...]]></title>
			<link>https://www.cosmosfarm.com/threads/document/12440</link>
			<description><![CDATA[<p>워드프레스에서는 데이터베이스 쿼리 기능이 조금 다릅니다.</p>

<p>우선 아래처럼 하시면 될 듯합니다.</p>

<p>&lt;?php<br />
$book = $wpdb-&gt;<strong>get_row</strong>("select * from `books` ORDER BY RAND() LIMIT 1");<br />
echo $book-&gt;content;<br />
?&gt;</p>

<p>혹은 아래처럼요.</p>

<p>&lt;?php<br />
$content = $wpdb-&gt;<strong>get_var</strong>("select `content` from `books` ORDER BY RAND() LIMIT 1");<br />
echo $content;<br />
?&gt;</p>

<p> </p>

<p>간단히 설명을 드리자면,</p>

<p>하나의 값을 가져오는 방법입니다.</p>

<p>&lt;?php<br />
$user_count = $wpdb-&gt;<strong>get_var</strong>( "SELECT COUNT(*) FROM $wpdb-&gt;users" );<br />
echo "&lt;p&gt;User count is {$user_count}&lt;/p&gt;";<br />
?&gt;</p>

<p> </p>

<p>한 줄을 가져오는 방법입니다.</p>

<p>&lt;?php<br />
$mylink = $wpdb-&gt;<strong>get_row</strong>("SELECT * FROM $wpdb-&gt;links WHERE `link_id`=10");<br />
?&gt;</p>

<p> </p>

<p>여러줄을 가져오는 방법입니다.</p>

<p>&lt;?php<br />
$users_list = $wpdb-&gt;<strong>get_results</strong>("SELECT * FROM $wpdb-&gt;users LIMIT 10");</p>

<p>foreach($users_list as $user){<br />
    echo $user-&gt;display_name;<br />
}<br />
?&gt;</p>

<p> </p>

<p>워드프레스의 데이터베이스 쿼리 방법은 자세한 설명은 아래 링크를 확인해주세요.</p>

<p><a href="https://codex.wordpress.org/Class_Reference/wpdb" target="_blank">https://codex.wordpress.org/Class_Reference/wpdb</a></p>
]]></description>
			<author>스레드봇</author>
			<pubDate>Sun, 19 Feb 2017 02:33:23 +0000</pubDate>
			<category>워드프레스</category>
		</item>
			</channel>
</rss>