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 4 years ago.
Improve this question
I have a array as below
$x= array("Name","Age","Place","John",34,"London","Ram",12,"New Delhi");
here I've to get as below
Name Age Place
John 34 London
Ram 12 New Delhi
is there any option to do this?
If you know the number of column you can use array-chunk :
$x= array("Name","Age","Place","John",34,"London","Ram",12,"New Delhi");
foreach(array_chunk($x, 3) as $row) // 3 is the number of column
echo implode("\t", $row) . PHP_EOL;
This will generate the output as:
Name Age Place
John 34 London
Ram 12 New Delhi
Related
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 5 years ago.
Improve this question
So I have this database:
John 4.2
Robert 6
Maria 3.2
What I would want is lets say I refresh a website. And in every refresh I will get a random name from that database based on the chance of showing-> that would mean that Robert would appear more times than the other people(because of his chance)
Any way to do this? I just can't think of anything.
I've create your table with columns name and weight.
The following request return on name, depending on the weight:
SELECT name FROM table ORDER BY RAND()*weight DESC LIMIT 1;
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 5 years ago.
Improve this question
From web scalping i get array like
1JANATAMF 7.20 -0.10 -1.37%
1STPRIMFMF 11.80 -0.10 -0.84%
AAMRATECH 32.80 0.40 1.23%
and many row.
I want to separate value like 1JANATAMF,7.20,-0.10,-1.37% or insert value to mysql data base by 1JANATAMF as a name and price as 7.20
How can i do this?
Regex: "#\s+#" Here we are matching string on one or more spaces.
Try this code snippet here
<?php
ini_set('display_errors', 1);
$data=array(
"1JANATAMF 7.20 -0.10 -1.37%",
"1STPRIMFMF 11.80 -0.10 -0.84%",
"AAMRATECH 32.80 0.40 1.23%"
);
foreach($data as $value)
{
print_r(preg_split("#\s+#", $value));
}
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 table named 'prices' and every range has its price.
course_id start end price
-----------------------------
1 1 5 20
1 5 10 18
1 10 100 15
-------------------------
I have for example $course_id = 1 and $weeks_num = 8.
How can I get the price of that course?
In the given example I should have 18 because 8 exists between 5 and 10.
You can use BETWEEN clause. http://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_between
...
WHERE 8 BETWEEN start AND end
...
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
My sample database query result looks like this.
ID Product Owner
1 iPhone Shanu
2 MotoX Shajan
3 HTC Amal
4 iPhone Jibi
5 MotoX Anil
6 iPhone Gregary
I like to get the number of each phones
I want the result like this:
iPhone 3
MotoX 2
HTC 1
This is a fairly basic query -
SELECT `product`, count(`product`)
FROM `table`
GROUP BY `product`;
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 9 years ago.
Improve this question
I have a variable $z_name=carredwidetastymodern...; (here I show just a part of string "opelmazdabmwhynday..." (in fact, it's a very long string)
I would like fill in ref field from $z_name, could anybody help me?
id name ref id name ref
10 opel 10 opel car
11 apple 11 apple red
12 river 12 river wide
13 food 13 food tasty
14 pc 14 pc modern
(here I show just a part of table. It's a very big table, a lot of records)
Use loop by all records and add inside
mysql_query("UPDATE table_name SET ref = '$z_name' WHERE id =$id");
Well, maybe I'm missing something... I would say that
"REPLACE INTO table_name SET ref = '" . $z_name . "'";