我是mysql的新手,我正在使用joomla 2.5,通过表单模块我收集来自2个字段的值,这些值(item1,item2)正确存储在mysql表(item1,item2)中应该自动存储userID和电子邮件。 现在我可以正确地在表中保存值和电子邮件而不是用户ID(在joomla中的当前用户),我会调用这些值,直到我尝试过滤用户(或用户email - mysql WHERE命令) ),我尝试了不同的语法而没有结果。
here's the mysql table (jos_schede)
id; item1; item2; item3;
1; value1; value2; email1 (current user email)
2; value3; value4; email2 (different user email)
here i would like to store in another column the userID (current user)
这是我在joomla中添加的脚本来提取db值
<?php
defined('_JEXEC') or die('Restricted access');
?>
<?php echo('the values are'); ?><br />
<?php
$user =& JFactory::getUser();
$userEmail = $user->get( 'email' );
$userID = $user->get( 'id' );
//connect to the server
$link = mysql_connect ("myhost", "myuser", "mypw");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//connect to the database
mysql_select_db ("mydatabase");
//query the database
$query = mysql_query("SELECT item1, item2, item3, id FROM jos_schede, jos_users WHERE item3='*currentemail*'");
//fetch the results / convert results into an array
WHILE($rows = mysql_fetch_array($query)):
$id = $rows['id'];
$item1 = $rows['item1'];
$item2 = $rows['item2'];
$item3 = $rows['item3'];
echo "$userID<br>$item1<br>$item2<br>item3";
endwhile;
?>