How To Make An Array With Query Results? (Postgresql)
Need help making an array with query results:
$value = $_POST['text'];
$pg = pg_connect('dbname=test user=user password=secret');
$query = "SELECT column FROM information"; $result = pg_query($query);
*** how to create array with $results ***
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Query Array, Sort Results And Display In Seperate Tables
The problem I have it breaking out the results and displaying them (broken out) alphabetically in seperate tables. For instance, I have generated (bookmarked) tables, one for each letter (A-Z) and want to display all recordsets with say, last name beginning with "A" in one 2 column table, "B" in another 2 column table, and so on... each table would have two columns (with 2 background colors alternating), each cell containing values of one recordset. Even more tricky is if I have an odd number of cells, still generating the last cell with empty values (for asthetics). And can anyone say "sort" (yes, I am nuts)? The ability to sort the whole mess by any column value. I have looked at freeware and other third part apps, but they can only do what I already can do (mine is actually cleaner) but not as complicated.
Query Problems With PostgreSQL
I'm having intermittent problems with queries from my php script to a postgresql database. I have a form where I can enter a search query - for instance a last name. This leads to a results page with a brief bit of information about each of the matching results. From there, I can click a link associated with any of the results which takes me to a page with all of the details. Pretty standard stuff. Problem I'm having is that for some of the results, when I click the link to go to the full details page, no information is returned by the script. I basically end up with my html template & no data populated. For the majority of items, things work just fine. One thing I've noticed is that it seems to be reproducable - that is, for example item 5123 always fails to return any results on the full details page. Quote:
Warning: PostgreSQL Query Failed: ERROR: Pg_atoi:
I've built a postgres database that can be controlled through browser inputs to update, insert or delete records. i'm using php to access the db and display results in html. all of my update commands work fine but my inserts will not, each time i try to insert it kicks out this line: Warning: PostgreSQL query failed: ERROR: pg_atoi: error in "head": can't parse "head" in ....... on line 47 for this example "head" is an attribute of type text which is all set up properly to send and hold the correct attribute type ($tag_method in the sql under here). Line 47 refers to the sql command in my php which looks like this: LINE 46: $sql="INSERT into sheep values ('$tag_method', $flock_id, '$sex', '$breed' , $age, $parent_id, '$born_on_farm', '$date_joined', $price_paid, $price_sold, $sheep_number)"; LINE 47: $result_set = pg_Exec ($conn, $sql);
PostgreSQL Queries, Storing Results Instead Of Multiple Queries
I have a script that does multiple SQL queries. So I have something like $result = pg_query($my_query); After this query I tend to loop through like this to get the result: while ($entry=pg_fetch_row($result)) { //do stuff } But my question is, how can I make a copy of the result? So I don't run the query more than once.
Trying To Make Populated Drop Down Box Query
My host is Godaddy, sql 4.1 - trying to create a populated drop down list that when submitted, displays the info row by row. I can populate the list, and when I post it takes me to the next page. The php on the next page makes the table header but there is no data underneath. There is data in the table cause I can display it all on another php page I have. Code:
How To Make MYSQL Query To Sort The Articles By Date ??
I am developing a site using PHP and MYSQL where i can post articles. Each Article has features like author, date, data etc... I want to find out top 5 recent articles. I store the date of an article in database as $timeStamp = Date("F j, Y"); when i make a query to retrieve the latest article by date as: $result = mysql_query("SELECT * FROM postData ORDER BY postDate DESC LIMIT 0, 5"); it doesn't give any output...
Sorting Sql Results In An Array Using Things Outside The Array To Sort Them?
I'm using PHP to connect to a database full of place names, and their associated post codes, latitude and longitude on the earth. A user types his or her post code into a form, plus a distance (in miles), and the script looks for other area codes (first half of the post code) within that distance. I can do that fine, but the results are ordered alphabetically by postcode, and I want to order it by the distance. Problem here, is that the distance isn't part of the array taken from the database, it takes the latitude and longitude of the area it's on in the while loop, and calculates the distance between the user's post code and that one, but it's not part of the array, so I can't sort the array using it. How can I sort it? Can I add the calculated distances to the array, and sort it using sort()? If yes, how do I add them to the array? Here's the page, just to explain better what the script does: http://navimaker.org/ed/owain/results.php?postcode=gl15&distance=34 Mess around with the postcode and distance vars. I'd put the source on here too but I'm doing all this over SSH and can't copy & paste very easily .
Getting Too Many Results From A Query!
This is very peculiar -- for some reason, I'm getting 6-8 results from each of these queries, although only one listing matches. I have a pair of forms on one page: <FORM> Search for lastname: ____________ [Submit] </FORM> <FORM> Search for email: ________________ [Submit] </FORM> This goes to a searchresults.php page: if ($searchname !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE lastname='$searchname'"; $result=mysql_query($query) or die(mysql_error("Could not execute query.")); while($row = mysql_fetch_array($result)) { $alt_artistID = $row['artistID']; $alt_firstname = $row['firstname']; $alt_lastname= $row['lastname']; $alt_email = $row['email']; $alt_city = $row['city']; $alt_state = $row['state']; $alt_country = $row['country']; echo "<CENTER><HR>".$alt_artistID."<BR>" .$alt_firstname." ".$alt_lastname."</A><BR>" .$alt_email."<BR>" .$alt_city.", ".$alt_state." ".$alt_country."<BR> <A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS LISTING?</A><BR></CENTER>"; } } The second section is identical except for: if ($searchemail !== "") { $query="SELECT artistID,firstname,lastname,email,city,state,count ry from artists WHERE email='$searchemail'"; etc... } I don't understand why I would get 6-8 records when you can look at them and see that all but one clearly do not match...?
Using Query Results
Can you use a queries results only once? In this script I'm looping through a query and saving some values in an array. A little further through the script I need to use the same query for output. When I loop through nothing is echo'd to the browser. When I output a row count it shows that the correct number of records, so they must still be there.
Query Results In 2 Columns?
I'm struggling to figure out how to do this properly. I have done a mySQL query to extract a list of names, and done a mysql_num_rows to determine how many results I've gotten. I want to split the list in to two columns. I've created $percol = $mysql_num_rows/2 but I'm not quite sure how to "loop" through the first half of the list, echo </td><td> and then list the balance. Can anyone give me some guidance on how best to structure this?
Finding The Results Of A Query
I am working on a script that will query a database for a FNAME/LNAME combo. If it finds the combo, I need it to do one set of instructions. If it doesn't find it, I need it to do something else. What I can't figure out is what variable to check against. Here is what I have for the relevant part of the script: $connection = mysql_connect($hostname, $username, $password); mysql_select_db($databasename) or die ("Cannot connect to database" ..mysql_error()); $query="SELECT FNAME, LNAME FROM (table) WHERE FNAME=('$FName') AND NAME=('$LName')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close($connection); I tried checking the value of $result to see if it changed depending on whether or not it found the selection. It does not. I just can't figure out what to use for: if (some expression){ perform this code } else{ do this }
Grouping Results Of Query
I'm brand new to PHP (just starting today to convert tons of ColdFusion/Access code to PHP/MySQL). There is a function in Coldfusion that I can't find an equivalent to in PHP. Here is what I am trying to do: If I have a query that results in this information: State Firstname Lastname Idaho Terry Pratchet Vermont Dan Brown Vermont Bob Smith Virginia Alice Johnson Virginia David Jones I would like to output the info like this: But all I can find in PHP is a way to loop through the query and show every row... if you are familiar with Coldfusion, what I am looking for is something similar to this: <CFOUTPUT GROUP='State'> #State#<BR> <CFOUTPUT> #Firstname# #Lastname# </CFOUTPUT> <BR> </CFOUTPUT> Is there a function that does this in PHP, or do I need to write code that watches the value of 'State' and manually takes care of things whenever it changes?
ODBC Query Results
Consider the following: <? $username = "foo"; $password = "bar"; $host = "db"; $connect = odbc_connect("$host", "$username", "$password") or die; $query = "SELECT id, name, address, city, state, comments1, comments2 FROM data.table1, data.table2 WHERE id = ô˜'"; $result = odbc_exec($connect, $query); while(odbc_fetch_row($result)){ $id = odbc_result($result, 1); $name = odbc_result($result, 2); $address = odbc_result($result, 3); $city = odbc_result($result, 4); $state = odbc_result($result, 5); $zip = odbc_result($result, 6); $comments1 = odbc_result($result, 7); $comments2 = odbc_result($result, 8); print("ID: $id<br>Name: $name<br>Address: $address<br>City: $city<br>State: $state<br>Zip: $zip<br>Comments1: $comments1<br>Comments2: $comments2<br> "); } ?> Only one record is returned from data.table1 (containing the id, name, address, city, state, & zip). However, there are multiple records returned from data.table2 (records from comments1 & comments2). What is happening is that when I run this script, all of the data returned from data.table1 is printed over & over again along with each record returned from data.table2. How can I make it such that id, name, address, city, state & zip are only printed once - and allow comments1 & comments2 to be printed multiple times for each occurance in the database? I've thought about just creating a second database query for the records in data.table2, however I need the join I'm getting by using the existing query. For what it's worth, I'm connecting to a DB2 database using PHP / Apache on Linux. I'm confused by this.
Losing Query Results!
If I make a query; $result = mysql_query($theQuery, $db); and then make use of the query results like so; while ($row = mysql_fetch_row($result)) { //do something with query results} I can't use $result again, I have to make another query! Why is this and is there any way around it?
Multiple Sql Query Results
I'm trying to do a query from 2 databases. Basically i have catagories within 2 databases. If both catagories return 0 rows then it does nothing but if one or both have rows returned then i need it to echo a result. I guess where i'm wondering if there's an OR statement i can use or something to that effect... something like if($numrows == 0 OR $numrows2 == 0) { echo (''); }else{ echo ('$result');
SQL Query - Results From Another PHP Page ?
Can I store this PHP code in another page, then refernece it on multiple pages using Require or Include ??? //results from sql query for ($i=0; $i<$number; $i++) { $ID = mysql_result($result,$i,"ID"); $CompanyName = mysql_result($result,$i,"1"); $ContactName = mysql_result($result,$i,"2"); $Phone = mysql_result($result,$i,"3"); $HomePhone = mysql_result($result,$i,"4"); $MobilePhone = mysql_result($result,$i,"5"); $AltPhone = mysql_result($result,$i,"6"); $SecondContact = mysql_result($result,$i,"7"); $SecondPhone = mysql_result($result,$i,"8"); $ThirdContact = mysql_result($result,$i,"9"); $ThirdPhone = mysql_result($result,$i,"10"); $Notes = mysql_result($result,$i,"11")
Sql Query Results And Scrolling
I make a mySQL database query and display the first 10 results. Then the user can click on "next" link to get the next 10 results. How can I do that without issuing the sql query again? Can I keep the results from the first query?
Query In PHP Won't Return Results In There's Only 1
$sql = 'SELECT `PageTitle` ' $sql .= 'FROM `Pages` ' $sql .= 'WHERE `PageID` = 1 LIMIT 0, 30' I have run this query in MySQL control panel and it works perfectly. When I try to do it via PHP I get no results. If I select all rows (i.e I don't specify a "WHERE") I get one fewer rows returned than there actually are.
Tabulating Sql Query Results
I'm trying to number my rows in the column named "Pos" but so far I not getting any success, someone please bail me out find below my script, this script displays my results fine but without my Positions (Pos); Code:
Combining Query Results
I have two queries which searches for any fixtures your clan (team) is in and then returns some information about the fixtures. Is there any way of combining these results and ordering them by date? Code:
Filtering Results With Php Query
This code works, but I don't know how to filter the results to where only one person is displayed..it displays all records with similar address or state or city, I would like to know how to make it display only one person when multiple search fields are entered. I'm using PHP5, and I have searched the forums but I'm not sure exactly if I found what I'm looking for...I don't know much about php or mysql. Code:
Capturing/using Results Of Query
I would like to display/capture/use the URL's that are displayed on a web page after making a query to a forum. What do I mean? I am part of a forum that uses vBulletin. One option is to display the forum topics that have had posts that day, i.e. active topics. Essentially, when you click on the link: http://www.somedomain.com/forum/search.php?do=getdaily the resultant page has a list of the active topics, highlighted as links. What i would like to do is capture/access that resultant page and use regular expressions to grab the URLs. I can do the RegEx but I cannot seem to capture that resultant page.
How Do I Show Results Of A Query
I know how to connect to a Mysql table. I want to run the query and show the results on my page. I'll have about 25 different fields I need to show on the page. Most of this information will be a couple of addresses. Basically, a billing and then a shipping address. Can someone show me how to show some of this on a page? I'll need to align all this stuff around the page.
Filter Results Of Query
I am modifying some pages in CRE Loaded. allprods.php list all currently active products and I added a manufacturers column that displays who makes that product. I want to allow shoppers to filter the product list so that it shows only products from a particular manufacturer. I have gone through several scenarios in my mind, but nothing I've thought of seems simple and bullet proof. One of the issues is that the all products query includes all manufacturers. If I were to put a variable in the query to select only a particular manufacturer, how would I code it so it does not interfere with the all products query? Would logic based upon the value of a form action work? If form action exists, someone wants to filter. If not form action or form action = all, then they want the whole list. Seems like filtering a list is pretty common and there should be an easy solution.
Make Selection In Array
I have this array: name => john, age => 45, profession => teacher name => hank, age => 22, profession => student name => mary, age => 36, profession => dancer etc. etc. It's going to be a big array. Now what i wonder, how can i do the following; while( $array['name'] == 22 ) { do something. } I want to prevent the following: while( $array ) { if( 'name' == 22 ){ do something } } Because this would create a big loop everytime.
Make Array Out Of Checkboxes?
I did a Web search, and a deja.com search on this...and I'm finding how to make checkboxes act like radiobuttons, and other interesting behaviors, but nothing that quite answers my question. If someone has a link or thread they know about, even just that would be great! What I have is a page that generates a list of items from a database...a list of rows. I'm having each row in the WHILE array create a checkbox, so that someone can put checks in any row they want to delete on submitting the form. Now, how do I set up where it collects which checkboxes were selected? I'm sure if I can get that far, I can figure out an EACH method of then deleting each id from the table. Here's what I'm doing so far with the checkboxes: while ($row = mysql_fetch_array($result)) { echo "<tr ".$bgcolour."><td><input name="del" type="checkbox" value="$iid"></td><td>" . $quantity . "</td><td>" .. $typename . "</td><td>" . $typesize . "</td><td>$" . $amount . "</td><td></td><td></td><td>$".round(($amount*$taxmult),2)."</td></tr>"; The $iid is the table.id mentioned in the SELECT statment before this. So that each checkbox, when checked, will have a value of that row's ID.
Formatting Problem With Query Results
I have a minor problem with a script. I have written a piece of code (do...while loop) that will return results of a query a row at a time, with the proper formatting in a table. Everything works fine when there are results to lay out in the table. The problem arises when the query yields no results. When this happens, the loop below iterates once (without data) instead of not executing at all: $result2=mysql_query("select * from ...) or die(""); $myrow2=mysql_fetch_array($result2); do { ...bunch of stuff... } while($myrow2 = mysql_fetch_array($result2)); Where do we go from here?
Combining Results From MSQL Query
I have the following 2 queries which each produce a result. I have spent hours reading up and have searched devshed but I can't find how I would go about Adding these two numerical results together using PHP. Query 1 $sql = "SELECT SUM(total) AS total_price FROM detail_tourdet WHERE voucher_id = '$voucher_id'"; $result = mysql_query ( $sql ); $row=mysql_fetch_array($result); echo $row['total_price']; Query 2 php $sql = "SELECT SUM(total) AS total_price FROM retail_acom WHERE voucher_id = '$voucher_id'"; $result = mysql_query ( $sql ); $row=mysql_fetch_array($result); echo $row['total_price'];
Sorting Database Query Results
I want to know if it is possible to sort query results so that the records with a value in a certain field is displayed first and the records with the field empty thereafter.
Sorting Query Results Into Groups
I have a 'staff' table with a column 'status', corresponding to a 'statuses' table with the appropriate titles (eg 1 | Editor in Chief). I want to display on the page the headings (the titles from statuses) along with all of the staff members with that status ID. I've attempted this using a query for each possible status, which I figure was pretty inefficient (plus it didn't work properly). The best I could do manually was to just display a list of staff and their statuses sorted in order of the title ranks.
How To LIMIT Results In Html Php/sql Query?
I need to limit results in the following query type: http://www.somewhere.com/php/sql-a....ql_order=&pos=1 I found a reference that says I should be able to use LIMIT x[,y], but I don't know where/exactly how to add that to the string. Once I know what it's supposed to look like, and can write something to generate it. If someone could post an example using the above and limiting the output to 100 records starting at position.
Display Query Results In A Table
$sql = "SELECT name FROM employee_tb; $result_query = @mysql_query ($sql);// run the query while ($row = mysql_fetch_array($result_query,MYSQL_NUM)){ $name = $row[0];} // assuming i have 8 results how can i display the results from this query in a table with 3 rows each column?
Query Results And Affected Rows?
I'm doing a mass database update and I have a query string something like this: UPDATE table SET field1=0, field2='' WHERE (email='address1' OR email='address2' {and so on...} ); I know you can view how many rows were changed after its done. I'm wondering though, is there a way I can view which entries failed? For example, lets say the email address - 'address34' was not found in the database, is there anyway I can display this from this UPDATE query? or to do this, would I have to compare each address individually with the table to check if it exists? (and if it matters I have about 1000 adresses that are being updated from this)
Query Results With Multiple Keywords
The way I have it set up now, a form results in 2 keywords, namely Keyword and Keyword2 using 1 text field, and one select field. In the text field, the person enters in the City, in the Select field, they choose a state, which abbreviates it to 2 letters. Now, for the code that is supposed to process this: Code:
Exploding Results Of Mysql Query
I have a table with times and dates listed like this: 0000-00-00 00:00:00 2003-09-20 20:26:22 etc etc What I want is to query the DB for the field (matchdate) and then get it to explode the ' ' to give jsut the date for me and then put it into a dropdown in a loop. this may sound easy but i too sleepy to work it out and searching aint good.
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?
Aligning Multiple Query Results
I'm trying to pull data from 2 different tables and do a loop to retrieve more than one row. I'm having problems with aligning the information. Can someone lead me in the right direction? I've done some looking myself and found something called GROUP BY? Is that what I need to use?
Checking Lenth Of Query Results
If I return a result from a query with mysql_fetch_array and need to check the character length of a specific field, what is the best way? I have tried mysql_field_len but am getting errors with the code below: PHP Code:
Arrays, Query Results And Select Box
I want/need to pre-select a drop-down box with a value if it's present in both a lookup table and user account table. After wrestling with this for a few hours I give up. i know this can't be this complicated, but apparently i'm missing something, so if anyone can suggest a way to go about this i'd be a little more sane. The idea is to have the user value already selected then when they change the value i'll update their account.
I Need To Export Query Results To A .txt File.
Here's some code: I need this info displayed on a .txt file that is updated each time that text file is called up. So if a new result is added, when that text file is called up I need that new listing to appear there. Or every time a new result is added, it updates the text file. Whichever makes the most sense, I'm not sure.
How To Truncate Multiple Query Results....
I have a news section on my website, where the article(s) are stored in a MySQL database. Titles in one column, article body in another. On the actual page, I have a limited space to which to print the content, and need to truncate it so it does not overlap, or stretch the content div and blow the design out of whack. When only returning one article from the db, I can do this easily, however, the problem is that not all articles are/will be lengthy enough to fill the div. In such cases, I want to return the next article, up to the remaining div space, then truncate it. For example, right now, the article that's being displayed fills up more than the allotted space, so it's truncated. But the next three articles I post may be short, where I'd need all three plus a segment of a fourth to fill the space. Using Dreamweaver MX2k4 I can do this by "repeating that region", but limiting the number of characters is only applicable to each query, not to the overall div. As such, it won't work in the way I need. Code:
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.
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:
Make Associative Array Out Of String
I have a string that look something like this: $string = "weight, kg|1200|width, mm|220|prize|20000"; and I would like it to an associative array and print keys and value: weight, kg: 1200 width, mm: 220 prize: 20000 (The string above is fetched from a database) Anyone have any bright ideas how to do it?
Make A Link Using Array Content
I want array's content to become a link itself. like,,,,, echo "<a href="$result[$rows][$cols]">".$result[$rows][$cols]."</a>"; this $result[$rows][$cols] in array has contents of email address.but it doesn't work. can anybody tell me how?
|