473,406 Members | 2,439 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,406 software developers and data experts.

Store references in array

I'm writing a dynamic search page for my mysql database.

I'm having trouble with my mysqli_stmt_bind_param() statement entering multiple parameters.

Before the statement I am saving all my parameters in to an array called $paramArray.

How would I add each element of the $paramArray to end of the function arguments?

My original thought was to implode the array with the "," delimiter. However, the function will treat the implode as a single string.

Expand|Select|Wrap|Line Numbers
  1. //Excerpt
  2. $paramArray[] = 100;
  3. $paramArray[] = 500;
  4. $paramArray[] = 800;
  5.  
  6. ...
  7.  
  8. mysqli_stmt_bind_param($stmt, "iii", implode(",",$paramArray));
  9.  
  10.  
The implode function creates the string, "100,500,800".
However I need it to work like this:

Expand|Select|Wrap|Line Numbers
  1. mysqli_stmt_bind_param($stmt, "iii", $paramArray[0], $paramArray[1], $paramArray[2]); 
  2.  
Any ideas? Thanks in advance!
May 3 '13 #1

✓ answered by Dormilich

My original thought was to implode the array with the "," delimiter. However, the function will treat the implode as a single string.
because it is a single string.

Before the statement I am saving all my parameters in to an array called $paramArray.

How would I add each element of the $paramArray to end of the function arguments?
unfortunately there is no easy way to do that in mysqli. you either do it manually (as demonstrated in your last code block) or you could try call_user_func_array():
Expand|Select|Wrap|Line Numbers
  1. array_unshift($paramArray, str_pad("", "i", count($paramArray)));
  2. call_user_func_array(array($stmt, "bind_param"), $paramArray);

4 1491
Exequiel
288 256MB
can you state some output examples that you want to print by your code??
May 3 '13 #2
Dormilich
8,658 Expert Mod 8TB
My original thought was to implode the array with the "," delimiter. However, the function will treat the implode as a single string.
because it is a single string.

Before the statement I am saving all my parameters in to an array called $paramArray.

How would I add each element of the $paramArray to end of the function arguments?
unfortunately there is no easy way to do that in mysqli. you either do it manually (as demonstrated in your last code block) or you could try call_user_func_array():
Expand|Select|Wrap|Line Numbers
  1. array_unshift($paramArray, str_pad("", "i", count($paramArray)));
  2. call_user_func_array(array($stmt, "bind_param"), $paramArray);
May 4 '13 #3
Thanks.

In order to get this to work I needed to add "&" to each of my variables stored in my $paramArray. (They are not all static values.)
May 7 '13 #4
Dormilich
8,658 Expert Mod 8TB
(They are not all static values.)
you must not pass values into ->bind_param() only variables, hence you need the references.
May 7 '13 #5

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

Similar topics

11
by: Colin Steadman | last post by:
Hope this makes sense! I'm building an ASP page which allows uses to add items to an invoice via a form, ie: Item No Part No Order No Quanity Units Price VAT ------- ...
3
by: jacob nikom | last post by:
Hi, I would like to be able to store numerical array in MySQL. I am really looking for the solution to store it in the one field only. For example, I have a matrix, which I want to store in...
1
by: Opa1 | last post by:
Hi, This question has been asked b4 on these newsgroups. I can't find a clear example. I have a byte array called signature. I'd like to store this byte array in a SQL server varbinary...
10
by: Peter Stojkovic | last post by:
I want store an integer-array of 1000 Values in a blob in a SQL-database. I will do this every 10 Seconds. How can I do this ???? What datatypes a have to use ??? Thanks
10
by: dfetrow410 | last post by:
Is there an example of how to store and access an array in a Property Dave
7
by: rhitz1218 | last post by:
Hi all: Is it possible to store an integer array to another integer array? Or should I use an array of pointers that will point to a particular array? Thanks for the help.
0
by: rajamohammed | last post by:
Can anyone please help me how to store byte array in SQL database? Please give some sample code. Thanks in advance.
5
rahulephp
by: rahulephp | last post by:
Hi there, can you please help me? i have data in array and i want to insert it in a single table. structure of table and array to be store is shown below: Please let me know how to store...
5
by: jatinch | last post by:
i have a byte array having 16 elements i.e 128 bits.. i want to do bit manipulations on this 128 bit byte array how can i store this 128 bit as one no.so i can do bit manipulations
3
by: Arjun Sarankulu | last post by:
I want to read numbers from XML file Suppose xml file contain <number>1</number> <number>10</number> <number>20</number> <number>30</number> <number>69</number> The above mention numbers in...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.