Jump to content

SQL Query and Arrays


paul2463

Recommended Posts

Hello,

I am trying to get information from a sequel query and place it into 2 different arrays based on a test. I am pulling two values from the table valueA and valueB, if valueB is a certain number then valueA gets written to one new array and if the test fails then it is written to the other new array. here is the code:-

<?php

//create new variable arrays
$arr1 = array();
$arr2 = array();

// connect to database , create and execute query
$query = 'SELECT valueA, valueB FROM table';

$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());

// check if records were returned
if (mysql_num_rows($result) > 0)
{
//iterate over record set
[!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]while($row = mysql_fetch_row($result))
{
if ($row['valueB' == '1')
{
$arr1[] = $row['valueA']; [!--coloro:#000000--][span style=\"color:#000000\"][!--/coloro--]//will this bit work??[!--colorc--][/span][!--/colorc--]
}
else
{
$arr2[] = $row['valueA'];
}
}[!--colorc--][/span][!--/colorc--]
}
else
{
// print error message
echo 'No rows found!';
}

// close connection to MySQL server
mysql_close($connection);

?>

It seems to run ok and places something into the relevant arrays but when I try and view whats in the arrays it tells me the block numbers of the arrays but the value is blank, as though it has placed a NULL value in there....I am now confused..thanks in advance

valueA is date object valueB is a number so what I am expecting is two arrays, both with dates in them, one corresponding to a row value of ones and the other to a row value of anything else.
Link to comment
Share on other sites

thanks for the help, I figured out my problem and it was tipping urror on my behalf, when you initialise a variable called "adate" and then try and refernece a variable called "aDate" it doesnt seem to work. how daft can one person be???

(rhetorical question - no actual answer required)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.