473,386 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to use two array in single query

How do I use two array in single query?

My code is:
Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['Submit']))
  2. {                
  3. echo $selected_radio = $_POST['q'];
  4. echo $qid=$_POST['qid'];
  5. reset($selected_radio);
  6. reset($qid);
  7. foreach($qid as $qid)
  8. {
  9.     foreach($selected_radio as $selected_radio)
  10.     {
  11.         echo $SQL = "UPDATE answers SET $selected_radio = $selected_radio + 1 WHERE QID=$qid";
  12.         $result=mysql_query($SQL) or die($result."<br/><br/>".$error);
  13. }
  14. }
  15. }
  16. ?>
Aug 17 '12 #1
1 1135
Dormilich
8,658 Expert Mod 8TB
hm, yes. two parallel but unsynchronised arrays are really a nuissance.

in case they indeed match, use a standard for() loop. two nested foreach()s can’t do what you want.

PS. I would use Prepared Statements here.
- they prevent SQL injection (which you currently ignore completely)
- they use the not-deprecated MySQLi or PDO libraries
- they’re very efficient when it comes to multiple query execution
Aug 18 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jai | last post by:
Say the following are the columns of a table A B C D E F Can a aggregate function like sum be applied to A like sum(a) and then order by b and c similarly aggregate function on d and group by e...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
6
by: ats | last post by:
I have a table that contains the database names of external databases. Each one of these external databases contain a table (which has the same structure) that I would like to query together as one...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
2
by: barrathi | last post by:
hai all, i have 10 database in one server. i need to take a backup daily iam using this type of query ex: mysqldump -a -u root -p dbname > dbname.sql(for each db) but i need
1
by: newbie | last post by:
table_info --------------------------------------------------------- | id | age | first_name | last_name | --------------------------------------------------------- | 10 | 21 | ...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
10
by: kirthikasubramanian | last post by:
I have to retrieve two tables which are not having any relation in a single query itself for example select * from memberphoto;select * from restricconfig; if i execute this query only...
25
by: Darsin | last post by:
Hi all I need to perform a summation on a column of a table based on a criteria given in another column in the same table. The catch is i need to perform different sums according to the number of...
1
by: bharathi228 | last post by:
How to write two or more select statements in a single query here my requirement is SELECT dbo.SYS_PARAMS.PARAMETER_NAME, dbo.SYS_PARAMS.PARAMETER_UNITS, SYSTEM2.dbo.CALIBRATION.CAL_TYPE, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.