$result = $stmnt->fetchAll(); Returning Duplicate Keys For A Single Query
For some reason when I do a fetchall on a PDO query the array returned
has duplicated keys. see below.
View Complete Forum Thread with Replies
Sponsored Links:
Related Messages:
Query Not Returning First Result
I have a query that is returning the correct number of rows. However, when I try to print the rows out, it will not print the first row, but all after that. I can't figure out why it isn't printing out the first row, even though the query is returning the results. Here is my code below to print the results in a table: Any suggestions? while($row2 = mysql_fetch_array($result1)) { $affinity_name = $row2['affinity_name']; $affinity_detail = $row2['affinity_detail']; $affinity_no = $row2['affinity_name']; $track_id = $row2['id']; get_name($affinity_name); $affinity_details .=<<<EOD <tr> <td><a href="/m_t5.php?affinity_id=$affinity_no&q=$name">$name</a></td> <td>$affinity_detail</td> <td><a href="/delete_track.php?track_id=$track_id">Delete</a></td> </tr> EOD; }
View Replies !
View Related
Getting Data For Duplicate Keys In $_POST
I'm trying to process a form that I got from a JSP generated page. Basically, want to take out and process some of the data, and redirect the rest to a JSP page that will handle the rest. All works well, i traverse $_POST, writeout hidden input fields and autosubmit the form with a little javascript, a perfectly acceptable solution for our users. However, the data the JSP page sends contains one certain input with the same name a couple of times. Due to complicated reasons, I cannot change that name into a PHP-style array. PHP, however, throws all the values of those fields away except for the last one. Is there any way to retreive data from inputs with duplicate names? I know that with GET, I could just parse the query string myself, but sadly i need to use $_POST (the thing I'm processing in PHP is a file upload). I have no way of changing the input names themselves (and see no alternative other than pulling a lot of ugly javascript hacks in the JSP page to fake it all).
View Replies !
View Related
Foreach Is Returning Value Of First Key For All Keys
I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first key for all the keys. My code is shown below and the problem areas are marked with comments. In case you're wondering, this script is for generating sticky checkboxes that include an event handler. <form> <?php if (! is_array($like)) { $like = array(); } function make_checkbox_click ($name, $query, $options, $onClick) { foreach ($options as $value => $label) { printf('<label><input type="checkbox" name="%s[]" value="%s" ', $name, $value); # This is the instance of foreach that's not working correctly. # It's returning the value of the first key for all the keys. foreach ($onClick as $key => $event) { printf ('onClick="%s" ', $event); } if (in_array($value, $query)) { echo "checked "; } echo "/> $label</label><br /> "; } } # End of user defined function. $characteristics = array( 'personality' => ' I love their personalities.', 'minds' => ' I admire their minds.', ); # This is the array that foreach isn't working correctly with. $charClick = array ( 'personality' => "alert('Aren't they the greatest?');", 'minds' => "alert('They're smarter than most people their age.');", ); make_checkbox_click (posPoints, $posPoints, $characteristics, $charClick); ?> </form>
View Replies !
View Related
Returning Field Results But No Duplicate Entries
I have a large MySql database full of addresses of clients. I am trying to use php to retrieve and display a list of all the countries that my clients exist in. Which I can do: -------- $sql = "SELECT * from Sheet1" ; $qry=mysql_query($sql); while ($result= mysql_fetch_array($qry)) { echo "".$result[11]."<br>"; } -------- However you can see the problem is this returns EVERY clients country so I end up with a list of duplicate countries. I would like to display the list of countries but not repeat any countries in the list.
View Replies !
View Related
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 !
View Related
One Result Set Makes Two Lists With Same Keys And Values
I have a page with two drop-downs, each listing the same employee names and their id's as the values. So they look like: <select name="selection_1"> <option value="12">Curly</option> <option value="8">Larry</option> <option value="36">Moe</option> </select> ....then further down the page: <select name="selection_2"> <option value="12">Curly</option> <option value="8">Larry</option> <option value="36">Moe</option> </select> Currently I am doing this, which works but seems sloppy: <select name="selection_1"> <? while($employees=mysql_fetch_assoc($qry_rslt)) { /* ADD NAMES TO DROPDOWN WITH emp_id's AS THEIR VALUES */ ?><option value="<?=$employees['emp_id']?>"><?=$employees['name']?></option><? /* CREATE ANOTHER ARRAY WITH THE emp_id AS THE KEY */ $emp_list_2[$employees['emp_id']]=$employees['name']; } ?> </select> Then on the second drop-down: <select name="selection_2"> <? foreach($emp_list_2 as $key => $emps) { ?> <option value="<?=$key?>"><?=$emps?></option> <? } ?> </select>
View Replies !
View Related
Returning 1 Result From MySQL
I know the usual way of receiving results from MySQL, useing a while loop e.g. $sql = "SELECT * FROM users WHERE email='joe@hotmail.com'"; $result = mysql_query($sql,$connection); while ($row = mysql_fetch_array($result)){ echo $row["firstname"]; echo $row["lastname"]; echo $row["email"];} BUT, if I know they only 1 result is going to be returned, is there a way to do this without using a while loop? So if I only wanted to get only the firstname of the person with email joe@hotmail.com. can I do this without a while loop or do I have to use one?
View Replies !
View Related
NO Error - But Returning No Result
Basically I have two tables, one for news, and one for results. I am doing a SELECT * FROM `news` AS t1, `news_comments` AS t2 WHERE t1.id = t2.newsid ORDER BY t1.date DESC, t1.id DESC, t2.com_datetime DESC query, and to start off with I already had comments I had inserted manually, it worked PERFECTLY! That was until of course, I deleted all of the comments, then I get absolutely no result from this query. Is there any way to get round this, where it still returns results even if there are no comments.
View Replies !
View Related
Script Not Returning Correct Numerical Result
I am working on a script to calculate returns on bets. This involves entering odds, stake etc. The problem I am having is with adding a new element into the calculation. In betting their is something called a Rule 4. This occurs in some races and diminsihes the retrun but there is no need to go into details. Basically, here is how it works: There is a race with odds of 2/1 and a rule 4 of 20 cents is in place. With the betting rules this means that the odds must be multiplied by 1 - rule 4. In this case the rule 4 is .20 so 1 - .20 = .80 You now have to mulpiply the odds by .80 We only multiply the first number os in the case that is 2 (for a 5/1 bet it would be 5 etc) .80 * 2 = 1.6 is the correct answer. This calculates ok in part of my script but when it gets to the second part on the same page it is returning 1.28 instead. PHP Code:
View Replies !
View Related
Code Returning False Mysql Result
I'm working on code which will allow users to "rate" something, for instance, on a scale of 1-5. When they click on a star (1-5), it sends them to the following PHP script, with ?rid=&rating= rid is the id of the item they are rating, and rating is the integer 1, 2, 3, 4, or 5. Problem is... even with an empty db table, it returns "Rating added successfully." - but doesn't add anything. If I add a row with uid=1 rid=2 and rating=3, and am logged in as uid=1, it still says "Rating added successfully.", and does nothing. It SHOULD HAVE updated the existing row and told me so. Code:
View Replies !
View Related
Pass Conditions From 4 Fields Before Returning The Result.
im doing a search query, whereby it'll have to satisfy a few conditions. as it's very straightforward it'll need to pass conditions from 4 fields before returning the result. i've made use of a temporary table. thing is, i could return it using one condition, but it gives a msg saying query unbuffered when i tried with all 4. $result = mysql_query("SELECT * FROM PEAR_reports WHERE trainer='$trainer1' AND program_title='$program_title1' AND start_date='$start_date1' AND end_date='$end_date1'"); anything wrong or funny with that line?
View Replies !
View Related
Getting MYSQL Result Into Single Variable
I have a MYSQL query running that returns a single string of data but it is returned as an array. What I need to do is store that single piece of data in a variable. I know it's probably a really simple process but it has been irritating me for far too long. the result I get when I use print_r($result) is: Array ( [ADDDATE(񟭇-04-05', INTERVAL 6 DAY)] => 2007-04-11 ) I can't figure out how to store the 2007-04-11(the result) into a single variable named $end_date.
View Replies !
View Related
Returning Result Set (many Rows) From MySQL Stored Procedure
I have a MySql stored procedure that simply runs a SELECT that will return multiple rows. I'm calling it using PEAR::Db->query. I get an error return: [nativecode=1312 ** PROCEDURE neighborhoodserver.proc_Get_available can't return a result set in the given context]' If I simply execute the SELECT statement through 'Db->query', it works fine. If I call the stored procedure from the command line, it works fine. What am I missing?
View Replies !
View Related
Turn Select Query Result Into Hyperlink To Other Query
I have a query which gives results of selecting coursenames from a table called trainingtopics but this does so in a continuous bulk of text without any breaks between each record. my question how do I create line breaks between each record and also how can I force each query result to become a hyperlink which when clicked runs another query that gives details of that course. <?php $user = "root"; $host = "localhost"; $password = ""; $connection = mysql_connect($host, $root, $password) or die ("Couldn't connect to server."); $database = "courses"; $db = mysql_select_db($database) or die ("Couldn't select database."); $sql = "SELECT coursename FROM trainingtopics"; echo $sql."=sql<br>"; $result = mysql_query($sql) or die(mysql_error()); echo $result."=result<br>"; while($row=mysql_fetch_array($result)) { // NOTE this one ABOVE the echo echo "result found!"; echo $row[0]; } ?>
View Replies !
View Related
MySQL Query Providing Duplicate
I can't figure out how to pull only one line per result set. I know why it's pulling double entries, one from each table in the join. I can't figure out what i'm doing wronge how do I remove these duplicates from the query. SELECT TABLEA.id, TABLEA.mem_id, TABLEA.individual_list, TABLEA.type1, TABLEA.type2, TABLEA.type3, TABLEA.type4, TABLEA.type5, TABLEA.type6, TABLEB.member_number, TABLEB.first_name, TABLEB.last_name.
View Replies !
View Related
Query Returning Array
I'm missing something very obvious, but it is getting late and I've stared at it too long. I am writing a basic function (listed at the bottom of this post) that returns data from a query into an array. The intent is that the following code: $foo = dbSelectData("SELECT foo, bar FROM table", $link); would return an array with the keys: 'foo' and 'bar'. But what I get is instead a multidimensional array. Doing a var_dump on $foo turns out to be array(2) { ["foo"]=> string(5) "Stuff" ["bar"]=> string(10) "More Stuff" } I'm wondering where I went wrong in writing the function below. function dbSelectData($query, $connection, $rtype=MYSQL_ASSOC){ $result = mysql_query($query, $connection); if(!$result){ dbThrowError("Error in function dbSelectData. Query Was <em> $query</em>."); return FALSE; } else{ $numrows = mysql_num_rows($result); if($numrows == 0){ return FALSE; } else{ while($rows = mysql_fetch_array($result, $rtype)){ $output[] = $rows; } mysql_free_result($result); return $output; } } }
View Replies !
View Related
Query Returning NULL
Trying to get a percentage (ROUND) off of two SUM columns but everything I try does not work. Is this even possible? The query I am trying: PHP Code: SELECT players.id, players.fname, players.lname, teams.name, player_stats.team_id, divisions.name, ROUND( ( 1.00 - ( SUM( player_stats.goalsa ) / SUM( player_stats.shotsa ) ) ) , 3 ) AS total_svp Trying to get SUM of both goalsa and shotsa, divide goalsa by shotsa, subtract that from 1.00, and ROUND that to 2 decimals. I can do it in PHP no problem, but am hoping to save some time by doing the calculation in the query.
View Replies !
View Related
Query Not Returning Results
I'm trying to prevent username duplication upon registering into a database. What I have in my PHP is.... $conn = dbConnect(); $sql = 'SELECT * FROM `tbl_users` WHERE `user` = ' . $_POST[ 'user' ]; $userCheck = $conn -> query( $sql ); if ( mysqli_num_rows( $usercheck ) != 0 ) { $result .= 'Username is already in use choose another one' . '<br />' $errors += 1; } The dbConnect(); function is working properly, but I'm not getting any rows in $userCheck. here's the specific error: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in C:wampwwwfastimportscontent egister.php on line 30 I purposely tried to add a username that was already in the database, so is it a problem with my query? possibly datatypes? The $_POST[ 'user' ] as you might have guessed comes from a text-type input box. I also wanted to check to see if I could convert to upper to check regardless of case.
View Replies !
View Related
Query Is Returning 0 Results
i thought i had this working earlier. I tested this in phpmyadmin and it worked fine. PHP Code: //Would be sent from flash, used for testing $theID="(letID=4)+(letID=60)+(letID=61)+(letID=3)+(letID=5)+(letID=6)"; $query = "SELECT * FROM scLets WHERE '$theID'"; $result = mysql_query($query); if (!$result) { Â Â Â Â fail("Couldn't list Lets from database"); } $letCount = mysql_num_rows($result); $letCount returns 0. But if i do it this way. PHP Code: $query = "SELECT * FROM scLets WHERE (letID=4)+(letID=60)+(letID=61)+ (letID=3)+(letID=5)+(letID=6)"; $result = mysql_query($query); if (!$result) { .......................
View Replies !
View Related
Query Not Returning Data
I'm trying to return information on a certain "family" or clan and the string my query returns is empty. Below is the familyinfo.php page which calls the function and below that is the function from database.php. Code:
View Replies !
View Related
Speeding Up Query/code (query Within Result Set)
I'm looking for ideas on how to speed up this script. Basically it finds all the zip codes in a zipcode table, then looks for all the records in another table with those zip codes. Right now it finds all the zips then within that WHILE, it looks for a record in another table with that zip: PHP Code:
View Replies !
View Related
Sql Query Not Returning Correct Results
i'm using an entry in an sql database as a semaphore and it, unfortunately, doesn't appear to be working. the script that spawns the child processes has a for loop that performs the same basic sql query over and over again until the value has changed (there's a one second delay between each query). unfortunately, the resultant row is always the same, even when the other process *has* changed it. as an example, if the orig. value was of the entry was 0, and one second into the execution of the second process, the entry was changed to 1, my program would, even 10 seconds later, fetch 0. in other words, it'd never be aware of the change. any idea as to why this is and what i can do to fix it?
View Replies !
View Related
MySQL Query Not Returning All Results
I have a user table in the DB, for example: +---------+----------------+-------------------+ | uid | username | firstname | |----------+----------------+------------------+ | 1 | cobby | Andrew | | 2 | admini | test-account | +---------+-----------------+------------------+ If, in phpMyAdmin, I query: SELECT `username` FROM `users`; It will return results correctly (cobby and admini, respectively). But if I make a simple PHP script, such as: <?php mysql_connect('localhost', 'cobby', 'dbpass'); mysql_select_db('testdb'); $query = mysql_query('SELECT `username` FROM `users`'); print_r(mysql_fetch_assoc($query)); ?> It only returns: Array ( [username] => admini ) Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.
View Replies !
View Related
Mysql Query Returning Incorrectly
The following MySql Query is not retuning correctly. It is returning dates outside the given range. Why? Code: SELECT distinct sale_type_landsale.sale_type_landsale_id ,sale_type_landsale.sale_date,sale_type_landsale.city,sale_type_landsale.name,sale_type_landsale.sale_price,sale_type_landsale.number_lots FROM sale_type_landsale Left Outer Join connector_sale ON sale_type_landsale.sale_type_landsale_id = connector_sale.ref_id Left Outer Join sale ON connector_sale.sale_id = sale.sale_id Where sale_type_landsale.sale_date >= ��-01-01' AND sale_type_landsale.sale_date <= ��-06-08' AND sale_type_landsale.city =Ɗ' OR sale_type_landsale.city =ཉ' AND connector_sale.ref = 'sale_type_landsale' AND sale.sale_archive <> 1
View Replies !
View Related
Use Query Result Field As Query Key For New Query..
$query  = "SELECT ProjID, UserID, ProjDesc, file, OrigProj, OrigUser, ProjDate FROM projects"; $result = mysql_query($query); I would like to take the field 'UserID', and utilise it for a Query statement to my users table in my database, to read and fill in information to my table, which looks like this: PHP Code:
View Replies !
View Related
Update From Single Query
Anyone know if this script is capabale of doing a multiple update in MySQL from a single form? It basically pulls out all the players from a particular team and adds static list boxes for games played/games won. The script works... but am having troubles with this part. code:
View Replies !
View Related
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 !
View Related
MySQL Query Returning Empty Column
Here's my code: $query_get_machine = sprintf("SELECT machines.ID, machines.NotifyID, machines.Name, notify.ID, notify.`Data` FROM machines RIGHT JOIN notify ON machines.notifyID = notify.ID WHERE machines.ID = %s", GetSQLValueString($colname_get_machine, "int")); Can anyone tell why the notify.`Data` column might be returned empty? All others display as they should.
View Replies !
View Related
Returning Results Of Query Into Alternating Table Cells
I am pulling results from a query into my page & am trying to get the results into a table that is 2 columns wide. I am also alternating the background color from row to row. I can get the results to alternate the background using the ternary operator, but am having trouble getting the records to echo correctly. It is obviously easy to get the records to just show a single record in each table row, but getting it to show 2 in one row & then continue on in the next row seems trickier. Code:
View Replies !
View Related
Using Query Result To Do Another Query In Loop
I have 2 tables, one called users2 and one called books. Books has a field called UserId, which is the ID of the user that added the book to the database. My problem, is that i need to take this ID from the book table, and use it to get some information from the user table. Here is my code to get the ID from the book table: Code:
View Replies !
View Related
Hyperlinking A Single Field From A MySQL Query
I've created a database that has the following fields: id (int) lastname (varchar) firstname (varchar) etc etc I'm able to query the DB and produce the FULL field list results as I need them (in DESC order), but my question is how do I generate the field 'id' into a hyperlink that will be formatted as mysite.com/query.php/id=(id number)?
View Replies !
View Related
Update Multiple Rows W/single Query
I was just wondering if it's possible to update multiple rows in a MySQL database with a single query? I'm updating a single column based on a WHERE clause obviously, I just want to avoid having to run a foreach loop and then executing n number of queries. Suppose this is the query: UPDATE tbl SET update_field = '$value' WHERE id = '$id' And I'm holding an array where the key holds the update_field and the value holds the id.
View Replies !
View Related
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 !
View Related
|