PHP array
I have a page listing part numbers and each row one checkbox. When selected rows are tagged, press "Save" and MySQL is updated. How to create an array?
Each checkbox (row) has a different value.
$TickMark=$Tickmark + 1;
print <<<EOD
<td>
<INPUT type=checkbox name="CheckApp" value="$TickMark">
</td>
<td>$myrow[PartNo]
</td>
When "Save" button is pressed:
$checkapp=$_POST['CheckApp'];
if (issue($checkapp) && $checkapp !="") {
mysql_query("UPDATE StockReg SET OrderTick = '$checkapp' WHERE PartNo = 'partno'");
rasat wrote:
Romashka wrote:What a strange construct... Is it Perl/Python/Rubysh thing? :?
Copied from from php's official manual. You also recommended to read it, that's what an user may get when too much information.
Where did you read that?
Function Reference - Arrays - foreach
The right way is described here, and also
You may have noticed that the following are functionally identical:
Even in Language Reference - Types - Arrays there's no mention of list/each way, only foreach. So I'm curious why did you choose that way.
It's highly recommended to read Language Reference, Security and Features before Function Reference, and always have the latest version of PHP Manual with users' comments (or online).
rasat wrote:This is why I prefer instead Arch Forum (General Programming Forum) ... if not the direct answer but right direction for the solution.
Arch Community is great!
rasat wrote:Thanks, for the simpler format.
You are welcome!
BTW, you are forum and wiki admin, but who maintains their code? dtw?
Similar Messages
-
Bind PL/SQL array to PHP array
Hi all!
I try to bind a PL/SQL array (nested tables, index by integer) returned by a PL/SQL-function to an PHP array.
Here is the code:
create or replace package MyPackage as
TYPE my_type IS TABLE OF VARCHAR2(1024);
FUNCTION MyFunction RETURN my_type;
end MyPackage;
create or replace PACKAGE BODY MyPackage is
FUNCTION MyFunction RETURN my_type IS
t_docs my_type;
begin
t_docs := my_type('val0','val1','val2');
return t_docs;
end MyFunction;
end MyPackage;
In the PHP-code ist looks like this
$query = "begin :vals := MyPackage.MyFunction; end;";
$stmt = oci_parse ($conn, $query);
oci_bind_array_by_name($stmt, ":vals", $vals_array, 5, 512, SQLT_CHR);
oci_execute ($stmt);
Output:
PLS-00382: expression is of wrong type. Error in Line....
This error point to
begin :vals := MyPackage.MyFunction; end;
^^^
Questions:
Is it generally possible to bind a pl/sql array to a php array? Or only the other was around?
Could you please post a snipet of code how to do it the right way :-)
Thanks a lot for your help! ChristianAs you noted, you can't return a PL/SQL array and map it to a PHP array when it is a record type. Likewise, you can't map an object type to a PHP array. You can return a reference cursor through PL/SQL, and then fetch the function result with oci_fetch_assoc($rc).
Alternatively, you can return an object type collection or a pipelined table function result into PHP. It's a bit long but you'll find examples on my blog. Start here, and there's a link to a full discussion of pipelined table functions:
http://blog.mclaughlinsoftware.com/2009/03/19/beats-a-reference-cursor/
This is an object table example, which you may prefer over pipelined table functions:
http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
Hope this helps. -
How to store spry data in php array
I am trying to store spry data in php array like this:
<? $foo= array();?>
<div spry:region="dsCALC">
<div spry:repeat="dsCALC">
<?php
$foo[]='{dsCALC::DataPrice}';
?>
</div>
</div>
<?var_dump($foo);?>
Outputs:
Array ( [0] => {dsCALC::DataPrice} )
If I tried a variable, it works ok... The array, not... Any ideas?Outputs:
Array ( [0] => {dsCALC::DataPrice} )
And so it should, because that is what you told the PHP-script to do in the following line of code.
$foo[]='{dsCALC::DataPrice}';
Please remember that PHP code is handled on the server, whereas JavaScript (Spry) is handeld on the client (browser) end. JavaScript cannot be handeld by PHP nor can JavaScript handel PHP.
My question to you is, why do you want to store the data in a PHP-array and how is the Spry data obtained?
Ben -
Import PHP-Array into Java-Application
Hi!
I want to call a PHP-Script from inside my Java-Application. The PHP-Script can return an array.
How do I use a PHP-Array in Java and how do I import it????
Thanks! =)thanks! =D
one last question:
-how would i have to change my example to make a
https-connection?
Did you try
URL theURL = new URL("https://www.mysite.com/myscript.php");It works that simply. The only complication is if your server is set up for https or not. This is an Apache (or whatever webserver you are using)problem not a PHP problem.
I think it gets upset if you try and use certificates with problems (self-signed etc) but not having tried this (I have only used it with certificates that are otherwise trustable) I don't know that for sure.
Once upon a time I asked a question about using https as a client in Java and I got a variety of answers including doing mystic stuff with my keystore but I tried the simple and obvious and it works like a charm. At least from an Applet but I see no reason an application won't work the same way.
Anyway try the simple and easy and see if that works for you. You might find that it does. -
Hi,
First off, I hope this is the proper place to post this
question... I've been looking all over for an answer and have yet
to find one.
I'm currently working on a project where I need to submit an
array of intergers into a database. The user makes a number of
selections on a form of check boxes, the form is submitted, and an
array (should be) stored in a column within my database. I'm
currently having issue though with only the value of the final
checked box appearing in my database. I'm wondering if anyone can
help as I've checked all over and can not find an appropriate
answer. Thank you in advance.sacomoney wrote:
> I'm sure it's not overly complicated but I
> guess I'm just not ready to grasp it yet.
It's not overly complicated, but you have come face-to-face
with a
common problem: it appears that you're relying on Dreamweaver
to
generate PHP for you without really understanding how the
code works.
Once you start doing anything not covered by the basic server
behaviors,
you need to have a good knowledge of PHP in order to adapt
the code
successfully. You have made a brave attempt, but it won't
work like that
in a million years.
The code that I gave you needs to go at the top of the page
like this:
<?php
if (isset($_POST['cb_minorcat'])) {
$_POST['cb_minorcat'] = implode(',', $_POST['cb_minorcat']);
} else {
$_POST['cb_minorcat'] = null;
?>
Then you need to change the code created by Dreamweaver from
this:
GetSQLValueString($_POST['cb_minorcat'] ? "true" : "",
"defined","'Y'","'N'")
to this:
GetSQLValueString($_POST['cb_minorcat'], "text")
Dreamweaver's GetSQLValueString() function prepares the form
values for
safe insertion into the database. What the first block of
code does is
change the array into a string. Therefore, you need to pass
$_POST['cb_minorcat'] to GetSQLValueString() as text.
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS4",
"PHP Solutions" & "PHP Object-Oriented Solutions"
http://foundationphp.com/ -
Not sure what's going on here, but hopefully someone can spot where I'm going wrong.
Its especially weird, as I'm using the same code, with the same database table names etc but on a different site.
Basically, I've set up a database table to store customer feedback on products.
Its all working fine on this site :
http://www.mye-reader.co.uk/customerreviews.php
But on the site I'm working on, its only showing the first record. There are only a couple of records at the moment, but I've tried changing the query from ASC to DESC, and it swaps the one it shows, so it looks like the issue is with the array. Even though its the same code.
http://www.mybabymonitors.co.uk/reviews.php
Anyway, my query looks like :
mysql_select_db($database_connPixelar, $connPixelar);
$query_rsReviews = "SELECT * FROM feedback WHERE Approved = 'Yes' ORDER BY Product DESC";
$rsReviews = mysql_query($query_rsReviews, $connPixelar) or die(mysql_error());
$row_rsReviews = mysql_fetch_assoc($rsReviews);
$totalRows_rsReviews = mysql_num_rows($rsReviews);
And the array code looks like :
<table cellpadding="0" cellspacing="0" width="100%" border="0">
<?php
$groups = array();
while ($row = mysql_fetch_assoc($rsReviews)) {
$groups[$row['Product']][] = $row;
foreach ($groups as $product_name => $rows) {
echo "<tr><td class=\"product\">$product_name</td></tr>";
foreach ($rows as $row) {
echo "<tr><td class=\"review\">".$row['Review']."</td></tr>";
echo "<tr><td class=\"name\">".$row['CustomerName']."</td></tr>";
echo "<tr><td class=\"date\">".$row['Date']."</td></tr>";
?>
</table>
Any ideas what's going on here?Its OK - I figured it out - it was the
$row_rsReviews = mysql_fetch_assoc($rsReviews);
line in the query.
Turns out it wasn't that one was working, and the other not - they were both starting from the second record. -
Dreamweaver CS6 does not recognize PHP array shorthand: []
If you use the shorthand [] in PHP for arrays, dreamweaver thinks it is syntax error.
array('hello', 'how', 'are', 'you'); works
['dreamweaver', 'is', 'not up-to-date']; triggers a (false) syntax errorNo. That's the difference between buying CS6 on a perpetual licence and CC on a subscription basis. You can use CS6 indefinitely without paying any more, but it will not be updated. CC gets regular updates, but is available only on a subscription basis.
-
Php array returning "null" to flash
my php seems to have trouble with an array that comes from a
datagrid from flash. I then proceed to
read the array and update the database but this doens't seem
to work cause I can't get to the objects in the array.
My return value to flash only produces "null"You have to serialize the array prior to sending it to your
php script. Use Alessandro Crugnola's SerializerClass to
serialize/and unserialize the array.
http://www.sephiroth.it/test/unserializer/ -
AS3 and/or PHP Array Issue
Good day,
Does anyone have any ideas (better yet, an effective
solution) as to why the following PHP code:That is odd,
Using this php -
<?php
$getYear=$_POST['year'];
$getMonth=$_POST['month'];
$getDate=$_POST['date'];
//omitted host etc...
$con = mysql_connect($host,$username,$password);
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db($db_name, $con);
$result = mysql_query("SELECT * FROM calendar WHERE
year='$getYear' AND month='$getMonth' AND date='$getDate'");
$return = "";
// Loop thru and pull out all records
while($row = mysql_fetch_assoc($result))
$return = $return . "year=" . $row["year"] ."&";
$return = $return . "month=" . $row["month"] ."&";
$return = $return . "date=" . $row["date"] ."&";
$return = $return . "time=" . $row["time"] ."&";
$return = $return . "title=" . $row["title"] ."&";
$return = $return . "description=" . $row["description"]
$return = $return . "type=" . $row["type"] ."&";
// Get rid of the last ampersand and echo the string
$return = substr($return, 0, -1);
echo $return;
mysql_close($con);
?>
and this AS
var url:String = phpURL;
var reqURL:URLRequest = new URLRequest(url);
reqURL.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.year = "2008";
variables.month = "9";
variables.date = "29";
reqURL.data = variables;
var ldr:URLLoader = new URLLoader(reqURL);
ldr.dataFormat = URLLoaderDataFormat.VARIABLES;
ldr.addEventListener(Event.COMPLETE, handleComplete);
function handleComplete( event:Event ):void
var ldr:URLLoader = URLLoader(event.target);
var vars:URLVariables = new URLVariables(ldr.data);
trace("year="+vars.year);
trace("month="+vars.month);
trace("day="+vars.date);
trace("time="+vars.time);
trace("title="+vars.title);
trace("description="+vars.description);
trace("type="+vars.type);
yields in the flash output panel
year=2008,2008
month=9,9
day=29,29
time=5:00,6:00
title=Test Event,test event 2
description=this is a test event to test the functionality of
the calendar.,this is a second test event
type=1,1
No problem with testing in the flash IDE. -
Hello,
Can PHP process more rows in ocifetch ?
regardsI did a little testing on Windows 2000 using SQL*Plus and client
libraries from Oracle 9.2. The DB was a 9.2 release on a remote
machine.
The SQL script was:
connect scott/tiger@mydb
define AS = 1
prompt Arraysize &AS
set arraysize &AS
set pagesize 0
set linesize 200
set termout off
spool c:\temp\bmsp.log
timing start
select * from all_objects order by 1;
spool off
set termout on
timing stopThe PHP file was:
<?php
require("ScriptTimer.php"); // from user comments on "microtime" man page
$pfrc = 1;
$filename = "c:/temp/bmphp.log";
$conn = OCILogon('scott', 'tiger', 'mydb');
Script_Timer::Start_Timer();
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
$query = 'select * from all_objects order by 1';
$stid = OCIParse($conn, $query);
OCIExecute($stid);
OCISetPrefetch($stid, $pfrc);
while ($succ = OCIFetchInto($stid, $row)) {
foreach ($row as $item) {
fwrite($handle, $item." ");
fwrite($handle, "\n");
fclose($handle);
$total_time = Script_Timer::Get_Time(3);
echo "$pfrc Time was $total_time\n";
?>SQL*Plus 9.2 results:
Time Arraysize
2.1 1000
2.1 500
2.1 250
3.0 100
3.0 50
4.1 10
9.1 1 PHP (CLI) 4.3.4 results:
Time Prefetchrowcount
4.5 1000
4.5 500
4.6 250
4.7 100
4.8 50
5.7 10
9.2 1 This was a pretty rudimentary benchmark. There are a lot of areas of
difference between SQL*Plus and PHP that could be debated and
examined.
Overall I'm comfortable that PHP's prefetchrowcount has a positive
effect.
-- CJ -
[Discuss] Custom array works like PHP array
So far, i only tested it with string object and i hope it also work with other object.
Please give me any suggestion or inform me if have any error.
class ObjArray
{ protected Object key[];
protected Object field[][];
public ObjArray(Object k[],Object f[][]){ reset(k,f); }
public void reset(Object k[],Object f[][])
{ if(k.length<f.length)throw new ArrayIndexOutOfBoundsException();
key=k;
field=f;
public Object[] getKey(){ return key; }
public Object[] getField(int k){ return field[k]; }
public Object[] getField(Object k){ return field[getIndex(k)]; }
public Object getName(int k){ return key[k]; }
public int getIndex(Object k)
{ for(int i=0;i<key.length;i++) if(k==key) return i;
throw new ArrayIndexOutOfBoundsException(); //It should be something to do with the key key.
public Object getValue(int k,int f){ return field[k][f]; }
public Object getValue(Object k,int f){ return field[getIndex(k)][f]; }
public void push(Object k[],Object f[][])
{ if(k!=null)
{ Object[] temp=key;
key=null;
key=new Object[temp.length+k.length];
for(int i=0;i<temp.length;i++) key[i]=temp[i];
int length=temp.length;
for(int i=0;i<k.length;i++) key[length++]=k[i];
temp=null;
if(f!=null)
{ int length=field.length+f.length;
if(key.length<length)throw new ArrayIndexOutOfBoundsException();
Object[][] temp=field;
field=null;
field=new Object[length][];
for(int i=0;i<temp.length;i++)
{ length=temp[i].length;
field[i]=new Object[length];
for(int j=0;j<length;j++) field[i][j]=temp[i][j];
length=temp.length;
for(int i=0;i<f.length;i++)
{ field[length]=new Object[f[i].length];
for(int j=0;j<f[i].length;j++) field[length][j]=f[i][j];
length++;
temp=null;
public void dump()
{ for(int i=0;i<key.length;i++)
{ System.out.println(key[i]+"=>");
if(i+1>field.length) System.out.println();
else for(int j=0;j<field[i].length;j++) System.out.println(" "+field[i][j]);
public static void main(String[] args)
{ String[] key={"Name","Age","Location","Interest"};
String[][] field=
{ {"Max"},
{"21"},
{"Net surfing","Gaming","Learning"},
String[] key2={"Gender","Email","Height","status"};
String[][] field2=
{"[email protected]","[email protected]","[email protected]"},
{"180"},
ObjArray a=new ObjArray(key,field);
a.dump();
System.out.println();
/*output
Name=>
Max
Age=>
21
Location=>
Interest=>
Net surfing
Gaming
Learning
a.push(key2,field2);
a.dump();
System.out.println();
/*output
Name=>
Max
Age=>
21
Location=>
Interest=>
Net surfing
Gaming
Learning
Gender=>
Email=>
[email protected]
[email protected]
[email protected]
Height=>
180
status=>
a.reset(key,field);
a.dump();
System.out.println();
/*output
Name=>
Max
Age=>
21
Location=>
Interest=>
Net surfing
Gaming
Learning
Object[] k=a.getKey();
for(int i=0;i<k.length;i++) System.out.println(k[i]);
/*ouput
Name
Age
Location
Interest
Object[] f=a.getField(3);
for(int i=0;i<f.length;i++) System.out.println(f[i]);
/*output
Net surfing
Gaming
Learning
Object[] f2=a.getField("Interest");
for(int i=0;i<f2.length;i++) System.out.println(f2[i]);
/*output
Net surfing
Gaming
Learning
System.out.println("getName(3): "+a.getName(3));
//getName(3): Interest
System.out.println("getIndex(\"Interest\"): "+a.getIndex("Interest"));
//getIndex("Interest"): 3
System.out.println("getValue(3,1): "+a.getValue(3,1));
//getValue(3,1): Gaming
System.out.println("getValue(\"Interest\",1): "+a.getValue("Interest",1));
getValue("Interest",1): Gaming
If it works as good as expected, i will add few method(pop,remove,insert,shift,replace...)>
Almost. LinkedHashMap is an associative array that remembers the order of insertion. You can't however directly access it's n-th element.
And if the value associated with any given key is a list, then it can hold multiple values.
But: I don't really understand the advantage of being able to access the elements with both a key and an index. It seems pretty fragile to me. -
Do I need to convert it to XML on the server side?
you can pass the array itself to flex if you use AMFPHP.
-
Hi all
I have an array from a mysql database which is currently loaded into PHP, but i need to do some javascript functions on it. Iv trawled through google seeing if i can find a nice simplified version of what i want to do, but i dont seem to be able to find one to test it out on, can anyone help me outline how i can transfer the information in my php array into a javascript one?
many thanksThe swf is not truly "hidden" if you know how to look.
Essentially, what they did was this:
1. Create an html page with only the SWF in it - centered.
2. Place an iframe in the page that loads that html page.
Thats it. The source code shows you where the html page is located, and then, if you navigate to that html page you can view-source and find the path to the swf.
Interestingly, this does place a level of complexity into the mix, and stops a lot of people from finding the swf. But, if you know how to look, this cannot stop you.
It would be better to work something server-side to obscure this from the view, or to place a level of authentication in-between to guarantee that a user cannot get to the flash file.
lynda.com has a nice method, where they dynamically create a link to the video file (quicktime, but applicable) using a session variable that is only valid for about a minute (or less, I'm guessing on the time). So, if you view-source and try to navigate to that video file after-the-fact it will give you a "404 - file not found" error.
I must note, however, that it is impossible to stop someone from getting content if they are determined enough. You can place obstructions in the way that may/will stop 99.8% of people, but there are always those that are determined (and knowledgeable) enough to get through, even hacking the server if they must. -
Hi, I have problem with that.
I`ve done regular button with javascript on click event.
var aSubmitFields = xfa.data.saveXML("pretty");
xfa.host.messageBox(aSubmitFields, "XML", 1, 0);
event.target.submitForm({
cURL:"http://domain.com/index.php",
aFields: aSubmitFields,
cSubmitAs: "XML"
or only that
event.target.submitForm({
cURL:"http://domain.com/index.php",
cSubmitAs: "XML"
and it doesn`t work.
PHP is receiving data but it shows that XML as empty array (messageBox shows data properly).
I`ve tried also submit type button with same script. It`s receiving string but not formated as XML and when I have multiple dynamic rows (adding rows dynamically after pressing "add" button) it shows me only first row.It would be also very helpfull if somebody could tell me how to send multiple dynamic rows to index.php becouse standard submit http button sends only first row. I know that problem is from naming of instance variables. Instances are named Row[*] but htttp sends only first row "Row" and the rest are gone becouse of same name. How to fix it? How to submit row count to XML tags or php array?
-
Connecting to PHP in FB 4.5 bugs
Associative PHP arrays are no longer converted to Objects when transferred via AMF.
They are converted to ArrayCollections of length 0.
I create an associative array on the PHP side:
$foo['bar'] = 'test';
And with FB 4.0 I get an object on the client:
{foo='bar'}
FB 4.5 somehow generated services that return an ArrayCollectionYou don't undestand
FB 4.0 recognizes an associative array as an object
FB 4.5 recognizes an associative array as an array collection and makes every property an object.
This behaviour broke all my code and I'm getting ready to bang my head against the wall
Maybe you are looking for
-
Hi all I am working with JRun4. My problem is logging. logging mechanism can send messages to these destinations: 1) The console screen 2) The Log file. In both cases , logging information is obtained. but The console screen shows information which i
-
Hi All, There is an A/P Invoice, with no line Items. But the Document Total is Rs. 100000/- When I check the Base Document there are 10 Line Items in GR(PO). Surprised to see this..............How is it possible. And when i open A/P Invo
-
A lot of folks are having "issues" with battery life after the over the air (OTA) update and there has been much speculation as to the cause. My frustrattion level increased with each new post I read that did not reveal a resolution. The back and f
-
Oracle Advanced Queueing on 10G dequeue options FIRST_MESSAGE
Has anyone used the " dbms_aq.first_message " in their dequeue options when dequeueing from a queue with oracle advanced queueing? If so, have yoiu noticed any change in performance time ? Has it slowed processing time in anyway? Just looking for any
-
Why are my purchased songs not showing up in my library?
I recently updated iTunes, but now it shows that I only have 1 song in my Library, while everything else I ever purchased isn't showing up in my Library. They show up under Purchased but not in my Library. Help please?