Select Single Column From Mysql Into Array
Is there a way to select a single column from a mysql database and
directly put the results into an arrray? Here is the workaround below,
but I would like to elimniate the array_push step:
$uids=array();
$res = mysql_db_query("db", 'select uid from tbl;', $link);
while ($row = mysql_fetch_row($res)) {
array_push ($uids, $row[0]);
}
View Complete Forum Thread with Replies
Related Forum Messages:
Search For Keywords In A Single MySQL Column
I am looking for a quick and easy way to take user entered keywords in a search field and search through a field in my MySQL table for matching words. I will have a field in the database called "Keywords" and they will be separated by commas. I know I can use: $search_array = explode(" ",$searchwords); to parse their submitted search terms into individual words, and $keywords_array = explode(",",$keywords); to break out the database field into individual words as well. I just cant think of the easiest way to compare here. Am I on the right track or have I lost my mind?
View Replies !
Single Mysql Select
I have a simple array named j12stuff that is a list of words. Can I use one mysql query to select all words from a table that matches the words in the array that are nouns? The point is to use mysql to reduce the array list to nouns only.
View Replies !
Combining 2 Fields In A Single Mysql Select Query
i want to combine 2 fields in a single select query fields. pageheader name values. abcd <div id="d"></div> i want to merge/combine the pageheader and name in a single select query so that it can retrieve the pageheader with some styles which i have stored in another table.
View Replies !
Loading A MySQL Column Into An Array
ok i have a forum i am creating and i store the id of the forums where people are moderators in their userinfo. i speperate them with a comma. i need to either load them into an array or use explode() but i'm not sure how to create the array. i'm thinking that using an array would be faster because i could search in it to find out if the user is a mod.
View Replies !
MySQL, Turn Column Into Array
Today is the first time I've used MySQL with PHP. What is the best way to turn a column into an array? This is how I am doing it at the moment, surely this is sub-optimal: $query = 'SELECT something FROM table' $result = mysql_query( $query ); $i = 0; while( $arrayTemp = mysql_fetch_array( $result ) ) { $array[ $i++ ] = $arrayTemp[ 0 ]; } echo "<ul>"; foreach( $array as $string ) { echo "<li>$string</li>"; } echo "</ul>";
View Replies !
Displaying Single Row For Same Column No
I have a table as follows: ---------------------------- Auth Name | Paper No ----------------------------- Gupta 7 Daiya 7 Daiya 8 I want the above table to look like if two rows have the same paper no ----------------------------------------- Auth Name | Paper No | Paper No ------------------------------------------- Gupta 7 Daiya 7 8 Can you please modify the below code: if ($result){ echo "<table border=1>"; echo "<tr><td><b>Author Name</b></td><td> <b>Paper No</b></td></tr>"; $numOfRows = mysql_num_rows ($result); for ($i = 0; $i < $numOfRows; $i++){ $name = mysql_result ($result, $i, "aname"); $email = mysql_result ($result, $i, "apno"); echo "<tr><td>$name</td><td><a href="abstract/$name.pdf">$email</a></td></tr>";} echo "</table>";}
View Replies !
Total Of Values In A Single Column
I'm trying to retrieve the total of all values in a specific column. I know that I can use some version of "SELECT SUM" to gather the info, but I can't figure out how to convert it to a variable. Here's what I have so far: <?php $scoreTotQuery = "SELECT SUM(score) FROM pc_complete"; $scoreTotResult = mysql_query($scoreTotQuery); ?> I want to be able to retrieve the total of all scores that have been recorded, so that I can display the average score.
View Replies !
MySQL Select From Array
I have two DBs, one is of dealerships and one is a zip code DB. I'm using ZipCodesRange.class from phpclasses.org Example: include("ZipCodesRange.class.php"); //initialization, pass in DB connection, from zip code, distance in miles. $zip = new ZipCodesRange($db,�',50); //do the work $zip->setZipCodesInRange(); //call to initialize zip array //zip code output, other processing can be done from this array. $zipArray = $zip->getZipCodesInRange(); It returns an array of zip codes and distances ($zipArray, $zipArray[0] = Zip, $zipArray[1] = Distance). What I'm trying to do is SELECT dealerships from the DB of dealership within the returned zip codes. But how do I SELECT from an array? Ideally, I would want to select dealerships from a given radius of a zip code and show the distance without using lat/lon.
View Replies !
How To Add Multiple Select From Array To MySQL?
For the last couple of weeks I've been absolutely stuck on inserting multiple select array (medewerker_voornaam[]) values from the field voornaam in table medewerker (employee) into the table software as medewerker_voornaam. I don't get any error message but the values are just not inserted into the database. I've searched just about the whole forum but still got no clue. All the other field values are inserted perfectly except the field medewerker_voornaam upon pressing the submit button. What could be the cause? I suspect that there might be something wrong with _POST not sending the array values to $medewerker_voornaam. Please ignore the names given to the field values in the tables or the code itself (Dutch). Code:
View Replies !
Clauses In A Single Select
I'm not able to figure out how I should change it and would appreciate some guidance. PHP Code: $sql = "SELECT `Enq`.* FROM `Enq` LEFT JOIN `Budget` ON `Enq`.Enquiryid=`Budget`.Enquiryid WHERE `Budget`.Enquiryid IS NULL AND ONÂ Â `Enq`.Visitid =`Budget`.Visitid WHERE `Budget`.Visitid IS NULL // syntactically wrong AND ( (`Enq`.`Visitid`= Ɔ' || `Enq`.`Visitid` IS NULL) ANDÂ Â `Enq`.Category!= 'D' AND `Enq`.Category!= 'A' ). if the field Visitid has a value in Enq but does not appear in a record in Budget, it should get selected. all other records in Enq where Visitid is 0 or null should also get selected. This is because, there are records in Budget with value in the Visitid field that correspond to a value in Enq and those should not be selected.
View Replies !
Changing From Single To Multiple Select
I have a poll script that I am in desperate need to let the users have more then one choice to the poll when they are voting...here is the original code below all i know is i have to change the type from radio to checkbox.. but other then that i'm totally lost, can anyone please give me the exact code i would need to change this I am still a real newbie as far as this stuff goes.. Code:
View Replies !
Select Max Column
I have a categories column and a title column in one table. What I'm trying to do is select the most frequently listed title for each category. I would think that this sql statement would do, but it just returns every column. select count(title) from table where title IN (select title from table where category = 'category'); To me the inner select should select every title that has a category = 'category'. Then the outside select should display a count of each title that has that one category listed in the inner select.
View Replies !
Mix Two Tables In A Single SELECT Statement - Not A Join
I have an Intranet with the organisation I work with. In this organisation there are two departments - community department and press office. Both the community department and press office have thier own news system where they can add news in their own admin section that will appear on their homepages. Both admin section have their own DB table thus two seperate tables. I would like to select all the rows from both tables in a single SELECT statement so when I output them they will be integrated. This is not the same as a table join as their are no keys and I want the rows from both to remain seperate. Can this be done? Could someone please post an example SQL statement demonstrating this if so?
View Replies !
Putting Zero In Front Of Single Digits In Select
I have an html form where a person inputs a date via a drop down select. How do I make php put a zero in front of the numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making the value="01" etc. but this doesn't work. Below is a snippet of my form and the code I am using to write to the file. Code:
View Replies !
Combine 2 Fields In A Single Select Query
i want to combine 2 fields in a single select query fields. pageheader name values. abcd <div id="d"></div> i want to merge/combine the pageheader and name in a single select query so that it can retrieve the pageheader with some styles which i have stored in another table.
View Replies !
Select Variable Column
Trying to select a column that is variable $leg1=week.$week._leg1; $rowh = mysql_fetch_object($query5); print "$rowh->$leg1"; Basically trying to print out a column where the column name (week1_leg1) will increment through a loop.
View Replies !
Select A Column Data
i want select the data in the first column of a row while i clicking a button in the same row. Table has many rows. if i click button in the third row i need to select the data in the first column of the third row Likewise i need to select the data on clicking the button. How can i do this. Now i tried a code. but it ill select the data in the first column of the last row. Code:
View Replies !
SELECT * FROM Table WHERE Column IS NOT NULL
I am running the following MySQL query: <?php $sql = mysql_query("SELECT * FROM comics WHERE story_arc IS NOT NULL") or die (mysql_error()); while($row = mysql_fetch_assoc($sql)) { echo $row['title']; } ?> The problem is that it is outputting all 4000+ records, when it should only be about 100. Is there an error with my 'IS NOT NULL'?
View Replies !
SELECT From 2 Differerent Tables, Only From 1 If A Column = -1
I have a Web page which must read data contained in a table called "operateurs" (operators in English). It has the following columns: id, Surnom (nickname), id_Usager (user id) If an operator has a user id, id_Usager contains it, but if he/she doesn't have one, it is set to -1. At the moment, when I extract data from the table, if id_Usager is different from -1, I read the operator's nickname from the usagers (users) table. Code:
View Replies !
Use The SELECT DISTINCT Command And Still Rename A Column
I am useing the query below can someone please tell me how i can use the SELECT DISTINCT command and still rename a column ie "label.id AS lid" but exculde this from the SELECT DISTINCT. "SELECT DISTINCT label, labels.id AS lid FROM labels INNER JOIN titles ON titles.label_id = labels.id WHERE titles.export = 1 ORDER BY label".
View Replies !
INSERT/SELECT With Differing Column Count
I just need a little help with an INSERT statement. I have 2 tables, one for confirmed users and one for temporary. I'm using an INSERT query to transfer data between the 2 once a user validates their registration by Email: Code:
View Replies !
Select From Drop List To Fill Table Column With Text -- HOW ?
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have a separate htm page with the text for each state -- california.htm for example. When the viewer selects California from the drop down list, the column below would "fill" with California.htm. Or, I could conceivably use a text or mysql database with two fields for each record: state_name and law_text -- but it would probably be easier to use separate htm files, since there will only be about 20 states involved, and the "database" would never have a large number of records. The table width would be 100% and each cell would be @33% My site is designed with FP 2002 and runs on Apache/FreeBSD. I have just had Apache-ASP installed but I have not yet configured or used the module.
View Replies !
Single Array To Multidimensional
I have a string, comma separated, with links and their respective URLs in it. Example: Google,http://www.google.com,Yahoo!,http://www.yahoo.com,WikiPedia,http://www.wikipedia.org etc, etc. i make an array of this with explode( ',', $string ); now what i wonder is how can i turn this array into something like this: $array[0]['name'] = Google $array[0]['url'] = http://www.google.com $array[1]['name'] = Yahoo! $array[1]['url'] = http://www.yahoo.com $array[2]['name'] = WikiPedia $array[2]['url'] = http://www.wikipedia.org I hope/think this is all clear ...
View Replies !
Some Arrays From A Single Array
I would like to fill up some arrays taking the values from another array in this way: these are the arrays: $name $surname $age $country $job $notes $allvalues I would like to do this simple thing: $name[0] = $allvalues[0] $surname[0] = $allvalues[1] ... $name[1] = $allvalues[6] ...
View Replies !
Removing A Single Value From $_SESSION Array.
What I have here is three select boxes one for all the tables in the db, one listing the table columns in that table and a third to collect the table columns selected stored in a session called $_SESSION['collections']. Up to this point all that works beautiful the session stores the selected collections. But heres what I want to be able to do: I want to remove single values from the $_SESSION['collections']. How do I do that? Code:
View Replies !
Get A Single Value Of Array When Doing Print_rÂ
why do i get a single value of array when doing print_r the page contain more than 10,000 record . i dont understand as you can see everything is fine can you tell me the possible solution or error $qry = "SELECT * FROM categories "; $result=mysql_query($qry); $total = mysql_fetch_array($result); print_r($total);
View Replies !
Get Single Element From Multidimensional Array?
I'm a newb trying to get a specific value out of a multidimensional array in our shopping cart. Heres the var_export() of the array. I want to get this element from the array : ["amount"]=> string(3) "35%" in the ["Discount"], but all of my feeble attempts have failed. Code:
View Replies !
Mailparse_msg_get_structure Returning Single Valued Array
I am writing code to strip out and write key data to a database from incoming e-mail. I am using the mailparse functions to handle the incoming mail. My code pulls in the e-mail fine, but the array returned by the mailparse_msg_get_structure() only has one row. The entire contents of the /var/mail/$user file is being put into one row instead of it being broken apart into individual messages. Here is the code:
View Replies !
Deleting A Single Item From The Middle Of An Array?
I have an array that contain objects, I want to be able to test against the id of that object and remove it from the array. In it's simplest for I want to go from this: $people = array('Tom', 'Dick', 'Harriet', 'Brenda', 'Jo'); ...to this... $people = array('Tom', 'Dick', 'Brenda', 'Jo'); The fact that the items in the array are objects should not matter right? Plus I've already written my loops and conditionals to check which item i need to remove. function removeItem ( $item ) { $len = count ( $_SESSION['basket_arr'] ) ; if ( $len == 1 ) { emptyBasket ( ) ; } else { for ( $i = 0 ; $i < $len ; $i++ ) { if ( $item->id == $_SESSION['basket_arr'][$i]->id ) { //$_SESSION['basket_arr'][$i] must go } } }}
View Replies !
Unserialize A Single Array Element In A Constant?
I have a question about unserializing a single array element from a serialized array. Can this be done, or must I first unserialize the array, and then access the element? For example, given: $data = serialize(array(Ɗ.50',Ɔ.00',Ɔ.00')); Can I unserialize individual elements from $data, such as: $data_element = unserialize($data[2]); As it is now, PHP will generate a syntax error, forcing me instead to unserialize the entire array before accessing it: $new_data = unserialize($data); $data_element = $new_data[2]; NOTE the value in this is as it relates to CONSTANTS, where arrays must be serialized before define()'d as a constant.
View Replies !
Make All The Elements In A Array Into A Single Variable
I have an array which is generated by the result of an SQL query... What I am trying to do is take that array and insert it into a different table in a single field, so what I am trying to do is make all the elements in a array into a single variable I can use to insert into a field with each array element seperated by a comma. This would be easy if the array had the same amount of lines each time but it dosent, sometimes the array has 1 element sometimes it has 5....any ideas??
View Replies !
Need Column Names, Not The Array Key...
I am running a script that exports a MySQL table into an excel file. The problem I am having is the column (header) names are not showing up in the final .xls file. I instead get the key value 0, 1, 2, etc. Here is the section of the code that should write the actual names. I can't figure out what's wrong. It looks good to me. Am I missing something? Code:
View Replies !
PHP - Column Names In Array
see the code below <? $rsQry = mysql_query ("select * from tblCustomer"); $arrQry = mysql_fetch_row($rsQry); ?> Now if I try to fetch a Customer's Name from the "Customer_Name" column from the "tblCustomer" table with the following code then I dont get anything: <? echo $arrQry["Customer_Name"]; ?> Why?
View Replies !
How To Call A Column Instead Of Row In A Multidimensional Array
I have a 2-d array. I want to pass columns from the 2-d array to a file that will graph the columns. Let's say its called my2darray I can pass a row with something like my2darray[4] But I can't pass a specific column with my2darray[][4] Any help with the syntax or a link to the solution would be helpful. Do I have to use a loop to call a whole column?
View Replies !
Recursive Array From A Twin-column Table
I have a MySQL table with two columns: catagory and parent. Parent contains the parent catagory of the catagory. I need to query the db ONCE, assigning the info to an array, then create a recursive array parenting catagories and grouping accordingly.
View Replies !
Structure The Data In Column That Should Be Index Of Array
MySQL Table structure. ID name value 1 c01 abc 2 c01 def 3 c02 xyz Here i want to structure the data in such a way that name column should be index of array and values should be mapped to index for eg. Array( [1] => Array ( [c01] => array([0] => abc [1] => def [2] => Array ( [c02] => array([0] => xyz .
View Replies !
Assign Column Names As Array Keys
Want to create an array that has db column names for the key names and field values as the array values. Is there an easy way to do this? If not possible directly, is there a way in php/mysql to get a list of column names in a table such that I could use those values as the keys?
View Replies !
Single Mysql Query
i thought that everytime I call this function to makes a query to the database when i already have the results. So i modified the function to query only if the result ($row) doesn't exist.below is the code, like i said it still works but can anyone tell me if i am still querying the db each time i call the function? function State($db, $sel, $row){ ############################# if (!$row){ $db = new MYSQL(); $sql = "SELECT state FROM states ORDER BY state ASC"; $query = $db->Query($sql); } ############################## OpenSelect($sel); while ($row = $db->FetchRow($query)) { $state = ucwords($row[0]); echo "<option>$state</option>"; } CloseSelect(); return $row; }
View Replies !
Escaping Single Quotes For MySQL
here's my SQL statement: SELECT item_id, artist, title, format, type FROM music_main WHERE artist = 'Bleu Collar' AND title = 'Makin' The Rounds' PHP is telling me this is invalid. What PHP function would I use to escape the single quote in the title?
View Replies !
|