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.





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 """ , $value , "&quot, ";  ////["1","2","3","4","5"].

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




View Complete Forum Thread with Replies

Related Forum Messages:
Printing Result Of Mysqli_query()
PHP Code:

<?php
$mysqli = new mysqli('localhost','root','*****','db');
$query = $mysqli->query('SELECT * FROM mytable');
?>

I was wondering as to how I would print out the result of my sql query. Let's say I have 1 row of data and 1 column. How would I get that to print out on the page.

View Replies !
Printing Database Result In Textbox...
I have a textbox with the value $name. I get the $name variable from a database. The result from the database is for example "john anderson" If I echo "$name", I get the correct result(john anderson), but when putting the result in a textbox, only the first word appears. If the result containes any spaces, the word after won't appear. what is wrong?

View Replies !
MySQL Result Printing In For-loop
I have a script that count and print every week in a selected year. Now i want to connect this to the returned result from a MySQL query. Code to explain what I am trying to accomplish: Code:

View Replies !
Only Printing First Row Of Array
Only the first row of this query is printed. The $Agent variable is gained from a previous query that a sucessfully returns an array of names. Code:

View Replies !
Printing Out Array &
I have database that stores array of filenames, for example:

ID FileNames
1 file1, file2, file3, file4
2 file1, file2, file4, file7, file9, file10

I have JS that I would like to use, but will depend on the files stored in the db. So, I would like to query and print out the the array and the corresponding filename, like so:

files[0] = file1
files[1] = file2
files[2] = file3
files[3] = file4

I can write the query fine, and tried to use foreach code, to print this out, but that did not work at all.

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 !
Array Not Printing Until Refreshed
I am working on a program that inserts values into an array. The values depend on user input. The user input is gathered in flash and then I have a php script that inserts them into an array.
In php I have an index.php and global.php. The index calls the functions stored in global. First I have a function that inserts the values into the array (StoreInfo), then the array is returned. Then I have a function that prints out the values (PrintInfo). Everything works as expected except my print function displays nothing until I refresh the browser window. Also when I print the array in StoreInfo it works without having to refresh, but I am trying to make the code easy to understand. So if I do it this way, I am making it work, but also perhaps creating a disaster for someone else!
I have been told that I should consider using serialize, but I have never used it before and I am not sure how it would help. I am already using sessions to store the array. I would really appreciate it if someone could help!!

View Replies !
Printing HTTP_POST_FILES[] Array - How?
I'm troubleshooting my first file upload script (it failed horribly) and would like to print the array of HTTP_POST_FILES to the screen (using php 4.0.3pl1).

View Replies !
Problem With Printing An Array Using While
I am a complete newbie to PHP and am currently trying to get to grips with the language. I have a database of music tracks and am trying to create a search function for them. So far I have the following code:

$sql = "SELECT * FROM `track_info`";

if($trackId!="" ¦¦ $trackName!="" ¦¦ $albumName!="" ¦¦ $artistName!="" ¦¦ $genre!="")
{
$sql.=" WHERE";

if($trackId!="")
{
$addAnd = "true";
$sql.= " `trackid`='$trackId'";
}
if($trackName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `trackname`='$trackName'";
$addAnd = "true";
}
if($artistName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `artistname`='$artistName'";
$addAnd = "true";
}
if($albumName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `albumname`='$albumName'";
$addAnd = "true";
}
if($genre!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.=" `genre`=$'genre'";
$addAnd = "true";
}
}
$result = mysql_query($sql);
while($row = mysql_fetch_array($result,MYSQL_ASSOC));
{
print_r($row);
}

The problem is that nothing from the array is getting printed out. I have taken the sql statement that is built and executed it in ems mysql and the correct rows were selected so I know the sql is fine.

Also if I take out the while loop the first row from the array is printed as expected. It just seems to be when I include the while loop that nothing at all is printed out. Would anyone have any ideas to what the problem might be?

View Replies !
Help Please With Printing $_POST Array
How can I display all of the variables held in the $_POST array on my web page?

For example:

View Replies !
Printing An Array In An Image?
helloanyone know how to print out an array in an image? does'nt seem to like this.:

$test = print_r($icons);
ImageString ($image, 2, 10, 10, $test$red);

View Replies !
Printing Out Array Keys
i'm trying to find a simple way of printing out the keys in an array
generated by mysql_fetch_array which returns a single row.

i.e.

while ($row=mysql_fetch_array($result) )
{

print out the $row keys and values

}

is this possible?

View Replies !
Printing An Array Using An Index?
I have to print an ACH file from an array I will recieve. I recieve this array through a function then I have to print this array to a file called "ACH.txt". The ACH file is broken down like this.

position 01-017 is 1st record to be printed

position 018-30 is 2nd record to be printed

position 31-44 is 3rd record to be printed

etc.

I was thinking psuedo code like this Code:

View Replies !
Printing An Array From A Form
I have a form setup and I'm passing the values to a php file. I'm trying to trouble-shoot by printing the array that I'm getting from the form like so:

if($_GET){
$array = $_GET;
}else if($_POST){
$array = $_POST;
} else {
echo "You must Access this file through a form."; // If someone accesses the file directly, it wont work :)
}

echo "{$array[&#392;']}";
echo "<br>";

Will this print the value in the key=2 of the array (of the 3rd value in array) created from the GET or POST functions? Because I can't get it to print any value from the array.

View Replies !
Printing From A Multidimentional Array
I have a multidimentional array like below. How do I just print out the second array from the three in the main array? Code:

View Replies !
Printing An Array Minus Certain Data?
I have a list of email addresses in a variable. There could be 5, there could be 500, and they're all mixed around in no certain order..

$mailing_list = "mail1@mail.net, mail2@mail.net, mail3@mail.net, mail4@mail.net";
$arr = explode(", ",$mailing_list);

is there a way to print $arr, specifically leaving out one of the email addresses? Say if I wanted to print everything in the $mailing_list contents EXCEPT mail2@mail.net, how would I go about it?

View Replies !
Printing From A Multi-dimensional Array
I have to create a multidimensional array that data for a bank will be stored in then from that array I will print it. My boss said to first program it like i am recieving the array. Then later he will have me create the array.

Order multidimensional Array I will recieve will be arranged in and the printed like this. Code:

View Replies !
Question About Printing A Multidimensional Array
I have a huge array that I need to print out. The print_r works except that it actually prints out the locatin within the array ie:

Array ( [0] => 1971 EXTS
[1] => ddd
[2] => abc
[3] => def
[4] => ggg
[5] => bbb
Array ( [0] => 1971 EXT
[1] => bscc
[2] => sddd
[3] => d3ddc

However, I want to print out the entire array without the [2] => part of it. But this is a huge multidimensional array, so I'm not sure exactly how to do that. Code:

View Replies !
Printing Our An Array On Multiple Pages
I have a multi dimensional array that I would like to print out on multiple pages, 10 elements at a time. Here is what I grab from my SQL -

$q="SELECT * FROM print_notes ORDER BY effective_date DESC";
$rez=mysql_query($q) or die (mysql_error());

I then proceed to iterate through the array printing out various elements...

while ($i = mysql_fetch_array($rez)

Now I want only 10 elements per page and am unsure how to go about this... I was thinking perhaps of adding a count like:

 while ($i = mysql_fetch_array($rez) AND $num < 10) {

                                $num++;
But I don't know how to start the next page at the 11th element in the array.

View Replies !
Help Reformatting String
I would like to take the following...watch carefully...almost like a puzzle:

ABCDEFGHIJKLMN
and rework it to be
EFGH-CD-AB IJ:KL:MN

Can someone help me on this please.

View Replies !
Printing Out An Associative Array - Whats Wrong?
I have this code segment:

$query = "Select * from Payments order by CustID";
..
.. /* execute the query */
..
if (ora_exec($cursor))
{
$recordset=array();
while (ora_fetch_into($cursor,$recordset,ORA_FETCHINTO_N ULLS|
ORA_FETCHINTO_ASSOC))
{
echo $recordset["CustID"]."<BR>";
echo $recordset["Amount"]."<BR>";
}
}

Gives me the following error
Notice: Undefined index: CustID
Notice: Undefined index: Amount

The table Payments has only CustID and Amount as attributes. is my
usage of the array offset incorrect?

View Replies !
Reformatting Telephone Numbers
I am  uploading a csv file into mysql, but I need to enter the telephone number without the hyphens. I basically need the telephone number to be stored in mysql db like this xxxxxxxxx instead of xxx-xxx-xxxx.  What can I change to fix that?  Here is the code:

View Replies !
Reformatting Dates In A Txt File
I have a personal thing I'm trying to fix. I just need some help in the right direction to code it myself but I'm unsure of where to start. I have a canadian version of quicken but I download aussie bank details.

Basically I'm running into trouble because CA Quicken thinks dates are MM/DD/YYYY whereas the Aussie banks give me dates in the txt file which are DD/MM/YY

Here is a sample of a typical txt file I get Code:

View Replies !
& WYSIWYG Reformatting Problem
I've been fruitlessly searching for months for a wysiwyg with the following deceptively simple criteria:

-open source (read:free)
-ftp integration
-wysiwyg that WONT ruin my php header/footer system by surrounding each page with HTML BODY and other annoying tags.

The only editor I know that doesn't add annoying/unnecessary markup to php files is Dreamweaver, but that is $$ and I don't want to charge my clients for that.

View Replies !
Reformatting Date: 20060123 To January 23, 2006.
I'm stumped and don't know how to handle transferring a yyyymmdd string to a long-formatted date. I have a date field in the YYYYMMDD format and need to transfer it to Month Day, YYYY.

View Replies !
Reformatting Data In MySQL Database And Stripping The String
I have imported data via ODBC into MySQL and one of these fields is the web address. now due to the fact that MS Access formates the web address string differently, it has imported like so: www.acordis.com#http://www.acordis.com#

I am initially looking to reformat this to the standard web address in the field. The second part is to strip this address and output the domain name into a separate field in the same table. i.e. from http://www.acordis.com i am looking to add acordis.com to another field called domain. Does anyone have any suggestions on how i may approach this?

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 !
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 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_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 !
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  &#3921;/08/2006' and &#3925;/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 !
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 !
MySQL Result As Array
$db= new MySQL($host,$dbUser,$dbPass,$dbName);
$sql=("SELECT * FROM sticker_files WHERE sticker_cat_id=&#398;'");
$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 !
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 !
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 !
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 !
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 !
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 !
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 !
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 !
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 !
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 !
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