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


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





Populating Array With Mysql Results


I'm returning a result set of one field in a table, and want to populate an array with the results. I can't for the life of me figure out a simple way to do this without using mysql_fetch_array() to cycle through the results, append that to a var, then explode that into a var and pass that. PHP Code:




View Complete Forum Thread with Replies

Related Forum Messages:
Populating A Drop Box With Results From Database
I have a MySQL database with a table (category) with two fields, catId (int) and category (char(50)). What I want to do is to get all category names in this database and place all of them into a dropdown box on a web page so that the user can choose from the list of available categories.

View Replies !
Populating Form From Database, Then Passing Results To Next Page
I have a multiple select input in a form that's being populated by a row
from my database as such:
<input type="checkbox" name="subm[]" value="$row[ID]">

That part is working fine as I can check the displayed page using View
Source and see that the value is the correct row number from the
database. It is then being submitted on a form by $_POST method to
another page where I want to evaluate the checkboxes and display the
contents of the entire row that corresponds to each value="$row[ID]"
that have been checked. But I can't seem to get it to work. I'm having a
problem passing the selected value. Can someone point me in the right
direction?

$query = ("SELECT * FROM `table`");
$result = mysql_query($query);

print "<p>Data for Selections:";
print "<table border=2><tr><th>You chose:";

foreach ($_POST['subm'] as $value) {
print "<tr><td>";
print "$row[ID];
";
print mysql_field_name($result, 1) . ": " . $row[name]."<br>";
print mysql_field_name($result, 2) . ": " . $row[address]."<br>";
print mysql_field_name($result, 3) . ": " . $row[city]."<br>";
print "</td></tr>";
print "</table>
";
}

if (!isset($_POST['subm'])){
print "<p>No matching entry ";
}

mysql_close();

View Replies !
Store Mysql Results Into An Array
i just started using php. i've used it before as a maintainer. fun stuff. well now i'm the writer. i want to abstract all the DB commands away from myself and all other developers. so i'm writing a function to query the php database from all users of the database and store them into an array as a return value so that i can seperate my database code from my html creation code.

1. is there a way to put all my database functions into a php file and include that file into all my other php pages? similiarly to a #include in C++ or a import package name in Java?

2. my code to run down the fetched results and store them into an array doesn't seem to be working the way i want it to. if i print out the results from the mysql returned fetch the data is fine. however the array seems to print out "Array[elementnumber]" instead of the value. Code:

View Replies !
MySQL Results Array Not Same As Query In DB
I am running a query in a MySQL database, and the results I am getting in my array do not match the results from running the exact same SQL in MySQL. Code:

View Replies !
How To Loop The Mysql Results Into An Associative Array
i am working on a script that write mysql results to excel file. I got a class that handle MSExcel Stream, but the only problem is I dont know how to loop the mysql results into an associative array like what the script do in the example. Code:

View Replies !
Building An Array With Mysql Results, Then Parsing Them
I'm trying to set up a word censor for a script I'm working on. Code:

View Replies !
Pushing Data Into A Multi-dimensional Array From Mysql Results
First, A result array I'd want to get could look like this:

$chart['chart_data'] = array (
array ( "Region A", 10,12,11,15,20,22,21,25,31,32,),
);

The first is "Region A" and the rest is just int's that I'd pull from the db, so to set it I'd do this:

$chart [ 'chart_data' ][ 0 ][ 0 ] = "Region A";

But the problem is when I want to insert the data in the while loop (like the 10,12,11,15...), I've tried array_push but it's not working, maybe it doesn't work with multi-dimensional arrays? Anyways, here.'s what I tried, the following inside the "while" to loop the mysql results with mysql_fetch_assoc:

while($r=mysql_fetch_assoc($res)) {
   
     $chart [ 'chart_data' ][ 0 ][ 0 ] = array_push($chart['chart_data'][0][0], $r['wght']);
     // the above line is where I have problems    ^^
}

What I want is on each loop to insert the fetched data inside the array so that it gives what I gave first at the top, but what I've written above doesn't work, it gives me a warning saying "first argument must be an array" which seems to be one, but anyway, anybody know how to do this?

View Replies !
Populating An Array Depending On The User Inputs
i am populating an array depending on the user inputs and displaying the contents to the user. The user wants to print the same information.

I want to pass that array without using sessiond through a link to another page so that everytime i need not query the database.

View Replies !
Populating Multi Dimensional Array From Queries
I am trying to populate a multidimensional array with a simple (categories > sub_categories) I get the categories into the array just fine but I can't figure out how to populate the sub_categories as array belonging to the first categories array; I am close. Code:

View Replies !
PHP + MYSQL, Populating Drop Down Box
I am looking to generate a dropdown box from MYSQL data:

db name = h2, table = Working, Column = Home.

View Replies !
Populating Drop Down From MySQL
I am trying to populate a drop down menu of MySQL data using PHP and I have hit a snag. I think its probably something simple that a freah pair of eyes could pick out right away that I am just not seeing...

For some reason only the "firstname" part of the data is populating in the drop down and I can't figure out why. When I try to make changes to the echo lines to correct this, nothing shows up including the "firstname" data. Code:

View Replies !
MySql Menu Populating
My goal is to use a Drop Down Menu that is populated by
the database. The user is then able to select a name from
the Menu that pulls all of the information for a particular
person from the database. Finally, a table is populated
with the information of the selected person.

View Replies !
Populating DHTML Menu From MySQL
I have a client that would like to have drop down menus added to a nav
bar that is generated from MySQL. Is it possible to have a dynamically
driven DHTML menu from MySQL?

View Replies !
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.

View Replies !
Populating Dropdown With Mysql Entries
I would like to create a combobox in Flash which is populated with mysql data and programmed with php. For example: There are 3 entries in database .ie. apple, bannana, peach. Now these I want in combobox in Flash MX/flash5.

View Replies !
Populating A List/menu From MySQL
is there a way to populate a list, or a menu form using php, and MySQL? Basically i have a list, and i am planing to import 2 variables, id, and name, bouth id and name are variables loaded from MySQL (yes there are multiple id's, and name's) Name would be the label displayed, and the value would be id. Thats what i need. After that i will make a submit button, witch will post the selected id to a different file. How can i achive this? Does anyone hae any samples maybe?

View Replies !
Populating An Excel .csv File Rather As Well As MySQL
I am very new to this and have what may be a ridiculous question. Is there a way to have info populate both the MySQL table and an Excel .csv sheet? I know that I can go into PhpMyadmin and dump the data but this seems to be a bit cumbersome.

View Replies !
Populating Checkboxes From A MySQL Database
what im doing is populating a php variable, and trying to use the result to add either checked or nothing to the value of the checkbox. Any ideas? Code:

View Replies !
Populating A Table With Data From MYSQL
I have a mysql table with the column names like as "id" and "value" and "bizunit". I also have an HTML table that have unique DIV IDs that correspond with the mysql table.

$query = "SELECT value FROM paceReport2 WHERE bizunit = 10"

How do I write a loop statement that will populate each of the cells in the HTML table?

View Replies !
Populating A Drop Down From A MySQL Table
When they click submit, I want the name dropped from "invite" and added to a table "guests" with their answer if they are coming and how many. I know the SQL to make it happen, but I am pretty sketchy about the PHP. Code:

View Replies !
Populating Page Content From Mysql Db.
First off my db table is orginized in this way:

ImgKey (auto increments)
ImgType (pertaining to the buttons in the gallery)
ImgName (name of image)

When you click a button from the initial gallery page, my plan is to pass a query string to the next page with the appropriate ImgType. On the next page I need to grab all the records in the table with that ImgType. (you can see the next page by clicking the first button) Code:

View Replies !
Passing 'var' Via GET And Then Populating Page (mysql)
I have a table with a column of numbers (random):

0000000001
0000000026
0000000059
0000000034

And I would like to link them to go to 1 specific template page. Then once on that page, the number that was clicked gets "posted" to the MySQL Query and the information for the page populated dynamically rather than having to have 4 different pages for each number (that's the way I'm doing it now). Code:

View Replies !
Populating An Html Form With Mysql Data.
What I have is a basic html form I have made consisting of header fields and fileds that will be populated from a mysql database. The brackets are the actual db fields and denote where I want the data to populate. Here is a small example of the form. Code:

View Replies !
Populating Multiple Drop Down Boxes From Mysql Table
Am having a problem with a dynamic, multiple drop down box query. If I run the code with only one select, it populates fine. If I run it with 2 selects then only the first drop down box populates - the second drop down box is empty. Am wondering if I need to put the query into an array and populate the boxes from there. Code:

View Replies !
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 .

View Replies !
Placed The Results Into An Array
Basically I have a query, and from the resultset I've placed the results into an array. In a nut shell the query below fetches the questions. Thats not a problem, the problem is that I want to display the first question out of the array. Code:

View Replies !
Results From Array
PHP Code:

<style type="text/css">
.booked
{background-color : #ff5050; color : black;}
.free {background-color : #CCFFCC;color : black; }
<font color=black size=2 face=verdana>
</style>

<?php
//book.php
$rt=1;
$sy=2005;
$sm=8;
$sd=28;
$start_date="$sy-$sm-$sd";
.........

View Replies !
Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.

I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:

View Replies !
Looping Through An Array And Using The Results.
function build_menu() {
$all_li = create_list_items();
$menu = '<ul id="navbar">'
reset($all_li);
while($li = each($all_li)) {
$menu .= $li;
}
$menu .= '</ul>'
echo($menu);
}

I'm trying to move through each item in the #all_li array and add it's contents to the $menu variable. $all_links is filled with string values from the function create_list_items().

I tried (above) using each(), but the output from the function is "ArrayArrayArray" and this has me confused. I think it's giving me this because each() creates an array which includes key values (yes?), which means each() is not the method I need to use.

Can anybody advise me on a method I can use to loop through the $all_links array and add each string to the $menu variable? So far I've tried a for loop, foreach, even attempted an array_walk(), but haven't had any success.

View Replies !
Grouping Results In An Array
I have a query that runs against a database and returns a result in an array. The array contain names of people and what section they belong to. Each section has a unique id. So I want to group each person by the section id. Any pointers?

View Replies !
Turning Results Into An Array
my code currently looks as follows:

$find_zips="SELECT * FROM zipcodes WHERE longitude > '$north' AND longitude < '$south' AND latitude > '$west' AND latitude < '$east'";
$find_all_zips = mysql_query($find_zips);
if (!$find_all_zips) {
die('<p>error retrieving zipcodes<br>' . 'Error: ' . mysql_error() . '</p>');
}

$all_zips = mysql_fetch_array($find_all_zips);

echo $all_zips[&#390;'];
echo $all_zips[&#391;'];
echo $all_zips[&#392;'];
echo $all_zips[&#393;'];
echo $all_zips[&#394;'];

that is my closest guess as to how to convert the results of $find_all_zips into an array. However, this is evidently how the proper way of going about things. How would i convert those results into an array?

View Replies !
Results Of An Array In Sets
im trying to make an image gallery, and i query the location of the pictures. what i want is the results as an array to be displayed in sets of 4 in each <tr> of a table. PHP Code:

$kidsquery = mysql_query("SELECT * FROM gallery WHERE gallid = 1 ");
$kidsrows = mysql_num_rows($kidsquery);

    if(empty($kidsrows)) {
        echo "No pics";
    }else{

echo "<table width=&#39100;%' cellpadding=&#393;s' cellspacing=&#397;' align='center'>";
........

View Replies !
Displaying Array Results In Table
I'd like to display the results of an array in a table format with the Alias, Alias Destination & Username as column headings & the results underneath. PHP Code:

View Replies !
Evaluating Array And Skipping Certain Results
I'm having a brain freeze on this. I have a script where I am reading
the contents of a file into an array. I have that up and working with no
problem. Then I'm exploding the array using

while ($line = fgets($fd, 4096))
{
$arrayData = explode("-", trim($line));
}

Works fine. But what I want to do now is evaluate arrayData[2] to see if
it contains the integers "00" (that's zero zero) and if it does, I want
it to skip that entry. I know I need to set it up with
if arrayData[2] == "00" {

But I'm drawing a blank on how to get it to skip this entire line in the
final results. There may be multiple instances of this happening in each
file and I want to skip them all.

View Replies !
How Do I Search Two-dimiensional Results Set Array
Here's the pertinent code to get the SQL results. It is generated by
dreamweaver adn I'm trying to learn to code php so I don't depend on DW to
do it for me.

$query_rsSummary = "SELECT sid, Count(wid) FROM plotting GROUP BY sid";
$rsSummary = mysql_query($query_rsSummary, $tableG) or die(mysql_error());
$row_rsSummary = mysql_fetch_assoc($rsSummary);


How do I search the array to see if a certain "sid" has an entry in the
array?

View Replies !
Mysql_fetch_array - Convert The Results To An Array
I've got following code:

         $sql = "select user_id from sales_users where sales_id = ".$user['id'];
         $res = mysql_query($sql);

         echo mysql_num_rows($res);

         $clients = mysql_fetch_array($res);

It's a database containing users(sales_id) tied to clients(users_id). Each is is salesman for one or more clients, so obviously the resulting array has one or more rows. Whensales_id is 44, there are 3 rows: user_id's 4,13 and 45.

The echo of mysql_num_rows tells me there are indeed 3 rows. Now here it comes: when I convert the results to an array, I only get 1 element in the array, user_id 4. When I change the user_id's, it always returns the lowest user_id and leaves the other 2 behind. A print of the resulting array:Array(=> 4)

What am I overlooking? Up until now this has always worked well for me, but now I really don't see what could be wrong.

View Replies !
Take All The Results From A Query And Store Them In An Array
trying to get my head around arrays, and I want to take all the results from a query and store them in an array so that I can use them  for later use: Code:

View Replies !
Select 4 Results At Random From Array
Doing some more user ranking. Basically I am selecting the top 10% of users based on total points (being in the top 10% qualifies you to be featured), then I want to select 4 users at random from the top 10%. I wrote this to select the top 10% of users based on their total number of bricks (ranking points). Requires a join because of my table structure (using both a user and points table). PHP Code:

$query2 = "SELECT COUNT(user_id) FROM users";
$result2 = @mysql_query($query2);
if ($result2) {
$row2 = @mysql_fetch_array($result2, MYSQL_NUM);
$tu = $row2[0];
if ($tu <  100) {
$pool = 10;
} else {
$pool = round($tu * .10);
}
$query4 = "SELECT users.user_id AS user, SUM(bricks.brick_num) AS brick, users.featured AS feature
FROM users, bricks WHERE users.user_id = bricks.user_id AND users.featured = 'N' GROUP BY users.user_id ORDER BY brick DESC LIMIT $pool";
$result4 = @mysql_query($query4);
if ($result4) {
$row4 = @mysql_fetch_array($result4, MYSQL_NUM);

I now want to select 4 results at random from this array and store them in a new array. I know how to use shuffle/rand but how do I limit to 4 results? Should I just randomize and write a loop with a counter and stop at 4?

View Replies !
Assign Query Results To Array
how to assign the rows of a query result to an array?

View Replies !
Query Results To Javascript Array
I have a piece of javasript that uses the following array in its code:

var myData = [
["Americans","42", "24", "32", "550"],
["British", "26", "23", "95", "406"],
["Germans", "37", "15", "82", "289"],
["Japanese", "31", "15", "164", "160"],
["Russians", "24", "34", "10", "431"]
];

Now, Instead of having the above hard coded in the javascript code. I'd like to be able query the data from a table. If someone can maybe just point me the right direction, the basis steps.

View Replies !
Insert Query Results Into Array
I want to insert my query results into an array for sorting. The code i'm using will display the results but not in alphabetical order, so i'd like to insert them into an array and use sort(). Code:

View Replies !
Building Array Of Difft Results For Return
I have 2 functions that I want to call from a subroutine, and then return their results; one result is an array, the other will be an array of arrays. The first will be the information about a product, $product, with values like $product['title'], product['id'], etc.

The second will be an array of arrays, each line of which contains information about an element of the product. I.e., $item[0]['title'], $item[2]['value'], etc. How would I best combine these so I can RETURN the total thing from the function, and then how would I refer to the parts in the calling code? For example, if I said Code:

View Replies !
ODBC: Fetch Results As Associative Array
Will PHP fetch the results of a query using ODBC as an associative array? I know that MySQL does that, but I couldn't find it for ODBC connections.

View Replies !
Taking SELECT Results And Turning Them Into An Array()
Does anyone know how take a mysql select statement and have the results placed into an array? I am returning 1+ rows and want to place those rows into an array so I can run a foreach() for each row and then run another foreach() for each column for each row? Code:

View Replies !
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 Replies !
Recursive Function Should Return An Array Of Results
im trying to write a recursive function in php where this function should return an array of results..here is my codes:

function comfibonacci2($limit){ //using recursive function
  if ($limit <= 1){
    return 1;
  }
  return (comfibonacci2($limit-1) + comfibonacci2($limit-2));
}

this is actually a fibonacci function. i want it to run same as its iterative function :

function comfibonacci($limit,&$fib){ //using iterative function
  $fib[0]=1;$fib[1]=1;
  for ($i=2; $i<=$limit;$i++){
    $fib[$i]=$fib[$i-1] + $fib[$i-2];
  }
}

can anyone correct my recursive codes?
thanks c",)

View Replies !
Sorting An Array - Sort These Results According To Their Relevance.
I'm trying to make my own search page for my website and I have it gathering correct results exactly as it should, but I'd like to find a way to have it sort these results according to their relevance (makes mroe sense of course).

As it is now, it is simply pulling them from my database newest-to-oldest. The array elements are compiled like this..

type_of_item.id_#_of_item.hits_for_item.data

..so you can see that I have them all seperated by periods, then to print the data I just get the length that it is from the left and echo it out. I have all of that working, but I need to find a way to sort my array by the 3rd period seperated part...the hits. I want the items with the most hits at the top.

View Replies !
Limit Number Of Results Displayed From A Multidimensional Array
The closest I've come to finding a thread that solves this problem is
"MYSQL_FETCH_ARRAY without using while " ... I think it was in the database forum.

If I pull a bunch of calendar events out of a MySQL table, I will have a variable number of events per day. I can put these into a multidimensional array (Say, $$ResultArray[$DATE][] All the sorting by date and time has been done by the original SELECT query.

Once I have this array, I know I can show the whole thing with a FOREACH loop: Code:

View Replies !
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.

View Replies !
Array Results Output On Online As Opposed On Separate Lines
How do i get to echo details on oneline as opposed to the next line.

$car=array("red", "green", "white", "blue", "orange");
foreach $car as $color) {

echo "$color<BR/>";

I dont want the results on separate lines but on the same line with commons...

View Replies !
Recursive Function - How To Save The Results From All The Loops And Return Them All As An Array.
I have this recursive function that seems to get what I am looking for when I echo from the function but I don't understand how to save the results from all the loops and return them all as an array.

I tried a few ways which I removed from the code to clean it up but none of them even came close to working. Code:

View Replies !
MySQL No Results
I've been pulling my hair out of this one, basically I have a query which will match if a deadline date is reached or past. and basically if i use PHP I can get the queries correctly.  But because of the pagination scripts i'm running I need it to work in mysql

Heres my query:
$result = mysql_query("SELECT * FROM `intranet_accounts_tickets` WHERE `recipients_account_id`='".$_SESSION['intranet_user_id']."' AND `ticket_closed`='0' AND `ticket_deleted`='0' /*AND `ticket_deadline_date` < '".date("j/m/Y, H:i:s")."'*/ ORDER BY `ticket_deadline_date` DESC LIMIT $limitvalue, $limit");

View Replies !

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