$sql= sql query
$i=0;
while
($a2=mysql_fetc h_array($a1)){a rray_push($temp array,$a2[0],$a2['ad'],$a2[1],$a2[1]);
{
I want this array to be the value of an asssoc. array $results[$i]
$results[$i] =$temparray doesnt work
$results[$i] =$temparray[] doesnt work
$results[$i][] =$temparray doesnt work
$results[$i] =>$temparray doesnt work
then $i++;
}
so what does ? 4 12059
try so
$results[$i] .= array($temparra y)
maybe work :)
pauld wrote: $sql= sql query $i=0;
while ($a2=mysql_fetc h_array($a1)) { array_push($tem parray,$a2[0],$a2['ad'],$a2[1],$a2[1]); { I want this array to be the value of an asssoc. array $results[$i] $results[$i] =$temparray doesnt work
<snip>
Why doesn't this work?
What's the error message?
What did you expect and what's the outcome?
Try inserting these two lines at the top of your script
ini_set('displa y_errors', '1');
error_reporting (E_ALL);
Thanks. adding the error reporting gives me a load of stuff about array
indiceds not defined. i thought PHP dynamically sorted out array
lengths. is there a 'better' way to do it than just let the scriptsort
it out ?
I want my results to end up as
results[0] => date,ID,value
results[1] => date,ID,value
results[2] => date,ID,value
etc etc
( there is probably a better way of resetting the temparray but ive
not found it !)
$i=0;
while ($a2=mysql_fetc h_assoc($a1))
{$temparray=arr ay();
array_push($tem parray,$a2['ID'].$a2['date'],$a2['value']);
$results[$i] = array($temparra y);
if (isset($temparr ay)) {reset($temparr ay);}
print '<br>'.$i.':';
print_r($result s[$i]).'<br>';
$i=$i++;
}
gives
0:Array ( [0] => Array ( [0] => 2005-10-07 [1] => 350 [2] => 21 ) )
0:Array ( [0] => Array ( [0] => 2005-10-28 [1] => 473 [2] => NC2 ) )
0:Array ( [0] => Array ( [0] => 2005-10-03 [1] => 337 [2] => NC4 ) )
dont know why the $i counter is incrementing the array
pauld wrote: is there a 'better' way to do it than just let the scriptsort it out ?
Yes :)
I want my results to end up as
results[0] => date,ID,value results[1] => date,ID,value results[2] => date,ID,value etc etc
( there is probably a better way of resetting the temparray but ive not found it !)
see below (*)
$i=0; while ($a2=mysql_fetc h_assoc($a1)) {$temparray=arr ay(); array_push($tem parray,$a2['ID'].$a2['date'],$a2['value']); $results[$i] = array($temparra y); if (isset($temparr ay)) {reset($temparr ay);} print '<br>'.$i.':'; print_r($result s[$i]).'<br>'; $i=$i++;
<snip>
Don't do this!
$var++ already increments it just by itself.
You really shouldn't assign that to the same var.
Try this (can you predict the output before running the script?):
<?php
$a = 1;
$a++;
echo $a, "<br/>\n";
echo $a++, "<br>\n";
$b = $a++;
echo $b, "<br>\n";
$c = ++$a;
echo $c, "<br>\n";
?>
(*) how to put the return from the database into the $results array
<?php
// ...
$results = array(); // initialize $results
while ($a2 = mysql_fetch_ass oc($a1)) {
// this construct adds an element to the $results array
$results[] = array($a2['date'], $a2['ID'], $a2['value']);
}
// DEBUGGING
echo '<pre>'; print_r($result s); echo '</pre>';
// ...
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Charles Banas |
last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to
get some opinions and comments on it, hopefully so i can gain some
sort of insight as to why this works.
at the top of the function (which was translated from Fortran code),
among other heinous and numerous declarations, is this bit:
static float bbuff;
static int bkey;
static int buse;
|
by: Mark Smith |
last post by:
I'm trying to copy data from a 1D array to a 2D array.
The obvious thing doesn't work:
int twoDee = new int;
int oneDee = new int { 1, 2 };
Array.Copy(oneDee, 2, twoDee, 2, 2);
This causes a RankException. But the MSDN documentation says:
When copying between multidimensional arrays, the array
|
by: chris |
last post by:
Hi there,
I created a Multidimensional array of labels
Label lblMultiArray = new Label { {Label3, LblThuTotal},
{Label4,LblFriTotal} };
Now I would like to compare the values in the array, comparing the text in
Label3 and LblThuTotal and the text in Label4 and LblFriTotal.
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to help do the most basic
things.
One of the "basic" things I haven't been able to find out how to do is how
to delete an item from a multidimensional array object and resize it
afterwards.
It seems so easy to conceive of the code to delete...
|
by: xhunga |
last post by:
I have try a new version of my work.
I have put the sizes of the matrix into the matrix.
A = number of rows
A = number of columns
The first element of the matrix is A
instead of A.
You can not use the row 0, and the column 0.
| |
by: dennis.sprengers |
last post by:
Consider the following multi-dimensional array:
---------------------------
$arr = array(
array(3, 5, 7, 9),
array(2, 4, 6, 8),
array(1, 3, 5, 7)
);
function add_arrays($arr) {
for ($row = 0; $row < count($arr); $row++) {
|
by: StevenT |
last post by:
Hello,
I am trying to dynamically create a table based on the information I have in my cookie for a shopping cart. I can create it and display it and all is good.
I put the contents of the cookie into a multidimensional array and loop through the array creating rows and cells based on the information. I create TextBox's and add them to the cells for displaying the quantity.
So I want to display the quantity of an item in a TextBox and...
|
by: LittleCake |
last post by:
Hi All,
I have a multidimensional array where each sub-array contains just two
entries, which indicates a relationship between those two entries. for
example the first sub-array:
=Array
(
=30
=31
)
|
by: Slain |
last post by:
I need to convert a an array to a multidimensional one. Since I need
to wrok with existing code, I need to modify a declaration which looks
like this
In the .h file
int *x;
in a initialize function:
x = new int;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |