Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a MySql database with three columns: skp, date and usr. For each skp and date pair there are several usr(s). Is there a query that will pull the data out with the following array structure:
array[i]['skp']
array[i]['date']
array[i]['usr'][j]
I'm wondering if somehow using a group by would work?
Use GROUP_CONCAT.
SELECT skp, date, GROUP_CONCAT('usr') AS usr
FROM yourTable
GROUP BY skp, date
Then when retrieving, you can split the usr column into an array.
$array = ();
while ($row = mysqli_fetch_assoc($result)) {
$row['usr'] = explode(',', $row['usr']);
$array[] = $row;
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
My question is that.
there is data in table with different dates in created column where i manually enter date in format yyyy/mm/dd with help of insert data
i want to fetch data according to date in array.
and most important the date should be displayed only once and data similar to that date should be displayed in following array
for example
data of 2017/07/04 should be displayed on in one array
data of 2017/07/03 should be displayed in one array
{date:2017/07/04}{{id=4,name=abc,created=2017/07/04},{id=5,name=def,created=2017/07/04}}
Although the question is very limited - I think you're after something like this:
$array = array();
foreach ($result->result_array() as $row){
$array[$row['DATE']][] = array('id'=>$row['ID'],'name'=>$row['NAME'],'created'=>$row['DATE']);
}
Obviously you need to replace the capitalised field names with your DB references.
Should you then want it JSON encoded use json_encode($array);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Hello I have this array:
$_SESSION['id'] = array();
I would like to select all array ID'S and then select them from the database.
How to do it? I have no idea..
$sql='select name from table where id in ('.implode(",",$_SESSION['id']).')';
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to extract each row from a table, but in random order. How can I do that? I tried using rand(), but I was not successful.
My database is named "permis54_permis-online-date" and my table is named: "intrebari".
Use ORDER BY RAND() MySQL:
SELECT column FROM intrebari
ORDER BY RAND()
select * from intrebari order by rand();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to search number in my MySQL data. String is +310623212542 but the mysql row data is only 0623212542. How can i compare ? Please help i am new to the mysql
Use
In php
<?php
$search_text = substr('+310623212542',3);
mysqli_query("SELECT * FROM tbl WHERE search LIKE '%$search_text%'");
?>
or
in mysql
use SUBSTRING
SELECT * FROM tbl WHERE search = SUBSTRING('+310623212542' FROM 4)
Note: using substring in mysql impact performance issue, when large data present
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to obtain a column name EmailId from the table named Users. But it returns only the first string and nothing else?
PHP:
$sql="SELECT EmailId FROM Users;";
$result =mysqli_query($conn,$sql);
$col=mysqli_fetch_array($result);
The database has 3 email-ids but count($col) returns only 1. Why so?
Thanks in advance.
The database has 3 email-ids but count($col) returns only 1. Why so?
Because
$col=mysqli_fetch_array($result);
only fetch the first row according to the internal pointer of the dataset, and therefore
count($col)
returns 1 because $col is an array having 1 item.