Create Query on PHP [closed] - php

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 . "'";

Related

PHP Array (list) to Table [closed]

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

SELECT with a chance of showing [closed]

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;

Mysql php get record where number is between two ranges [closed]

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
...

Store numbers in mysql and change that number to something? [closed]

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 7 years ago.
Improve this question
I'm thinking adding a number to a row, and in an array (or something) i can declare what it is.
Like this:
mySQL table
id type duration
1 2 5
2 3 4
3 6 10
PHP array or something
type 2 = jumping
type 3 = biking
type 6 = painting
This way it will be easier to add, or remove a "type".
But sorry, i have no idea how to do this.
The effect I'm looking for is to display
Johan was jumping for 5 minuts
Johan was biking for 4 minuts
Johan was painting for 10 minuts
Help much appreciated!
I would suggest to safe everything to a DB instead of hard-coding it in your code. So taking your table as basis:
Table: t1
id type duration
1 2 5
2 3 4
3 6 10
Table: t2
type_id whatever
2 jumping
3 biking
6 painting
You could use a SQL-Join to combine those two tables:
SELECT t1.id, t2.whatever, t1.duration
FROM t1
JOIN t2
ON t1.type = t2.type_id
will produce
1 jumping 5
2 biking 4
....

Merge similar rows and count [closed]

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`;

Categories