Questions tagged [mysql-select-db]
74 questions
8
votes
2 answers
Can you reuse a mysql result set in PHP?
I have a result set I pull from a large database:
$result = mysql_query($sql);
I loop through this recordset once to pull specific bits of data and get averages using while($row = mysql_fetch_array($result)). Later in the page, I want to loop…

MarathonStudios
- 3,983
- 10
- 40
- 46
5
votes
5 answers
How can I select the last edited version of a post?
Here is the table structure:
+----+-----------------------------+-----------+
| id | post_content | edited_id |
+----+-----------------------------+-----------+
| 1 | content 1 | NULL |
| 2 | content 2 …

Martin AJ
- 6,261
- 8
- 53
- 111
3
votes
5 answers
How to insert data in two different tables of two different database in php
I have to insert data in two different database's table.
I have created database1 and table1 for database1,
also i have created database2 and table2 for database2.
For inserting data i have written code,
$connect =…

M Gaidhane
- 531
- 8
- 29
2
votes
4 answers
Insert query depend on another table
Below are MySQL tables. I need to insert values from table A's ID column to Table B's ID_A column. Already existed values in ID_A should be ignored. So that in the below mentioned example IDs 1 to 3 from Table A should be ignored and IDs 4 to 10…

Kaizar Laxmidhar
- 859
- 1
- 17
- 38
2
votes
2 answers
"mysql_select_db" fails while "mysql_connect" OK
new here, only starting basic PHP. Trying to understand the specifics of the two MySQL commands.
Please see this code

Andrejs
- 10,803
- 4
- 43
- 48
2
votes
3 answers
how to select MAX(updateTag)
I create digiCardPass with updateTag column that is timestamp.
I try:
$query1 = mysql_query("select MAX(updateTag) as updateTag from digiCardPass");
$row1 = mysql_fetch_array($query1);
$updateTag = $row1['updateTag'];
error_log("max…

malinchhan
- 767
- 2
- 8
- 28
1
vote
2 answers
MySql query to return a random row returns unexpected number of rows
I am trying to get a random word from a long list of words in a MySql table: word_list [id*|wword].
My query looks at the moment like this:
SELECT * FROM word_list w where id = (SELECT FLOOR(1 + RAND()*(10-1)))
I thought the above query would…

Muleskinner
- 14,150
- 19
- 58
- 79
1
vote
1 answer
Need to Create MySQL Procedure for getting data from table based on condition and insert them into another table
Using a single MySQL procedure i need to write queries to get data from a table (where the results can be of a list also) after getting the results,need to insert those selected rows into another table of the same database..I'm finding dificulty in…

reema
- 19
- 8
1
vote
2 answers
What is the best approach to getting the last x records? Using MySQL Limit and ORDER DESC?
I was wondering if there are any other best/better practices then this as far as performance or optimizations.
EDIT: I'm using PHP7. Should have made that clear, I apologize. I'm doing a volunteer project for a local non-profit and it's setup like…

BluTiger
- 27
- 8
1
vote
1 answer
How to add new column in select statement
i want to add new column in my select statement
SELECT…

Mheljun Enanoria
- 25
- 5
1
vote
1 answer
MySql Distinct Issues: Error Code: 1242 Subquery returns more than 1 row
I want to select distinct of apps_user.imeino
My current SQL Query:
SELECT app.name,app.emailid,app.mobileno,app.imeino,img.id,img.approve_status,img.path
FROM apps_user app, apps_userimage img
WHERE ((SELECT DISTINCT apps_user.imeino FROM…

naveen maurya
- 63
- 6
1
vote
1 answer
Show result of MYSQL select query in two div according to column name, using a single select query
I have a table with column names id, name, category, title,and news. Once select query executes I get all the required data from table but i need to split up this data into two div according to the category they belong. there are two different…

munna ss
- 194
- 1
- 2
- 11
1
vote
4 answers
php mysql_select_db parameter 2 not working
I have the following code for test, and I just found the 2nd parameter is not actually working.
$conn1 = mysql_connect("127.0.0.1", "xxxx", "xxxx");
$conn2 = mysql_connect("127.0.0.1", "xxxx", "xxxx");
mysql_select_db("test",…

Chenglu
- 1,757
- 2
- 14
- 23
1
vote
6 answers
MYSQL - select TABLE A rows that are not in Table B except the rows are in TABLE C
TABLE A:
dvdID.......dvdTitle
d01..........Avenger
d02..........Avenger
d03..........Spiderman
TABLE B:
rentID.......dvdID
r01...........d01
r02...........d02
r03...........d03
TABLE C:
returnID.......rentID
t01...............r01
i want to…

Altiano Gerung
- 824
- 2
- 15
- 28
1
vote
2 answers
MYSQL - How to UPDATE after SELECT from a table
i want to UPDATE the a column after i SELECT a table
SELECT id_copies, id_shop, id_dvd
FROM dvd_copies
WHERE id_dvd = '001-192.168.1.103-6' AND id_shop='002'
ORDER BY id_copies DESC
LIMIT 2;
i got just 2 rows that i want to be updated
how can i…

Altiano Gerung
- 824
- 2
- 15
- 28