-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
$sql = "SELECT s.sub_cat_name , GROUP_CONCAT(t.topic_title ORDER BY t.id $DESC_ASC SEPARATOR ', ') as items FROM subcategory s INNER JOIN datatb t ON(s.sub_cat_id=t.sub_id) GROUP BY s.sub_cat_id ORDER BY s.sub_cat_id $DESC_ASC LIMIT 5"; $res = $db->query($sql); while ($row = $res->fetch_assoc()) { echo "<strong>{$row['sub_cat_name']}</strong><br>{$row['items']}<br><br>"; } /** results **************** subcat a aaa, bbb subcat b ccc subcat c ddd, eee subcat d fff, ggg, hhh, iii subcat e jjj, lll ****************************/
-
At last! I've being trying to connect to the forum for over 3 hours. Yes, I missed the comma when I was rearranging your query. When I run with my test data I get this mysql> SELECT s.sub_cat_name -> , GROUP_CONCAT(t.topic_title ORDER BY t.id DESC SEPARATOR ', ') as items -> FROM subcategory s -> INNER JOIN datatb t -> ON(s.sub_cat_id=t.sub_id) -> GROUP BY s.sub_cat_id -> ORDER BY s.sub_cat_id DESC -> LIMIT 5; +--------------+--------------------+ | sub_cat_name | items | +--------------+--------------------+ | subcat f | mmm, kkk | | subcat e | lll, jjj | | subcat d | iii, hhh, ggg, fff | | subcat c | eee, ddd | | subcat b | ccc | +--------------+--------------------+ test data:
-
$date = '2013-11-01'; $last = date('Y-m-t', strtotime($date)); echo "$date - $last"; // --> 2013-11-01 - 2013-11-30 or you could do WHERE EXTRACT(YEAR_MONTH FROM date) = EXTRACT(YEAR_MONTH FROM '$date')
-
A while loop not executing could be the result of no matching data. Try simplifying the query $get = "SELECT * FROM ".TBL." WHERE test = '1' AND '{$fieldx['ShortVersion']}' IN (test, test2, test3, test4)"; (judging by those column names it looks like that table is a good candidate for normalization)
-
if you comment out the header function calls, does it produce the correct data output?
-
Try something like this (untested) SELECT s.sub_cat_name , GROUP_CONCAT(t.topic_title ORDER BY t.id $DESC_ASC SEPARATOR ', ') FROM subcategory s INNER JOIN datatb t ON(s.sub_cat_id=t.sub_id) GROUP BY s.sub_cat_id ORDER BY s.sub_cat_id $DESC_ASC, LIMIT 5
-
how to select last value for a particular value both in the same table
Barand replied to udaystrad's topic in MySQL Help
I have amended the code to pick up up the id from your attendance table and transfer it to attendancenew table. The final query then selects the id for display. $db = new mysqli(HOST,USERNAME,PASSWORD,DATABASE); $db->query("DROP TABLE IF EXISTS attendancenew"); // delete existing table $sql = "CREATE TABLE attendancenew ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, MemberId VARCHAR(3), TimeIn DATETIME, TimeOut DATETIME )"; $db->query($sql); $sql = "INSERT INTO attendancenew SELECT id , MemberID , CASE TimeIn WHEN 'Missed' THEN null ELSE STR_TO_DATE(CONCAT_WS(' ', Day, Month, Year, TimeIn), '%d %M %Y %T') END , CASE timeOut WHEN 'Missed' THEN null ELSE STR_TO_DATE(CONCAT_WS(' ', IFNULL(OutDay, Day), Month, Year, TimeOut), '%d %M %Y %T') END FROM attendance"; $db->query($sql); $sql = "SELECT a.id, a.MemberId, IF(a.timeout IS NULL,'Missing', a.TimeOut) as TimeOut FROM attendancenew a JOIN ( SELECT MemberId, MAX(COALESCE(TimeIn, TimeOut)) as latest FROM attendancenew GROUP BY MemberId ) as last ON a.MemberId = last.MemberId AND latest IN (a.TimeIn, a.TimeOut) "; $res = $db->query($sql); echo '<pre>'; printf("%5s %-10s%-20s\n\n", 'ID', 'MemberId', 'TimeOut'); while ($row = $res->fetch_row()) { vprintf("%5d %-10s%-20s\n", $row); } echo '</pre>'; Also note that to display the day month and year separately on output is not not necessary to store them separately in the database. SELECT id , MemberId , DATE_FORMAT(TimeIn, '%d %M %Y') as DayIn , TIME(TimeIn) as TimeIn , DATE_FORMAT(TimeOut, '%d %M %Y') as DayOut , TIME(TimeOut) as TimeOut FROM attendancenew; +----+----------+------------------+----------+------------------+----------+ | id | MemberId | DayIn | TimeIn | DayOut | TimeOut | +----+----------+------------------+----------+------------------+----------+ | 1 | 007 | 16 November 2013 | 12:32:50 | NULL | NULL | | 2 | 007 | NULL | NULL | 16 November 2013 | 12:34:45 | | 3 | 004 | 19 November 2013 | 11:25:12 | NULL | NULL | | 4 | 009 | 19 November 2013 | 13:39:02 | NULL | NULL | | 5 | 006 | 20 November 2013 | 11:01:44 | NULL | NULL | | 6 | 006 | 20 November 2013 | 11:02:40 | NULL | NULL | | 7 | 006 | NULL | NULL | 20 November 2013 | 11:02:57 | | 8 | 007 | 23 November 2013 | 11:52:42 | NULL | NULL | | 9 | 008 | 20 November 2013 | 15:07:47 | NULL | NULL | +----+----------+------------------+----------+------------------+----------+ -
Looks like my last month's electricity bill
-
mysql> SELECT * FROM shiftaction; +----+-------------+ | id | title | +----+-------------+ | 1 | Dell tablet | | 2 | Dell laptop | | 3 | Sony laptop | | 4 | Dell pc | +----+-------------+ 4 rows in set (0.00 sec) mysql> SELECT * FROM shiftaction -> WHERE title LIKE '%dell%' AND title LIKE '%laptop%'; +----+-------------+ | id | title | +----+-------------+ | 2 | Dell laptop | +----+-------------+ 1 row in set (0.00 sec)
-
mssql_ library is obsolete. Download the sqlsrv lib and documentation from Microsoft for MSSQL Server 2005 onwards http://www.microsoft.com/en-gb/download/details.aspx?id=20098
-
HOW TO Fetch data from multidimensional array without foreach loop
Barand replied to justin7410's topic in PHP Coding Help
Is there any reason why you can't just get the data for the city selected from the database when you want it rather than getting all the cities and storing in an array?- 3 replies
-
- multidimensional
- array
-
(and 3 more)
Tagged with:
-
One thing I did notice, you are putting email in company field and vice versa $query = "insert into complainant(username,password,c_name,email) values ('$com_username','$com_password','$com_email','$com_companyname')";
-
Sorry - missed the important bit SELECT m.id, m.name, SUM(v.rate) as total FROM mixtape m LEFT JOIN vote v ON m.id = v.id_mixtape WHERE m.status=1 GROUP BY m.id ORDER BY total DESC LIMIT 12
-
As there is nothing your tables regarding scolarship scolarship type marks family income no. of non-earning family members then I wish you luck in your venture. Goodbye.
-
You need to JOIN the tables. In this case use LEFT JOIN as there may be mixtape with no vote records SELECT m.id, m.name, SUM(v.rate) as total FROM mixtape m LEFT JOIN vote v ON m.id = v.id_mixtape WHERE m.status=1 ORDER BY total DESC LIMIT 12
-
xProteuSx, If there are less than 10 items then you'll have "undefined index" problems. This would cure it echo '<ul>'; $k = min(10, count($array)); for ($i = 0; $i < $k; $i++) { echo "<li>" . $array[$i] . "</li>"; } echo '</ul>';
-
$array = range(1,50); // create array with 50 items echo '<ul>'; foreach (array_slice($array,0,10) as $item) { // get first 10 items echo "<li>$item</li>"; } echo '<ul>';
-
try $sql = "LOAD DATA LOCAL INFILE '$filename' INTO TABLE keyurl FIELDS TERMINATED BY \",\" LINES TERMINATED BY \"\n\" IGNORE 1 LINES (keyword,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy) "; $db->query($sql) or die($db->error);
-
Some formats don't work with strtotime() and d/m/y is one of them. A couple of options $date = str_replace('/', '-', '26/11/2013'); echo date('Y-m-d', strtotime($date)); //--> 2013-11-26 $date = DateTime::createFromFormat('d/m/Y', '26/11/2013'); echo $date->format('Y-m-d'); //--> 2013-11-26
-
It's more of a "notice board" than a forum. People contact you direct (PM, email, skype) with their replies
-
Don't out put the link with the path, down load the selected file. The only link you expose is <a href="download.php?code=1001">Download me</a> and download.php would now look like <?php $get = $_GET['code']; if(!empty($get)){ require "script/db.ini.php"; $select = "SELECT * FROM files WHERE code='$get'"; $return = mysqli_query($db,$select); $row = mysqli_fetch_assoc($return); $name = $row['name']; $code = $row['code']; $size = $row['size']; $date = $row['date']; if($get !== $code){ header("Location: http://website.me"); }else{ // // download the file // header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="'.$name.'"'); header("Content-Transfer-Encoding: binary"); header('Pragma: no-cache'); header('Expires: 0'); readfile("myfilepath/$name"); } }else{ header("Location: http://website.me"); } ?>
-
That is why we have a freelance forum where you can hire someone to do the conversion for you
-
Please explain why.
-
Not as you have there. function a() expects a form as its parameter therefore b() would need to return a form. b() is not returning anything. Also, write your functions to return a result rather than echo something. This would work <?php function a($form ) { return "<div>$form</div>"; } function b() { $formElements = "<form>\n"; $formElements .= "<input type='text' name='name' />\n"; $formElements .= "<input type='submit' name='btnSubmit' value='Submit' />\n"; $formElements .= "</form>\n"; return $formElements; } echo a(b()); ?>
-
alternative using xpath search $min = 99999.99; foreach($xml->xpath('//Company') as $co) { if ($co->SLevel != '-') { $min = min($min, $co->SLevel); } } foreach( $xml->xpath("//Company[SLevel='$min']") as $lowest) { echo "$lowest->Name : $lowest->SLevel<br>"; } results Caledonian Life : 23.98 Caledonian Life : 23.98