我想在Yii 2中实现以下SQL查询,但没有成功. 这应该给出唯一公司名称的总数:SELECT count(DISTINCT(company_name)) FROM clients这应该显示带有客户端代码和id(PK)的company_name:SELECT (DISTINCT(company_name,client_code)) FROM clients怎么做到这一点?解决方法:尝试这个:$total = YourModel::find()->select('company_name')->distinct()->count();在搜索模型中:public function search($params) {$query = YourModel::fi...
关于指定的问题,请帮助我: 代码部分:$result = mysql_query("SELECT *, UNIX_TIMESTAMP(eventdate) AS eventdate, UNIX_TIMESTAMP(throughdate) AS throughdate FROM events ORDER BY eventdate where id='$_GET[id];'");// the above query is not working if ( mysql_num_rows($result) == 0 ) { print "<p>No events right now.</p>\n";} else {$lasteventmonth = '';while ($row = mysql_fetch_array($result)) { $eve...
<?php$conn=mysql_connect("localhost","root","")or die("cannot connect");$db=mysql_select_db("ticket",$conn)or die("no db");if (isset($_POST['submit'])){$name1=$_POST['name'];$phone1=$_POST['phone'];$email1=$_POST['email'];$pass1=$_POST['password'];}$query="insert into register(name,phone,email,pass) values ('$name1','$phone1','$email1','$pass1')";$result=mysql_query($query)or die("Error in pushing...
我有一个包含多个输入的表单,这是我的过滤器.这是我的代码(不是全部,只是我要解决的部分):$req_resumo = ''; $req_status = ''; $req_usuario = ''; $n_req = 0; $parametros = "";// Checks which fields are filled and increases the number of filters for future usage if (isset($_POST['usuario']) && $_POST['usuario'] != "") {$req_usuario = $_POST['usuario'];$n_req++; }if (isset($_POST['resumo']) && $_POST['res...
快速问题…我的SQL查询正在吐出这些数据……Array ( [id] => 1 [name] => Test Name [text] => This is text [image] => image.jpg ) 当有两行数据时,我的php代码有问题吗?$query = "SELECT id, name, text, image FROM categories";$results = mysql_query($query, $connection);$results = mysql_fetch_assoc($results);解决方法:mysql_fetch_assoc一次读取一行.您需要遍历结果集:while(false !== ($row = mysql_fetch_assoc($...
我已经在phpMyAdmin上输入了这段代码作为SQL查询.我正在尝试创建一个表(这是来自另一个站点的复制和粘贴代码)CREATE TABLE `members` ( `id` int(4) NOT NULL auto_increment, `username` varchar(65) NOT NULL default '', `password` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; -- -- Dumping data for table `members` -- INSERT INTO `members` VALUES (1, 'john', '1234');我收...
我真的不明白这里的问题是什么,我已经尝试了我可以做的所有事情来诊断问题,并设法隔离我认为问题的原因(见下面的隔离): 这是我的完整代码:include("db_conn.php"); $conn = mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error()); mysql_select_db($db_name) or die(mysql_error());;$timestamp = time(); $add_time = time()+(60*60);$query = "UPDATE links SET timestamp = '$add_time', hit_counter = '0' WHE...
我的mysql查询有问题. 我的数据库:sections id section_namegrades id user_id section_id date grade我希望我的数据显示如下: Section_name等级 但我希望等级最接近今天的日期……这是我到目前为止,但它没有显示最新的成绩.相反,它按ID排序(我猜)SELECT *FROM grades, sections WHERE sections.id = grades.section_idANDgrades.user_id = '.$id.'GROUP BY grades.section_idORDER BY grades.date DESC编辑:$id变量是会话中的用...
我将如何制作这个MySQL&的分页脚本? PHP查询.if (isset($_GET['c'])) { $c = $_GET['c']; }$query = mysql_query("SELECT * FROM Categories WHERE category = '$c' ");WHILE($datarows = mysql_fetch_array($query)):$id = $datarows['id'];$category = $datarows['category'];$code = $datarows['code'];endwhile;$query2 = mysql_query("SELECT * FROM Games WHERE category = '$code' ");WHILE($datarows_cat = mysql_fetch_a...
我想知道如何用PHP中的两个表进行查询? 我有这个单一的查询?php $sQuery = "Select * From tb_columnas Where col_Status='activo' Order by col_ID DESC"; $result = mysql_query($sQuery, $cnxMySQL) or die(mysql_error()); $rows_result = mysql_fetch_assoc($result); $total_rows_result = mysql_num_rows($result);if ($total_rows_result > 0){do {$id_columnas = $rows_result ['col_ID'];$col_Titulo = $rows_result [...
我有一个变量$元素,其值为:Array ( [4] => easy [5] => easy [7] => easy [8] => will [9] => easy [10] => will ) 我想在我的查询中使用此变量:$sql = "SELECT * FROM questions where type='$element'"; $result = $conn->query($sql);if ($result->num_rows > 0) {// output data of each rowwhile($row = $result->fetch_assoc()) {echo "id: " . $row["question_name"]. "<br>";} }实际上我想从$element变量的每个元素解析并...
我正在使用特定的查询来插入记录.一切顺利.我甚至用选择查询获取记录.但我的问题是,如果记录包含单引号”,那么它会给我这个错误:> NOTE: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 'B''' at line 1SELECT查询是:$result= mysql_query("SELECT s.name, s.sid as sid, s.category, p.name as pname FROM poet p INNE...
嗨,我试图找到如何修复我的查询以返回正确的结果.这是我的查询:$selectShoeRatingQuery = "SELECT cast(round(AVG(rating)*2)/ 2 as decimal(10,1)) FROM rating WHERE shoe_id = '$_GET[id]'"; $shoeRating = mysql_query($selectShoeRatingQuery);查询应返回一个带小数位的数字(3.5).它在PhpMyAdmin中测试时工作正常,但是在我的网站上它返回资源ID#8. 数据库连接一切正常.解决方法:mysql_query返回一个资源.你需要从中获取一行:...
我想在CI中组合AND OR mysql查询.我已经看过这个帖子:http://codeigniter.com/forums/viewthread/92818/.但他们没有在那里提供确切的解决方案. 如何使用严格的CI框架创建以下查询? (我可以在没有括号的情况下轻松创建查询,但它不是同一个查询.)SELECT * FROM `Persons` WHERE LastName='Svendson' AND Age="12" AND (FirstName='Tove' OR FirstName='Ola' OR Gender="M" OR Country="India") P.S.:这只是一个示例查询,即使它没有...
我已经搜索了可能的解决方案.我尝试循环以及尝试mysql_fetch_assoc和mysql_fetch_array的变体,但我仍然得到资源ID#5:0:错误. 这是我认为产生错误的代码.<?phpmysqlc();$email = GetSQLValueString($_SESSION['user'], "text");$query = sprintf("SELECT * FROM newmember WHERE email = %s",$email);$res = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />\n$sql");$row = mysql_fetch_assoc($res);?> ...