I have page where I want to display a single value from one table based on a value found in another:
$username = 'Joe';
$query = 'SELECT * FROM chars WHERE uname = "$username"';
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$query = 'SELECT cname FROM chars INNER JOIN usrs
ON chars.cid = usrs.clastused WHERE usrs.uname = "$username"';
$q = mysql_query($query) or die(mysql_error());
$r = mysql_fetch_assoc($q);
echo '<p>q = "'.$q.'" and r = "'.$r['cname'].'"</p>'; //for debugging
foreach ($row['cname' as $opt) {
$output .= '<option value=\"'.$opt.'\"';
if ($opt=$r) {$output .= ' selected';}
$output .= '>'.$opt.'</option>';
}
PHPMyAdmin gives the response I expect CNAME Joe and $q
gives Resource id#5 but $r
is blank. How do I echo the result? What I want at the end of the day is to have a dropdown list where the clastused is the preselected option.
I fixed this by using the array variable directly:
foreach ($r as $opt) {
$output .= '<option value=\"'.$opt.'\"';
if ($opt=$cname) {$output .= ' selected';}
$output .= '>'.$opt.'</option>';
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다