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.





Changing Array Format From Result Of MySQL


here is what MySQL returns in a visual way..

game_id | team_id | stat_id
1 | 1 | 1
1 | 2 | 3
1 | 3 | 7
1 | 3 | 6
2 | 1 | 1
2 | 4 | 3

in records with the same game_id, there will be no repeating team_id
in records with the same team_id, there will be no repeating stat_id

so, after I got the query, I made them into this format

PHP Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Changing Date Format To Mysql Default Format
i hve a date variable in mm-dd-yyyy format how can i change it to mysql default format i.e., yyyy-mm-dd format ...

View Replies !
Changing Date Format In MySQL
How can I change the way MySQL displasy the date format on my php page? At the moment it displays like YYYY/MM/DD and I want it to display DD/MM/YYYY... Any ideas?

View Replies !
How To Convert MYSQL Data Result To Csv File Format.
How to convert MYSQL data result to csv file format.

View Replies !
Mysql Result Into Array?
I have a shopping cart script sending info to a processor. I need to send the qty's and item name's in some sort of string via a single variable to the process form.
i.e. (3) Hipster Turnips, (6) Butter Milk Baby Brains, (2) Super Freaks Code:

View Replies !
Mysql Result Set As An Array
the question is, is there a way of assigning each value returned from the sql query and assinging them to a single array. for example i have a a query like so;

$table = "sales_table";
        
$query = "select treatments from $table where
date between  ད/08/2006' and ཕ/08/2006'";
$result = mysql_query($query);

because the values stored in the treatments field are imploded as a single string when the user submits the form the value looks like; 1, 22, 33. Code:

View Replies !
MySQL Result As Array
$db= new MySQL($host,$dbUser,$dbPass,$dbName);
$sql=("SELECT * FROM sticker_files WHERE sticker_cat_id=Ǝ'");
$catdirs = $db->query($sql);
$dirs=$catdirs->fetch()

and I need a for each loop (i think) to insert that data below:

$params = array(
'mode' => 'Jumping',
'perPage' => 3,
'delta' => 2,
'itemData' => array(****RESULTS HERE AS COMMA SEPARATED string)
);

View Replies !
Mysql Result To Array
I have this query, it gives the suspected information in myphpadmin:

select listid, count(*) from table1 group by listid

How do I put this the result into an array in php? I have problems with the
count(*) field

View Replies !
Array With MySQL Result
//MAIN FLOW
$counter = 0;
$sql[$counter] = "SELECT * FROM category WHERE parent = 0 ORDER BY parent";
$result[$counter] = mysql_query($sql) or die(display_and_log_error("SQL ERROR: ".__LINE__));
while($myrow[$counter] = mysql_fetch_assoc($result[$counter])){
echo $myrow[$counter][category_name];
...

View Replies !
Replacing Array With Mysql Result
I wanted to repalce the following line of code $data = array(40,21,17,14,23); with

for($i=0;$i<$numrows;$i++)
{
//print(mysql_result($result,$i,2));print("<br>");
array_push($data,mysql_result($result,$i,2));}

where mysql_result($result,$i,2) is the value and when i print it displays the values. But $data array is the Y axis value for drawing a chart. Here I wanted to replace the hard coded value with values from mysql but the second code does not function. Does anybody have idea how can I replace the $data array or what may be the problem with my coding The first one works but the second one does not work but in both cases it does not display any error.

View Replies !
Sort A Mysql Result According To A Php Array
Hi everybody !
I have a question for the gurus ;+)
I have to arrays :

PHP Code:




$id = array(45,9,21);
$pos = array(3,1,2);






I select in my mysql table using the ids :

PHP Code:




$sql = "SELECT * FROM MyTable WHERE id IN(".implode("",$id).")";






and I now want to sort the result according to the $pos array.
Is there a way to do this directly in mysql ?
If not, what would be the smartest way to do it in PHP ?
Because I would prefer NOT to do the following :

PHP Code:




while ($t = mysql_fetch_array($ret)) {
    $a_field1[] = $t["field1"];
    $a_field2[] = $t["field2"];
    $a_field3[] = $t["field3"];
    $a_field4[] = $t["field4"];
...
}
array_multisort($pos,$a_field1,$a_field2,$a_field3,$a_field4)






I fear it could be a very time consuming process when there is a lot of results and a lot of fields. But may be the no other solution...

Thanks

View Replies !
If Result Of Mysql Query Is Only One Row/column, Why Use An Array?
If I'm doing a very specific select statement, which I know will only ever return one value, can I get that resulting bit of data without storing it in an array or object?
If not, is mysql_fetch_array() the fastest method for getting this one value?

View Replies !
MySQL Result To Real Array In Function
I'd like to create a function which input is the result of a mySQL
query.
The output should be exactly the same, only not a mySQL result array,
but a 'real' array.
So it should also get the fieldnames returned by mySQL and use those as
keys.

I can't get things to work properly: it should return a
multidimensional array,
like

$result_array[1] = array(
[field1] => field1 value,
[field2] => field2 value,
etc.
)

somehow my result is (with code below)

$result_array[1] = array(
[0] => field1 value,
[field1] => field1 value,
[1] => field2 value,
[field2] => field2 value,
etc.
)

+++++ code ++++++

$get_res= mysql_query(QUERY);

if( $res = mysql_fetch_array( $get_res ) )
{

do{

$result[] = $res;

}while( $res = mysql_fetch_array( $get_res ) );

};

foreach( $result as $key => $value ){

print_r($value);

};

View Replies !
Can I Put A Mysql Query Result Directly Into A Multidimensional Array?
I have two joined tables:

Departments - which contains the department description and a key
Positions - which contains position data

What I'm attempting to achieve is to display the department title in one table cell and then list all the positions associated with that department in the cell under neither the title. I need to generate a table two column table with as many rows as required, depending on the number of departments, which is dynamic.

Do this I'm trying to turn the result of my SQL query into multidimensional array e.g. dept = VioP positions = "designer", "engineer" etc, which I can do then use to generate the table.

I've done a search on the forum and looked around the manual and I'm stumped on how to achieve this, a point in the right direction would be greatly appreciated. The query I'm using is below. PHP Code:

View Replies !
Making Mysql Result Into Multi-dimensional Array
My php problem is I want to make the result of 3 tables linked through foreign keys into a 3-dimensional array that reflects their relationship without repetition and without having to call the database more three times.

I know I'm doing a couple of things wrong, one thing for instance is initializing a variable at the end of the loop to remember the previous value s that it does not repeat itself, surely there must be a more elegant way to go about this, but I'm lost and I've been stuck on this all day. Code:

View Replies !
Changing Format
I am extracting data from a database and creating a report. The date in the database is stored in the format YYYY-MM-DD HH:MM:SS but when i display the report i just want the date to be displayed as MM/DD

View Replies !
Changing Date Format
If I fetch a date from a mysql field and the date is: 2006-01-12 00:00:00

Is there a way I can reformat it in php to lose the hr.min.sec so that I am just left with the date 2006-01-12??

View Replies !
Changing Time Format
I was looking forward to changing a string as "Apr 09" to "04/09". I first thought about switching through the months and preg_matching the day, and then I saw date() and strtotime(), but I don't really know if strtotime() will work with my input. How could I actually do this?

View Replies !
Changing Date And Time Format
Currently, the script has dates formatted in the European way (day, month, year) and time is in 24-hour mode. I want dates to be month, day, year and time in 12-hour mode. I tried changing this to fix the date:

header('Expires: ' .  gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');

To this:

header('Expires: ' .  gmdate('D, M d Y H:i:s', time() + 86400) . ' GMT');

That change had no apparent effect, so I'm not sure what to do. It's probably something really obvious and I just don't see it.

View Replies !
Format The Result Like This, 16:13:22 ?
Im pulling information from an xml file tha returns the time formatted like this 161322, how would i format the result like this, 16:13:22 ? Code:

View Replies !
Format Table With PHP Result
I have to create some kind of dynamic page, logic is next: i have integer in variable and i need to create certain number of fields based on that int. example
$variable = 6 and I need to have table with 6 fields, 4 in one row and 2 in second....my problem is how to do that, how to get new <tr> when number in bigger than 4.

View Replies !
Format Result Text Using Passthru Of System
I tried to use the Passthru and System function to resolve some whois
information.

echo passthru('whois 62.69.168.12') .'<br>'
-or-
$whois = system('whois 62.69.168.12', $retval);

It works fine, but all the result text is at one line. How can i format this
output correctly ?

View Replies !
How To Convert UK Date Format (DD/MM/YYY) To A Format That Will Be Accepted By MySQL (YYYY-MM-DD)
I am trying to work out how to convert UK date format (DD/MM/YYY) to a format that will be accepted by MySQL (YYYY-MM-DD), so far I have been almost successful by using the following:- PHP Code:

View Replies !
Format The Date And Time Entered By The User To The Mysql Format
I am trying format the date and time entered by the user to the mysql format which is: yyyy-mm-dd hh:mm:ss for example the user enters 25-8-2007 16:20:00 I want to convert it to 2007-08-25 16:20:00 and insert to the database. Code:

View Replies !
Array Explode Problem Result In A 6 Item Array
I have the following:

$BB_Basket = "basket=¦APL6007,2.00¦AVX8900,1.00¦ARCAV500,1.00";
$basket_containers = explode('¦', $BB_Basket);
unset($basket_containers[0]);
print_r($basket_containers);

This results in

Array ( [1] => APL6007,2.00 [2] => AVX8900,1.00 [3] => ARCAV500,1.00 )

Now when I try to explode further with

$basket_items = explode(',', $basket_containers);
print_r($basket_items);

This results in

Array ( [0] => Array )

This should result in a 6 item array. Any ideas what I'm doing wrong?

View Replies !
Changing An Array Name.
If I have an array called my_array1, how do I call it within a for cycle? Something like this:

for($a=1;$a<=5;++$a){
$my_array = 'my_array'.$a;
          //prints $my_array
}

I know that doesnt work, so, I tried something like the following:

for($a=1;$a<=5;++$a){
$my_array = 'my_array'.$a;
          //prints $$my_array
}

That does work with variables, but doesnt work with arrays. I know that in Java and ActionScript what I'm trying to acomplish is pretty simple, but I cant seem to find the correct syntax for php.

View Replies !
Changing Array Keys
I've looked and looked and apparently I don't know what terms I'm supposed to be looking for. Code:

View Replies !
Changing A Value Of An Element In A Two Dimensional Array
I am having a problem with array manipulation.

in my php script i am reading from a csv file.
the content of file is like this:

View Replies !
Changing Array Keys After Using Explode
I have used explode to split a string into parts but the the resulting array keys are ints...is there a simple way of changing the keys from numbers to informative values?

View Replies !
Changing Object Data In An Array Of Objects
In this sample script I create an array of objects. Print out their data
with print_r().Update their data with a sub called v_set(). Print out data
showing the chnages using print_r(). I push the altered objects into a new
array and print them out again, still see the updated data. Then I iterate
over the original array again with print_r and the objects lose the updates
and have their original data.

<?
for ($i = 0; $i < 1; $i++) {
$listingObj = new Listing;
$listings[] = $listingObj;
}

foreach ($listings as $aListing) {
echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY BEFORE VARS SET</h3>";
f_array($aListing);
}

foreach ($listings as $aListing) {
$aListing->v_set(
array(
'name' => 'Jane',
'address' => Ïã Ohce Ln.'
)
);
// HERE IS BUG: WHY DO I NEED TO PUT IN NEW ARRAY?
echo "<h3>THIS IS IN SCRIPT IN ORIG ARRAY AFTER VARS SET</h3>";
f_array($aListing);
$newArray[] = $aListing;
}

foreach ($newArray as $aListing) {
echo "<h3>THIS IS IN NEW ARRAY</h3>";
f_array($aListing);
}

foreach ($listings as $aListing) {
echo "<h3>THIS IS IN ORIG ARRAY, APPARENTLY NOT
ALTERED/UPDATED?</h3>";
f_array($aListing);
}

class Listing {
var $changedVals = array();
var $name = 'Dick'
var $address = ì« Echo Ln.'

function v_set($data){
foreach ($data as $key => $value) {
$this->$key = $value;
$this->changedVals[] = $key;
}
}
}

function f_array($array) {
echo '<pre>'
print_r($array);
echo '</pre>'
}

?>

View Replies !
Add Sql Result To An Array
I am trying to add the results of a query (specifically a particular field's value) to a new array. The result is either an empty array or the last row in the query result instead of all the rows. Code:

View Replies !
Array Result
PHP Code:

function match_username()
        {
            $connection = new db_connect;
            $connection->connect();
            $this->table  = "bs_user_member";
             $this->query  = mysql_query("SELECT username FROM $this->table");
                while ($this->result = mysql_fetch_object($this->query))
                {
                    global $uname;
                    
                    $uname = array($this->result -> username);
                }                    
        }

Should show all right?

View Replies !
Getting First Result From Array?
Trying to get the top 10 male authors from my database that works fine .. but id also like to just get the top male author too So since ive fecthed the top 10 , shouldnt i be able to get the top 1 from that? Code:

View Replies !
Format An Array
Im struggling with something probably really easy!! but just cant work it out!

I have an array that is populated like so

1, 1, 2007-08-16, 1, 2, 1
2, 1, 2007-08-16, 2, 2, 1
3, 1, 2007-08-16, 5, 6, 1
4, 2, 2007-08-16, 1, 3, 1
5, 2, 2007-08-16, 1, 5, 6

im trying cycle through this array and use the 2nd value as a group or header like below

1:
   1, 2, 1
   2, 2, 1
   5, 6, 1
2:
   1, 3, 1
   1, 5, 6

I cant get close - any ideas?

View Replies !
Xml To Array Format
i have an xml file which kind of looks like this[as an example i have kept it simple].I want to conver this xml to the array format shown below.dont know how to do it..please help.after i get this array format then it will be easy for me to insert these records into database table by iterating: Code:

View Replies !
Simple Array From DB Result
I have a simple DB query which puts a set of values into a pull-down menu as follows:-

View Replies !
Mysql_fetch_row($result) In Array
I'm generating 20 rows of textboxes in PHP. Some textboxes are pre-filled with information from mysql table. Code:

View Replies !
How To Add Function Result To Array?
The way I'd like to set up a particular set of functions is to have them either return TRUE or, for example:

$errors[type] = "Sorry, the file type is not allowed. Allowed types are ".print_array_inline($acceptedTypes).". ";

Then later, I have a foreach loop that echos each array element. However, when I echo each array element is doesn't output the whatever the print_array_inline function does.

Any suggestions?

View Replies !
Result Of Array Diff()
I'm successfully able to compare two different arrays with array_diff(). The result of this comparison is, of course, assigned to a new array. Unfortunatly (for my purposes) the array indeces of the resulting matching items are retained, yet empty:

[a][b][empty][d][empty][empty][g] - and so on.

I'm wondering if there's a built-in function that would sequentially assign all non-empty index items of my array_diff() result to a second array, like:

[a][b][d][g]

I know I can do this with a loop, but am wondering if there's already a function to handle this.

View Replies !
Skip First Result In Array
I have an array that contains both key and value. The first key/value is used to store a heading so it is not needed in the rest of the loop. How can I skip that first key/value and display the rest. Example:

$myarray = array("key1"=>"heading", "key2"=>1, "key3"=>2.......

Without knowing the key/value of the first result, how can I skip it

foreach($myarray as $k =>$v){

//if first key skip

//else continue the loop

}

View Replies !
How Do You Store An Sql Result In A Php Array?
How do you store an sql result in a php array? The array will hold, the following fields; itemid, itemname and itemdesc. I would then require, depending on the user selection to query the array by itmeid, and return the itemname.

View Replies !
Query Result To Array
i have a table with two field ID and CAPACITY. i want the ID to point to the capacity on an array

$top = "SELECT * from topics";
$db = new mysqli('localhost','root',?');
$db -> select_db('testing');

$res_top = $db->query($top);
$topics = array();
while ($row = $res_top->fetch_row())
{
$topics[$row['id']] = $row['capacity'];
}

View Replies !
Outputting Just The Result Of An Array
I'm trying to print the results of an array taken from my database.
here's my code:

$subc = array($subcdat);

print_r($subc); The problem it's outputting: Array ( [categories_name] => Spoon Boy )when I only want it to output: Spoon Boy. I'm trying to save the spoonboy as a variable to use, so I'm using the print_r function to check what it's outputting. If it's outputting correctly I'll use $subc as the variable to read from.

View Replies !
How To Fetch Result Set As An Array
I use $result_set = mysql_query($query) to get a set of rows, and then I can use mysql_fetch_array($result_set)to access each value of column in a row, but each element inside is a column value of one row.

I want to get the result as an array from $result_set so that each element of array is an ENTIRE row, so I can add or remove elements inside. Is there such function?

View Replies !
Outputting A 2D Array In A Certain Format
I have a mySQL result which is from a database of 9 columns and $x rows. I need to create a loop so that it displays the content of each field in a row before going to a new line and then displaying that row.

The reason I am doing this is to cretae a loop system for adding data to an excel sheet I have created using COM. This works fine, its just a matter of looping through the results correctly. here is the loop code I have at the minute (which isn't working correctly)
PHP Code:

View Replies !
Load Result Contents Into An Array?
Is there a way of loading an entire result set into an array without manually looping though mysql_fetch_row?

View Replies !
Moving A Query Result Into An Array
I have read all the array stuff done searches for examples, but am still not clear if there is a way to do a query from a MySQL table and move those vaules into an arry.

I am sure it can be done, but I thought I would find a function that would do it. Am I just overlooking something?

$resultID = mysql_query("SELECT DISTINCT slot FROM items");
while(list ($slot) = mysql_fetch_row($resultID)){echo"$slot";}

So anyone have a good way to move the result into some array?

View Replies !
Query Giving Array As Result
I just started PHP and getting the following error when trying to read and echo something from my DB. I get Array as an result of a working SQL query (I tested it in PHPMyAdmin SQL Query) and it should be something else. Array doesnt return in the database i selected, but still it's here.

<?
$host="localhost";
$user="xxxxxxxxx";
$password="xxxxxxxxxxx";
$dbname="mohaaleague";
$connection = mysql_connect($host, $user, $password) or die ("Kan niet verbinden");
$clan = "Belgian Fun Clan";
$db = mysql_select_db ($dbname,$connection) or die("Je Stinkt");
//SELECT clan FROM clan WHERE clan='Belgian Fun Clan'
$query = "SELECT clan FROM clan" or die("Query Mislukt");
$result = mysql_query($query) or die("Query Mislukt1");
$row = mysql_fetch_array($result, MYSQL_ASSOC) or die("Query Mislukt2");
extract($row);

echo($row. "<br>");
if ( $clan == $row )
{
echo "het werkt";
}
else
{
echo "het werkt niet";
}
$disconnect = "mysql_close";
?>

View Replies !
Reformatting An Array And Printing The Result.
I have an array called $value which, when echoed, returns [12345]. Instead, I desire to reformat this array so that it prints or echoes in the following format:

["1","2","3","4","5"].

So far, I have:

echo "&quot;" , $value , "&quot, ";  ////["1","2","3","4","5"].

This yields my desired result, but I want to encapsulate that result in a variable. Code:

View Replies !
Display Array Result Horizontally
I have two issues but i'll diplay them in two threads for clearity sake. one now and the other in a different thread. thanks for your support.

I want to display the output of the script below horizontally, say in five colums without diplaying an element twice. Code:

View Replies !
PHP Array Email Data In CSV Format
I have a web form which collects data and then does a POST action to call a PHP file which takes the data and sends it to an email address. This all works fine, but right now when I get the data in my email I get it back as follows:

Date Submitted: 7/28/07
Name: Mark Jones

I do not want the Labels with the : (I just want the data emailed) Basically what I need to be able to do is easily copy this data into an Excel file when I get it. With the labels include with the :, the data all gets put into the same column in Excel, so I need to remove the labels. I'm pretty sure I have to modify something in my code listed in Red below, but not sure what or if thats the only thing. Code:

View Replies !
Duplicating Form Elements With Array Result Set
order form with repeating element areas 1) Item: select/option 2) Quantity: input

I have a query which returns the result I want to display in area 1) which is a list of products.

I tried to setup a loop to populate the select/option with the same list as many times as needed - 4X with option to show 15x with each Item/Quantity line named with the increment of the loop. Code:

View Replies !

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