Arrays Working With MySQL
How can I grab a certain field of a Multi-Dimensional Array using the ID. I have set for that Array? I just want to be able to create a simple function to do pretty much what this function does, but for an array. Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Working With Arrays
I have a database with users, with unique ID and what I want to do is create users with random IDs, there's a tool for user creationg where you specify the range of posible ids (comonly 1000:9999) and the number of users you want to create (comonly 20). So, I build an array having this key/velue pairs: 1000=>1000 1001=>1001 1002=>1002 ... and then I get all the ids in the database from 1000 to 9999 and I remove them from the array, so I should end having something like (suposing there's a user with id 1001) 1000=>1000 1001=>1002 1002=>1003 I think for doing this, I would have to get the ids and one by one remove them from the array and then run a renumeric loop renumering all the values and then I randomize in the result and I'll always get free ids.
Help Passing Arrays - Serialize Not Working...
I found this example somewhere: <?php if( isset($ser1) ) { $arr1 = urldecode($ser1); $arr1 = unserialize($arr1); echo 'First four elements of array:' echo $arr1[0] . '<br>' . $arr1[1] . '<br>' . $arr1[2] . '<br>' . $arr1[3] . '<br>' } else { $arr[] = 'First' $arr[] = 2; $arr[] = 'Third' $arr[] = 4; $ser = serialize($arr); $ser = urlencode($ser); echo '<a href="' . $PHP_SELF . '?ser1=' . $ser . '">Pass</a>' } ?> It works fine. But my a href statement is something like this: echo '<a href="modules.php?op=modload&name=modname&file=index&req=dosomething&id1=1& id2=1&text=$ser">Pass</a>' I simply can not get this to work. It does not pass the serialized data correctly. If I look in the status bar, it will show text= a:4:{i:0;s: and then when I click the link it displays a:4:{i:0;s:5:"First";i:1;i:2;i:2;s:5:"Third";i:3;i:4;} How on earth do I do this?? Seems like it must be a syntax issue (i.e. my statement has all those &'s and the example does not).
Arrays In MySQL
Can I store an array into an SQL database and then take it back out and it would still be an array?
Arrays Into Mysql
The mysterious message: Couldn't add data to the CATLINK table:Unknown column 'Manufacturing' in 'field list' PHP Code:
MySQL Query And Arrays
I have a 'links' category on Table A and I want to retrieve the links from the Table and display them in a list-like fashion when the page is called upon. How would I go about seperating the links from one another (there a space inbetween each link.. EXAMPLE: http://asdf.com http://asdasd.com http://asdfff.com), loading them into an array (or using the best possible method to acces them easily) and then displaying them in a list like fashion..?
Arrays And MySQL Querys
I can't get an $array[key] to be used as a select query on a mySQL database. I have a 'parts list' which displays on a page (works fine) and is a form. At the end of each row is a input type='text' (quantity) cell with a default 0 The quantity can be altered. At the bottom of the table (form) is a submit to basket Button echo "<form action='basket.php' method='POST'>....
Arrays And While Mysql Functions
How can I get this array to work? I am trying to add data to an array for every row of data? This is a sellection of queries that I need to parse into an array so a function can use the arra to draw a graph. I am new to arrays how can I get this to work? Code:
Passing PHP Arrays To Mysql Best Solution
I am relatively new to PHP and until now I have only needed to use relatively simple php/mysql solutions. I am working on a problem where I need to store CD information (Artist Name, Album Name, Track Names, Catalog Number) I am working on a solution with two tables "album" and "tracks" and I am using the catalog number as a key to link the two. The problem I am having is coming up with the best way to populate the tracks table as there are several tracks for each release. I am assuming that an array would be the correct way and maybe a dynamic form to input the tracks where you decide the number you need to add and this then creates a form with "n" input boxes?
Insert Multiple Arrays Into Mysql
I am having problems writing the code to generate my SQL INSERT query. I have 3 arrays and one static variable ($cat_number): $track_name[] $music_link[] $track_number[] $cat_number Should I be using a foreach command. I know how to insert multiple values but its generating the query that i'm not sure about. INSERT INTO table (track_name, music_link, cat_number, track_number) VALUES (var1,var2,var3,var4), (var5,var6,var7,var8), (var9,var10,var11,var12); I don't want to store the actual array in the dataabase, I am just using an array to catch the data.
Multiple Selections, Arrays, And MySQL
OK this place has been great with explaining things that are way over my head, now I could use a boost to get my brain working again. I have a form with a drop down menu with multiple selections. When the form is submitted it shows up in the DB field as "array", as well as the page where I how the form's info. I think I have to set up an array, and loop(?) it, or do I need to implode the array? And how and where would I put these commands on this incredible messy form page. Would someone mind helping me get started? Here's the form: (please don't make fun of me, I used to a Dreamweaver extension to create the form using PHP, before I decided to try and write this stuff myself. I am re-doing the form but this actually works for now, so I am using it. Code:
Sorting Arrays Retrieved From A MySQL Db
I am trying to make a news system. I have done it, but the news are listed with the last on at the bottom. This makes it kind of troublesome to read the latest news when you enter the site and there are a lot of news items, cause you would have to scroll down. PHP Code:
Populating Arrays From MySQL Query
I have the following code: http://pastebin.com/746601 The field 'material' in 'is_material' contains multiple values for each record in 'is_details'. Because of this I have used 'is_material_lookup' as a reference lookup table containing the 'style_code' and 'material_code' which refer to their full details in the respective tables. Currently I have got the script outputting all the details and one material then in the next block of data, repeating the details with a different material. What I would like to achieve is having 1 block of data with a list of all materials in that, instead of the repeat, but sadly I can't know exactly how to do it.
How To Insert Arrays Into Mysql Database
This is my order.php file. Now I try to make a new php-file for processing the ordered items on this page, into another table "ordered_products" in the database. I want to INPUT following values into the table "ordered_products": 'order_num', 'order_item' and 'order_ant' I know how to insert rows in a table using the INSERT query, but I don't know how to do it while looping the arrays. I have to fetch the arrays from this page, and insert them row by row in the "ordered_products" table. Code:
Using Arrays With Mysql Query Results
im currently in the process of making a piece of code that will firstly take all the data from a table in mysql and then assign it to an array. This data will consist of several different rows of data each with different infomation for each field in the table. i want to be able to use an array in a loop so that depending on which number of the loop is on will change the infomation that is assigned to a certain array. Code:
Merging 2 Mysql Resultant Arrays
im currently executing sql queries on two seperate mysql servers. i take back each of these results into individual tables to display them. What i wanted to do was perform a merge of the two arrays, so that i could order the results by my "TimeStamp" field. When i try to perform a basic " $mergedresult = array_merge($result, $isaresult); " i get the following. " Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164 Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:Program Filesxampplitehtdocsseatpub.php on line 164 " Im rather new to this and so havent delt with arrays before, but im under the impression my results from the sql queries, are Assoc arrays. can these be merged ? do i need to use an alternate php function ?
MySQL Not Working For PHP 5
I have a fresh install of MySQL and PHP 5 but PHP is saying that the mysql_connect isnt there...does anyone know how to fix this?
Working With Mysql
I have installed php on my server and can get the phpinfo page to display. I have installed mysql 5 and I'm able to get into the database and create data. I would like to be able to get php to pull the data. I have been reading on the internet as to what I need to do in php and have created a couple of pages. When I go to the page all I get is a blank screen - no data from the database. I edited my php.ini file to allow for mysql. I copied libmysql.dll to my c:windowssystem32 directory. Is there anything else that I need to do to make mysql and php work together?
MySQL Results Not Working So Hot
Ok. Here I am again....probably posing a question with a solution so easy that, after looking at it for an hour, I can't figure out. Ok. here's the deal. please review the code below. Looks simple enough, right?
MySql Session Not Working
This is my first time using php and sessions. I am trying to follow what I recently read, but it isn't working as I was expecting. Please tell me what I'm doing wrong? I have defined my session handlers in a session handler include file, sessions.php. This file calls session_set_save_handler() and also calls session_start(). Each handler function operates correctly when I login - the data is put into the session table. After successful login, the user is redirected to /path/index.php, which includes sessions.php. session_start() is called again, but the $_SESSION global has no data. I know the individual pieces of code are working properly, because at one point in the process they individually worked. But when I put it all together, it just keeps going back to the login page.
MySQL 'update' Not Working..
I'm setting up a website on which you have to pay for membership. I allow the user to register with an 'elec' field in the database as '0'. The 'elec' field is '0' when they haven't paid and '1' when they have. I've tested it and the login/register scripts work fine but i cant get it to change 'elec' to '1'. I use a separate script to buy elec, as shown below. Code:
Mysql Check Not Working?
The login and everything used to work until I moved these down from above the header. I moved them below the header so that the error messages (if any while logging in) will be displayed within the body rather than at the top of the page where they're hard to be seen. Code:
MySQL Connect Not Working
mysql_connect("localhost","---myUsername---","---myPassword---");And yet, it won't let me connect and gives me errors. I don't think it's my username or password that is messing this up, I think it might be the localhost part. I don't know which port to use, or what to put there. So, I would appreciate it if somebody could tell me how to find out what to put, or what to put. Also, I am using PHPMyAdmin, so if this does not work with mysql queries then please tell me and I will try to figure out how to download a new MySQL database.
Pesky Checkbox Arrays And A MySQL Song Database
I'm not one who likes to ask for help, so for the last three days my brain has been turning to mush while I try to create a DJ Request Song Wish List. Anyone who can help me out will be saving me from severe insanity. :) My goal is to: 1. Display search results for song title, artist and genre. (accomplished) 2. Allow the user to add songs to their Wish List. This is done by displaying checkboxes with the corresponding value equal to the songID. (working on it) 3. Allow the user to update their wishlist by adding/deleting songs. So far I have a form that retrieves the song info from a database in a repeating region. In Dreamweaver: <input name="songID[]" type="checkbox" id="songID[]" value="<b><?php echo $row_RecordsetSearchResults['Title'];?></b> by <?php echo $row_RecordsetSearchResults['Artist'];?>"> This puts the corresponding songID number into a checkbox value, which in turn is submitted by form POST action to the following page as an array. To process this array I have: if(isset($_POST['songID'])) { $songID = $_POST['songID']; print '<p>Song IDs:</p>' // process items $n = count($songID); for($i = 0; $i <= $n; $i++) { //See if the values are being passed from POST echo $songID[$i]; echo '<br>' } $songsInsert = '*'.implode('*',$_POST['songID']).'<br>' $insertSQL = sprintf("INSERT INTO wishlist (Username, Title) VALUES (%s, %s)", GetSQLValueString($MM_Username, "text"), GetSQLValueString($songsInsert, "text")); mysql_select_db($database_ToneDeaf, $ToneDeaf); $Result1 = mysql_query($insertSQL, $ToneDeaf) or die(mysql_error()); } The problem is, I'm using implode. It does store the songs, but only as one long block of text. So if the user picks "New York by Frank Sinatra" and "Hot In Here by Nelly" it is stored as "*New York by Frank Sinatra*Hot In Here by Nelly*" Obviously this gives me no options to make this actually readable, let alone allow the user to remove one of those songs from their list (both would be have to be removed.) Also, referencing only the songID number as stored in the music database doesn't seem a good option, since the song database will be changing frequently and song data may be overwritten. Not sure if there's a viable workaround there. Originally I wanted to store Title, Artist, Genre under seperate columns so I could link them to something like "See more songs from this Artist." However the more I read about arrays and multidimensional arrays, I realize I'm not ready to go there yet. (I just started learning PHP two weeks ago.)
Image From MySQL Database Not Working
<?php include 'dbinc.php' $result = mysql_query("SELECT image,mime_type FROM photos WHERE image_id=".intval($_GET['id']), $link) or die("MyErr:".mysql_error()); if ($row = mysql_fetch_assoc($result)) { $ext=array('image/jpeg'=>'jpg','image/gif'=>'gif','image/png'=>'png','image/x-png'=>'png'); header("Expires: Mon, 26 Jul 2030 05:00:00 GMT"); header("Content-Type: $row[mime_type]"); header("Content-Disposition: inline; $_GET[id].".$ext[$row['mime_type']]); echo " ".stripslashes($row['image']); } mysql_free_result($result); ?> what am I doing wrong? I don't get an image. I've seen thumbnail stuff. I don't want a thumbnail (that code didn't work either for some reason).
Comparing Values Of 2 Arrays Combined With Mysql Field Names
I am trying to create an edithistory table that has a text column into which I will put a string that can be read using strtok later to revert changes if necessary. I want to build this function so that it's dynamic enough to be applied to every table so that I don't have to write one for each table that might be updated. When a row is added to any table (a new entry), it retrieves the next available editid # from the edithistory table and assigns it to that item in the "edits" column for its row in its own table. Every edit made is a new entry in the edithistory table (entryid auto_increment primary key), and the editid is a reference back to the object being edited. Code:
Working Combination Of PHP5, MySQL And OpenSSL
I'm trying to compile php 5.2.0 under FreeBSD 6. If I use the version of OpenSSL that came installed with FreeBSD (0.97a) then it builds okay and then segfaults on make install when it gets to installing pear. I tried building with the latest OpenSSL and that causes make to fail with an error about libmysql.a !! The reason I am building with OpenSSL is because I need to access secure sites (https://) via HTTP_Client and cURL. Without it cURL segfaults when I attempt to access a secure site, and HTTP_Client returns "Malformed response". Does anyone know of a combination of MySQL, PHP5, and OpenSSL that builds, installs, and functions correctly ?
Checking For Values In MySQL And Other Conditions Not Working?
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? And then sometimes when the conditions are correct, it doens't redirect. It appears to be very inconsistent. //Check for repeat name $result = mysql_query("SELECT * FROM survey WHERE FirstName = '".$FirstName."' AND LastName = '".$LastName."' "); $num_rows = mysql_num_rows($result); if($num_rows > 0){header("location: ./oops.htm");}; //Check for repeat email $result = mysql_query("SELECT * FROM survey WHERE EmailAddress = '".$EmailAddress."' "); $num_rows = mysql_num_rows($result); if($num_rows > 0){header("location: ./oops.htm");}; //Check for existance of first name, last name, and email if(!$FirstName){header("location: ./oops.htm");}; if(!$LastName){header("location: ./oops.htm");}; if(!$EmailAddress){header("location: ./oops.htm");}; $newrecord = ("INSERT INTO survey (FirstName) values ($'Joe')"); $result=mysql_query($newrecord);
Working With Substr To Get Paraphrased Data From MySQL
I have created a small PHP script that pulls the last 5 posts subject line from my message board and displays them on the main page of my site. The message board is made by WBB and the data is stored in a mySQL database. What I would like to do is limit the amount of characters displayed on the main page to 20 per subject line. I have tried many ways by using the substr call, put I'm not having any success. Can anyone point me in the right direction as to where the substr call should be living in my script, and how it should be used? Code:
Connection To Mysql Working In Eclipse But Not On Apache?
I have installed apache, php5 and mysql on my laptop. I write my code in eclipse and when I test it inside eclipse, the mysql database connection is working, I can execute the script inside eclipse. But when I put that same script into my htdocs on the apache server running on the same laptop and access it using my browser, I get a "Call to undefined function mysql_connect()" error message.
PEAR DB Not Working With Recently Upgraded MySQL 4.1
I recently upgraded from MySQL 3.23 to 4.1. Now db is not working properly. I'd very much like your help in solving this issue! Here's the code I used to test it: require_once 'DB.php' $db =& DB::connect('mysql://user:password@localhost/dbname'); if (PEAR::isError($db)) { die($db->getMessage()); } $res =& $db->query('SELECT * FROM table'); if (PEAR::isError($res)) { die($res->getMessage()); } The error message I get: DB Error: insufficient permissions I have this username in MySQL 4.1 set up in mysq.user in the old style (pre MySQL 4.1) password. This user has no right in the user table and SELECT rights in the db table for this dbname. This is the way it always worked in the past. This is different, I think, from my previous post about php not working with MySQL 4.12 because I have that working now - php4.4.4 is workingon my machine with MySQL 4.1 yet Pear DB is not. I verified the password by UPDATE setting it using OLD_PASSWORD() and flushing privileges.
UPDATE Command Is Not Working On MySQL, Windows 2000 Server
Hi all, I encountered mysterious problem with MySQL and PHP. UPDATE command is not working on MySQL configured on Apache 2 with Windows 2000 Server. It pulled my hairs for atleast 5 hours. MySQL says Affected rows: 0 (Query took ~ sec) always? Now, I've decided to move all PHP files and db to remote server. Can anyone suggest possible reasons for above errors?
Arrays Within Arrays, How To Split
I have been stumped on this one and it is probably easier than I think it is, especially since my brain is fried. This is what my array looks like: array(7) { ["injuredPerson"]=> string(0) "" ["dates"]=> string(0) "" ["describe"]=> string(0) "" ["location"]=> string(0) "" ["type"]=> array(3) { [0]=> string(8) "abrasion" [1]=> string(10) "amputation" [2]=> string(12) "asphyxiation" } ["part"]=> string(0) "" ["times"]=> string(0) "" } This is actually an array of information from a form check. I have the error handling check the form and depending on if there is an error or not, the array gets populated with "" or an actual value(s). I am testing a checkbox area of the form (the name is type, so type can hold an array of values, thats why it currently contains abrasion, amputation, and asphyxiation). I have had no problem going through the array until I get to the area with an array within the array. Let me give you some code so you can see how I am doing this:
Searching Arrays With Arrays
ive looked through alot of the array search functions and i dont think any of them support arrays as the "needle" to search for. so say i had a numeric array, $array1 with say 5 elements, 0-4, each element is a single word, lowercase. say i had another numeric array structured the same way called $array2 with say about 5 elements, 0-4. Is there a function which i could use or does anyone know of an easy way to search every element in $array1 and compair it through each of the elements of $array2? and if a duplicate is found in $array2 have that element be removed or unset? im sure this can be done probably easy with some kind of loop function, but thats my weak point right now in php and im working on it.
Sessions Working, Then Not Working?
I wrote a login script (one that I have used on quite a few sites previously) and have found that it was working, then not working, then working again now not working - all without me changing any code. Here is the process: 1) l/p gets sent to login.php to query the db 2) if login successful, set $sid = session_id, and other session variables, register them in the session, and redirect to main.php 3) first thing on main.php is check_login function, all this does is see if $sid is set and equal to the current session_id(). If succeed continue to display data on main.php based on registered user data. If fail, redirect to error.php with the appropriate error code. this all takes place on a shared ssl server if that matters. The trouble I'm having is the check_login function is failing because no session variables are present, including $sid. I'm 99.9 percent certain it's not a code issue because 1) I have done this same script many times before with no trouble, and 2) this particular one was working before So I am really looking for php configuration issues to check on, or things like that.
Add To Arrays
this is the situation. i am passing variable thru an input form to a function on the same page. within that function, it will determine if the checkboxes are checked, if it is checked, add that value to one array. if it is not checked, add to a different array. i do not know the line to add to an array. i am trying array_push but that is not working. array_fill will not work either (do not have php 4.20 installed)
Different Arrays, How To Tell Them Apart?
Is there a function or way to tell the difference between these two types of arrays: array(1,2,3,4,5,6,7,8,9,0); array(1=>"one", 2=>"two", 3=>"three", 4=>"four"); The is_array() function does not distinguish between the two as they are both arrays and is_array looks to see if its an array, so back to step 1. Anyways, is there a function or workaround to find this out??
Arrays
Is there any way that after filling the array in a loop with values that i can go back and start filling in the same array from scratch with a different set of values.
Arrays
is it possible to have an array (or the equivalent) that allows you to say like $text['hi']; or $text['this'];?
PHP 2D Arrays
Please how do we create 2D array and make it global in PHP.
PHP And Arrays?
How can one tell if a PHP array is a simple array or a hashed array (key/valye). The gettype returns "array", but is there a function that will tell me the type? Also, when you have a mixed array, some flat, some hashed, how can you tell the type of each element?
Using Arrays For Look-ups
Just a quick sanity check... Sometimes it's useful to use an array as a kind of reverse lookup. For example, the indexes being productIDs and the value being it's name. If I do something like this... $x = array(); $x[1] = 'foo' $x[345] = 'foo' $x[12345] = 'foo' .... PHP is intelligent enough only to allocate 3 data chunks for this right? As I type this, it seems far more obvious, but if someone could just confirm :-)
WHILE And Arrays
I appear to have the logic on this one worked out(maybe) but when it goes through the while loop, it only echos the first element of the associated array. Now as a Test I echoed what it should be using as the keys and that works fine. So I don't understand why its failing. With out further ado, heres the problem.. So I have this string in the database, lets say that this string is... PHP Code:
Two Arrays As One
How do I convert the following two arrays into one, and loop through it? Code: $sections = array("Articles", "Bio", "Disc", "Home", "Photos"); $table_ref = array("articles", "biography", "discography", "homepage", "photos"); for ($i = 0; $i < 5; $i++) { if ($section == $sections[$i]) { $result = mysql_query("SELECT * FROM $table_ref$i] WHERE artist_name LIKE '$artist_name' ORDER BY artist_name", $db) or die("<font size="4"><b>Error =(</b></font><br><br>Unable to connect to database. Please try again later."); echo create_page($artist_name, $sections[$i], $result);}}
Arrays
when i submit this form, how can i do similar type of processing for all of them, like the first one i want to add to database, or any other processing maybe not related to database, also .. i can do also for the rest, rather than repeating my codes again and again, i know some sort of array.. but.. how Code:
How To Use Arrays
I want to assign some values from a database into an array. I have two fields, id & name. When I am finding the values from the database, I would like to assign the id to an array and the name into another array. I can do this using the array_push() . How can I then print the array? I tried to just print the variable but it give me 'Array'. Maybe a loop? PHP Code:
Arrays
I have problems in trying to '++' an array value. Every time I find a city I add it in the array, and if I find it many times I increment the value (counter) of the city. Here's the code: $address = "http://www.cji.co.il/bw040609.txt"; $address_local = "bw040609.txt"; $lines = file($address_local); $heading = "Companies covered in this CJI report:"; $heading_line = 0; $towns = array(); for($i=0; $i<count($lines); $i++) { $pos = strpos($lines[$i], "Location: "); if($pos !== false) { list($loc,$town) = preg_split("/: /", $lines[$i]); if(in_array($town, $towns)) { $towns[$town] = 1; echo "Town added: $town<br>"; } else { $towns[$town]++; echo "Town added: $town<br>"; } } } foreach($towns as $key => $value) { print "$key => $value<br>"; } The output is like this:
|