Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Php Array Inserted (element By Element) Into Mysql DB


I want each element of the array to be inserted into the database, but only the last
element of the array is inserted... all the elements will echo... any ideas? I'm a PHP newbie... you can probably tell by the code:




View Complete Forum Thread with Replies

Related Forum Messages:
Auto-inserted "input" Element Is Causing XHTML 1.0 Strict Validation To Fail
I originally posted this in an HTML forum, but have realized that the solution may (a) require a server-side change or (b) be non-existent. In any case, since the page I'm dealing with is a PHP page and the problem has to do with an auto-inserted "input" element, I'll post it here, too. I'd appreciate any advice, commentary, or even pessimistic sympathy if I'm just SOL.

I am pasting some code below that I am having a lot of trouble with. I have a php guestbook page that I'm trying to validate, and I keep getting an error stating that I can't have a certain "input" element in a location in which I am not actually attempting to place one at all. I
have tried to enclose all other input elements in blocks of "td" tags, which has worked for the most part, but because this particular input element seems to be dynamically generated, I can't figure out what I ought to do to prevent it from producing this kind of error.

Here's the error code: ....

View Replies !
Does An Array Contain An Element?
I'm using PHP 4.4.4. Is there a shorter way to check if an array has
an element besides doing a for loop and iterating through each element?

View Replies !
Is The Element Of An Array The Last One ?
What is the best way to solve the next problem: PHP Code:

View Replies !
Getting Element Only Once In Array
I've got an array like so: 1,1,5 But I want to try and make it so if it has the ID appearing more than once then it won't be in the array multiple times. i.e. I want the above to say 1,5.

View Replies !
How To Get Array Element?
get_the_category() returns an array that looks like this:

ResourceArray ( [0] =stdClass Object ( [cat_ID] =3 [cat_name] =>
Certifications [category_nicename] =ms-certifications
[category_description] =Certification Resource [category_parent] =0
[category_count] =5 [fullpath] =/ms-certifications ) )

I want to get the value in "category_description" and have tried:

$category = get_the_category();
$cat_d = $category->category_description;
print_r($cat_d);

But that doesn't print anything. What is the correct way to get the
value I'm after?

View Replies !
Array Element
I am having trouble getting a weather sticker php script to work properly. I have been working with the guys that wrote it, but so far they haven't come up with a solution. They/we have narrowed it down to the section of the script that compares a text string (which has been converted into UPPER CASE) from a file generated by the weather station, with an array. It is supposed to match an index in the array, that points to which graphic file to generate. This works about 30% of the time.

(When the text string is VERY SIMPLE - like CLOUDY or CLEAR or RAIN) But not when the text string is more complex, like HEAVY RAIN, MIST OVERCAST, LIGHT RAIN or PARTLY CLOUDY.

Here is the line that defines one of the elements in the array:

Quote $vws_icon["PARTLY|MOSTLY+CLOUDY|SUNNY+THUNDERSTORM"] = "./icons/" . "$daynight" . "_tstorm.$image_format";

I did not incluse the whole script, nor the whole array because of its length.

My Question (Finally...) is --- in the line above within the square braces, he has enclosed a string in double quotes, but the string is delimited by | characters and + characters. Can someone explain to me in English what this means? I have tried reading through two big reference books on php arrays, and they only made me even less certain. (For example: "the line means - If the string is PARTLY or MOSTLY CLOUDY or SUNNY and THUNDERSTORM, then set $vws_icon to whtever the $daynight._tstorm.$image_format evaluates to.)

I know, my example translation makes NO SENSE in English. Maybe it makes no sense in php either? I think what he's trying to ask is "If the string contains 'THUNDERSTORM' and any of these other words, then generate the correct icon file for thunderstorm".

View Replies !
Using The Last Element In An Array
This is the code I have: PHP Code:

$sql = mysql_query("SELECT * FROM dt_directories WHERE category = '$category' ORDER BY name") or die(mysql_error());
  
$last_sql = mysql_query("SELECT * FROM dt_directories WHERE category = '$category' ORDER BY name DESC LIMIT 1") or die(mysql_error());

while ( $last = mysql_fetch_object($last_sql) ) {
     $last_element = "$last->name";
}

while ( $dirs = mysql_fetch_array($sql) ) {
     $allowed_dirs = $allowed_dirs."name = '$dirs[name]' OR ";
    }

What this does is output the following into the variable $allowed_dirs:

E.G - name = 'Best of the Web' OR name = 'Dmoz' OR name = 'Yahoo!' OR

Another part of the code outputs the last element in the array to the variable $last_element, in the example above, $last_element would be "Yahoo!". What I want to do is use $last_element to remove the last "OR" in the example above. Any ideas?

View Replies !
Sum One Array Element
I have an array that contains two elements partNo and Quantity. I want to sum the quantity element for all values in the array. From what I can tell array_sum() sums all elements and converts non-numeric fields to their number equivalent or something. whatever it does I don't get a good total. I'm sure there is an easy solution but I'm hitting a wall.

View Replies !
Get Key Of The First Element Of An Array
Is there an easy way to get the key of the first element of an associative array?

View Replies !
How Do I Use The First And Last Element Of An Array
I want to use the first and last element of an array, don't care what happens to the rest. I tried using.

$count=count($name);
$fname = $name[0];
$lname= $name['$count'];

but it only gives me the first one.

any ideas?

View Replies !
Add Element Onto Array
I have an array that has been already created from a script. Here is the code for that array:

$returnArray[]= array("id" => $smilieRow['id'],
"url" => $smilie->url,
"bbcode" => $smilie->bbcode);

I have another array too that is created pretty similarly to that. What I want to do is add another element to the array called "$num". Now I would just loop through it again with a foreach, but is there an easier way?

View Replies !
Get Value Element From Array:
removing one key=>value element from array: I have an array of this sort:

array(
[#document]=> <?xml version ="1.0"?>
[finemae]=>2344ddd
[subscriptionstatus]=>unread
[trackingnumber]=>45566
}

I wanted to get rid of the first Key=>value element which is #document=> <?....?>

element:

insert into table (#document,filename,subscriptionstatus,trackingnumber) value ('"<?...?>','..',...);

View Replies !
How Do You Take An Element *out* Of An Array?
is there a way to leave a certain field out?

for instance, I'm using http_build_query() to build a new query and I have page_num=2&color_id=5&start=5 and all I want to do is keep color_id=5&start=5 .. I don't want/need the page_num info How can I take that out of the array?

View Replies !
Element From An Array
I have an array that contains numbers. Each element in the array is guaranteed to be unique.Let's say I have another variable which I know for certain is in the array, but I don't know the position.


View Replies !
Delete Array Element
How can i delete an element from one array. Let us suppose that i've an array of 10 elements $a[0], $a[1], $a[2]...etc
And when i delete $a[2] i wanna the elements to be re-ordered like this
$a[0] will be the same $a[0]
$a[1] will be the same $a[1]
but $a[2] will be the $a[3] element i had before deleting $a[2]

It would be called in Delphi, HOW TO DELETE AN ELEMENT FROM A COLLECTION? Is this possible? Have i to use another type of data?
Hope you've understood the idea.

View Replies !
Use Session_is_registered() With An Element Of An Array
If I want to use session_is_registered() with an element of an array, how do I code it?

View Replies !
Deleting An Element In An Array??
Here is the problem:

I've got an array with the following elements

$array = ("ice","ice","polka","skate","polka");

thats 2 polka, 2 ice and 1 skate

Now i want someway of removing just one of the polka's from it..

so that i'd be left with:
$array = ("ice","ice","skate","polka");

what i did was a basic search with for loop and break

Code: for($x=0;$x<sizeof($array);$x++)
{
if($array[$x] == "polka")
{
echo("match ".$x);
break;
}
} alls well n good till now.. now i've got the index value(2 in this case) of the element which needs to be deleted.. but what should be done now?? is there any function which'll let me delete a particular element in an array?

Is there any other way to go around this?

View Replies !
Editing An Element Within An Array
I have a two-dimensional array that looks like this:
array(
array(0, 123),
array(0, 234),
array(0, 345),
array(0, 456)
)
I want to REMOVE any element that contains 234, and I want to
INCREMENT the first value for any element that contains 345, to make
it look like this:
array(
array(0, 123),...

View Replies !
How To Substract An Element From An Array
I'm looking for a function which substracts an element from an array. For example,

$array = array ("green", "red", "blue", "grey" );

array_substract($array, "red" );

now it's like I had :

$array = array ("green", "blue", "grey" );

notice that the order should be preserved!

View Replies !
Missing Array Element
I am trying to store the id's for 3 hotel rooms into an array called
$rooms, using a simple mysql select statement. Here is the code:

<?php require_once('Connections/Vita_Italiano.php'); ?>
<?php mysql_select_db($database_Vita_Italiano, $Vita_Italiano);
$query_rsAllRooms = "SELECT * FROM room";

$rsAllRooms = mysql_query($query_rsAllRooms, $Vita_Italiano) or
die(mysql_error());

$row_rsAllRooms = mysql_fetch_assoc($rsAllRooms);
$totalRows_rsAllRooms = mysql_num_rows($rsAllRooms);

// create array of all rooms
while ($row_rsAllRooms = mysql_fetch_assoc($rsAllRooms))
{
$rooms[]= $row_rsAllRooms['Room_Number'];
}

?>

When I use <?php print_r($rooms);?> to display the contents of the
variable, the array only contains 2 room numbers, instead of 3. These
are stored in $rooms[0] and $rooms[1].

Does anyone have any ideas what is going on here?

View Replies !
Missing Element In Array?!
I have the following query I run to pull some data from the db. The
sql (when run on the db) returns 2 elements. However, if I var dump my
variable ($aidlook) then the first element in the array does not show
up.

$getaid = mysql_query("SELECT a_uid FROM `answers` WHERE `qid` =
$qid", $db);
$aidlook = mysql_fetch_array($getaid,MYSQL_NUM);

Doing a var dump returns: array(1) { [0]= string(1) "4" }

I should be getting 2 elements (4 and 5).

I am totally baffled. code as follows:

*********************
if (!is_array($aidlook)) $aidlook = array($aidlook); // Check for the
existence of the array in case of null returns

if (!in_array($userid,$aidlook)) // Look for our element which in
this case is "5"
{
if ($qstatus === 1) // Do a status check
{
}

answer_box($qid,$answ); // additional function being run

} else
{
echo "Your Text Here";

}
}

View Replies !
Deleting An Element Of An Array?
How can I delete an Element of an array? Consider the following Example: PHP Code:

View Replies !
Eliminate An Element Of An Array
I want to eliminate the last element of an array, couse when I print it, it doesn´t have any value. I tried to use array_pop but it doesn´t work.

View Replies !
Deleting An Element From An Array
is there some handy and short method to delete an element from an array and than shifting the rest of elements one place ahead
e.g

array(1,2,3,4,5,6)
becomes
array(1,2,4,5,6)

View Replies !
Remove Element From Array
How do I remove an element from an array? Here is my current code:

$sql = mysql_query("SELECT suitenos FROM gssettings WHERE id=1");
$row = mysql_fetch_assoc($sql);
$suites = split(",",$row['suitenos']);
$number_of_suites = count($suites);
for($i=0;$i<$number_of_suites;$i++)
{
if($suiteno == $suites[$i])
{
$selected = "SELECTED";
} else {
$selected = "";
}

echo<<<endhtml
<option value="$suites[$i]" $selected>$suites[$i]</option>
endhtml;
}

Now I have another table in my database called "gsdays" that holds values of suite numbers that are already booked. What I want to do is remove any suite numbers that are already booked from my $suites array. To get the booked suites, I would do the following query.

$query = mysql_query("SELECT suite FROM gsdays WHERE date='2007-03-24'");
$row = mysql_fetch_assoc($query);

$booked_suites = $row['suite'];

so basically what I want to do is remove $booked_suites from $suites. I tried using array_splice but I don't know what I'm doing.

View Replies !
Random Element From An Array
seems simple enough, but not as much as rand($ARRAY); how would i select a random element from an array?

ie $User_Prize = rand($Users);

View Replies !
Sort 2D Array (by Value Of Second Element)
I was looking forward to sorting an array by the value of the second element. e.g.: Sort by number of hits:

<?php
$webs = array (
   array("url" => "example.com", "name" => "example 1", "hits" => "5"),
   array("url" => "example.org", "name" => "example 2", "hits" => "20"),
   array("url" => "example.net", "name" => "example 3", "hits" => "10")
);
?>

View Replies !
Foreach Seems To Only Get Last Array Element
I'm probably doing something stupid that I just can't see (it is 3:30am here).

Here is the result of print_r($children):

Code:
Array
(
[0] => Array
(
[id] => 1380
[fname] => Mary
[lname] => Contrary
[status] => 1
[type] => 2
[email] => Mary.Contrary@nowhere.xxx
)

[1] => Array
(
[id] => 1378
[fname] => Jane
[lname] => Doe
[status] => 0
[type] => 2
[email] => Jane.Doe@nowhere.xxx
)

[2] => Array
(
[id] => 1379
[fname] => John
[lname] => Smith
[status] => 1
[type] => 1


View Replies !
Hide Array Element
I am just wondering how I can hide a directory from showing? I've been playing around with files and it doesn't show the "." and ".." for parent folders but I can't seem to make it hide the "admin" folder (which is in the folder "Folder"). I have tried using unset but without success. Code:

View Replies !
Using An Array Element And Substr
Hi, just new to the list, but couldn't find anything about this on google so I hope it's never been asked before.

I'm trying to write a function that takes a rather large (ASCII) string and splits it into distict sections. The input string is beyond my control since it will be read from a magnetic card (like a creditcard).

The string looks like this: ....

View Replies !
Making Third Element In Array =0
PHP Code:

Array ( [2005-08-21] => 20 [2005-08-22] => 20 [2005-08-23] => 20 [2005-08-24] => 20 [2005-08-25] => 20)

The above is my array, the day of each date is sun(21), mon(22), tue(23), weds(24), thurs(25). i use the code below which reports back the day of the week of each day. PHP Code:

$day = date('w', $dates);
output
0
1
2
3
4

what i want to do is somehow to make the third element in the array = 0 if the first two elements that falls on a day between 0 and 4 (sun and thurs) i.e if the days are 0,1,2,3 then 2 should = 0 or if the days are 3,4,5,6,0 then 0 should = 0.

View Replies !
Array Last Element Index
which array function gives the index of last element out?

View Replies !
How Do I Sort An Array By It's Second Element.
I've searched the forums and can't seem to find a solution to this. How do I sort an array by it's second element. For example, how do I sort this array with this general setup:

$player[0]['pts'] = 2;

so that the player with the most points (pts) is at the start of the array?

View Replies !
Maximum Element Of An Array
what is the maximum element of an array?

View Replies !
Return Every Other Element From An Array?
Anyone know how I can return every other element from an array?

For example:

$numbers = array(&#391;',&#392;',&#393;',&#394;',&#395;',&#396;');

I want to return:

&#391;', &#393;', &#395;'

I'm playing with array_splice, but I haven't figured it out yet.

View Replies !
Delete Element Of Array
I am trying to check if any of the elements in a certain array (which is to be inserted into a mysql table) are already listed in the table. For example I have an array containing multiple URL's, and I want to check whether any of these urls is already in my table. If it is i need to remove that particular element of the array. Can anyone point me in the right direction, i am currently trying array_search and in_array.

View Replies !
Removing Array Element
I have this array:

$array[0]["ID"] = 3;
$array[0]["name"] = "jan";
$array[1]["ID"] = 5;
$array[1]["name"] = "piet";
$array[2]["ID"] = 6;
$array[2]["name"] = "joris";

I want to search the array for "piet". If it finds "piet", then this is what my array should look like:

$array[0]["ID"] = 3;
$array[0]["name"] = "jan";
$array[1]["ID"] = 6;
$array[1]["name"] = "joris";

So it has to remove all of $array[1], then update the keys so there's no "gaps" in the array.

View Replies !
Removing Element From Array
i have an array and i want to remove an element from it. I've currently been using 'for' loops that will miss out the element i want to remove, for example: Code:

View Replies !
How To Add Element In Array Dynamically?
I want to add two element in a array. the first one is
the key and the second is the value.but I want to add it
dynamically. i want to do it like the following code:

$arr="";
for($i=0;$i<20;$i++) {

$arr[$i]=arr($i=>$i+1);

array_push($arr[$i]);

}

print_r($arr);

But of couse it don't work. Could anyone tell me how
to do it ?

View Replies !
Deleting An Array Element By Value
I've been trying to figure out how to delete a part of an array by its value... for example, if I have an array called $numbers with the values 1, 2, 2, and 3 (with arbitrary keys), how would I go about deleting one of the &#392;'s? I tried using the function:

array_diff( $numbers, array([&#392;'])

The problem is, this deletes ALL of the elements with the value &#392;' when I only want to delete one of them. Any ideas?

View Replies !
Using $ POST With An Array Element
$_POST['class[1]'] doesn't seem to work.

This works:

<input name="class[1]" type="text" value="<?PHP if(isset($class[1])) echo $class[1];?>">

This doesn't work:

<input name="class[1]" type="text" value="<?PHP if(isset($_POST["class[1]"])) echo $_POST["class[1]"];?>">

View Replies !
Deleting An Element In An Array
I have a value in a database that i seperate by commas and explode() into an array. Im trying to delete one element of the exploded array, implode() the array back into a string and update the database. Here is the code I tried.

$array[$id] ="";
implode(",",$array);

The problem is it still implodes the empy values back into the string. Is there an easy way to delete an element from an array without a for loop that shifts everything forward one?

View Replies !
Take The Entire Array And Apply The Htmlentities Function To Each Array Element
what I want to do is take the entire array and apply the htmlentities function to each array element. So here is what I am doing:

$result = $dbconn->query("select * from tablename");

while($case = fetch_array_html($result))

Here is the function:

function fetch_array_html($result)
{
$arr = mysql_fetch_array($result);
foreach($arr as $key=>$val)
{
$arr[$key] = htmlentities($val);
}
return $arr;
}

Here is the error I get: Warning: Invalid argument supplied for foreach() on line 129
What exactly am I doing wrong here? I can usually fix my own errors, but this one is dominating me.

View Replies !
Check If An Element Exist Within An Array
I thought there must be a simple function that checks if an element exist within an array. I can't find it anywhere... does anybody know?

View Replies !
How To Control Which Element Of An Array Is Printed
Anyone know how to control which element of an array is printed, say from 1-4 then 5-9 etc.

View Replies !
Removing Element From Array Using String
I am trying the following based on an example from php.net

<?php

$array_of_items = array ('A','B','C','D');
array_splice($array_of_items, 'B', 1);

foreach ($array_of_items as $array_of_items2)
{
Print $array_of_items2;}?>

I expect the result to be ACD, I am getting BCD, Not sure why.

View Replies !
Insert An Element In Numbered Array
I need to do the following:

Say I have a multidim array:

$array = array();

$array[0]['name'] = 'Kevin'
$array[0]['age'] = 23;

$array[1]['name'] = 'Julia'
$array[1]['age'] = 31;

$array[2]['name'] = 'Bob'
$array[2]['age'] = 26;

$array[3]['name'] = 'Drew'
$array[3]['age'] = 37;

and I have a seperate array:

$person = array();
$person['name'] = 'Dana'
$person['age'] = 33;

now I want to insert the $person array into the $array in such a way
that it ends up at index 1 and the subsequent elements get pushed up and
renumbered, so $array[1] becomes $array[2] and so on.

Does php have a built-in function that does this?

View Replies !
How To Add An Element To The Middle Of An Associative Array ?
I got an array that consists of elements that are arrays also. Now I
wish I could add an element to the middle of it. Let mi give you an
example:

array (
- array(1,15,apple),
- array(2,28,banana),
- array(3,41,orange)
}

I would like to add, let's say, carrot on 2nd position:

array (
- array(1,15,apple),
- array(2,57,carrot),
- array(3,28,banana),
- array(4,41,orange)
}

Array_splice() does not work (or maybe i use it in a wrong way? - it
splits an adding element for, in that case, 3 elements). Array_push()
adds only to the end of an array. can samobody tell me how to add and
element to the middle of an associative array?

View Replies !
Changing A Value Of An Element In A Two Dimensional Array
I am having a problem with array manipulation.

in my php script i am reading from a csv file.
the content of file is like this:

View Replies !
Removing An Element From The POST Array
I have a form that is posting it data to PHP_SELF. This then gets processed and does it's thing. My question is that when I hit the submit button, I get all the data from my form but I also get one item from the Submit button itself. Can I make the submit button not include itself in the POST?

Here is an example output of print_r($_POST)
Array
(
    [ACPlatSearch] => -1
    [ACDeedSearch] => -1
    [ACUserInfo] => -1
    [ACPropertySearch] => -1
    [ACStatsTotalSales] => -1
    [SavePermissions] => Save
)

The last element is the submit button, the other ones are checkboxes.  I don't want that last one.  So is there a simple way to not include it or do I need to loop through the array and remove it manually?  I need the rest of the array intact for further processing with array functions.

View Replies !
Update The Content Of An Element In My Array
foreach ($consumers as $key => $consumer) {
if ($consumer ['transstatus'] == 'OK') {
$consumers [$key] ['transstatus']= "Payment Successful";
}
}

I am trying to update the content of an element in my array above. The consumers array contains the data is created by an sqlquery.

View Replies !
Random Element From Associative Array
I've got an associative array named $pictures.
I've got there filenames for example: "picabc.jpg"

I want to randomize this array. Hmmm...
Maybe you will see, what I mean on example:

I wanna do something like:

drawOneOfElementsIntoVariable($picture);
echo("<img src="$picture" />");

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved