Select a value from others [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table wich contains:
RO;DE;ES;AU;IT;
How display data where DE is show on table! I need for milions queries!

It seems like you have multiple values in the same "cell". You will need to process the string. One way is to use wildcards:
SELECT something FROM something WHERE field LIKE '%DE%'
Please note however that your table design is absolutely terrible. It violates the first normal form. You should never have multiple values in a single cell that you then have to split using wildcards or other string functions. This adds overhead to your queries and will slow them down significantly. You say that you have millions of records, the impact of not having separate values has the potential to be quite large.
You should definitely think of breaking those strings into multiple records if you can.

Related

Using SQL table join to use a value from one table as a reference to a value in another (primary key) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I have two tables stored on phpmyadmin, 'gigs' and 'bands'.
gigs: "gigID, gigBand, gigDate"
bands: "bandID, bandName, bandGenre...."
gigBand is a integer which corresponds to the bandID. I am aiming to diplay all the available gigs, but show the actual band name rather than the number. I have read table joins are the easiest way of doing this, and I have no trouble displaying the data of 'gigs' on the webpage.
But managing to display the name rather than the value is proving very difficult.
Any advice, or even an example of the code would be greatly appreciated.
You need to use a MySQL JOIN to pull the records of two related tables.
http://dev.mysql.com/doc/refman/5.7/en/join.html
SELECT * from gigs
INNER JOIN bands ON gigBand = bandID
This is pretty basic stuff though, so I would strongly recommend taking the time to do a bit more research. This seems like a good place to start:
http://www.tutorialspoint.com/mysql/index.htm

Create individual variables for each row in table? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a table, codes, with 3 columns (code, email, sent).
How do I call on the first X number of rows of table codes and assign each individual code (in code column) a variable with ordered numbers? (ie $code1, $code2, $code3, $code4)
Now, I will be calling on a multiple of 10 rows (10 rows, 20 rows, 30 rows) at a time so I need to be able to call on these codes individually for other procedures.
Thanks so much for the help!
Try putting the results in an array. Then call on them by using $code['1'] or what ever you are looking for

Sort a list with a specific way [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a list of number in my database and wanna list them like this:
1
11
111
11101
11101001
11101002
11102
11102001
11102002
11102003
11102004
11103
Any suggestions?
You want to sort the items as strings. This way, "11101002" comes before "11102".
The parameter SORT_STRING will achieve that when sorting an array with sort():
sort($myarray, SORT_STRING);
You will need to populate an array with the data from your database.
Other option, possibly less costly, is to sort them directly when querying the DB, by using ORDER BY.
What you wanna do is to treat your numbers like strings.
You can CAST or CONVERT your numbers to strings :
ORDER BY CAST(my_numeric_column AS CHAR(50))

Retrieve mysql data that doesn't contain number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to retrieve a list of words, but don't want any words that contain a number or numbers in them.
The idea is very simple, but I'm not even sure how to try. I have one column of words some of which have numbers in them. I only want to retrieve the ones without numbers.
How would I do this in my SQL query?
Thanks
Use a regular expression, either with php's preg_match, or with REGEXP in mysql.
SELECT list_col FROM list_table WHERE list_col NOT REGEXP '[0-9]'

Deleting everything in database less than a number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In PHP, I would like to run a query that would delete every row in a database that had the ID of less than a figure.
The context I want to use it in, is running a PHP CRON job every 24 hours that will delete all rows with values in the 'time' column that are LESS THAN time();
Putting it in to another context: I want to run a query that will delete every row that has an ID of ~10.
Thanks
I imagine you are not very familiar with SQL. This is a simple delete statement:
delete from t
where id < 10;
This assumes that by "database", you really mean "table". It also makes some other assumptions about foreign key references in other tables. Because the question seems so basic, I am guessing these are not issues.
However, I would recommend that you study up a bit on databases if you are going to use them in your applications.

Categories