Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array problem

Status
Not open for further replies.

Jamfool

IS-IT--Management
Apr 10, 2003
484
GB
<?php require_once('Connections/jxpDREAM.php'); ?>

<?php
mysql_select_db($database_jxpDREAM, $jxpDREAM);
$query_data_grab = "SELECT `data` FROM datadump";
$data_grab = mysql_query($query_data_grab, $jxpDREAM) or die(mysql_error());

while ($row = mysql_fetch_array($data_grab, MYSQL_BOTH)) {
printf ($row["data"]);
}

mysql_free_result($data_grab);
?>

ok this uses mysql_fetch_array to grab the data and stick it into an array.(then prints it just to make sure its there) However how do I go about assigning it to an array variable?
like this-->

$vCht4 = array(60,40,20,34,26,52,41,20,34,43,64,40);

so that my sql data is assigned to the $vcht4 array variable as above...
This doesnt work-->
$vCht4 = mysql_fetch_array($data_grab);

(Any links to array handling php/sql greatly received)
 
Code:
while ($row = mysql_fetch_array($data_grab, MYSQL_BOTH)) { 
       $myarray[] = $row["data"]; 
   }

will place the data into an array called $myarray



Bastien

Cat, the other other white meat
 
Remember that a result from a SQL query returns record by record. The decision you have to make is if you want to use a temporary variable to store the column values of each record or if you can actually write your code that you process one row at a time.
If you are planning on iterating the array you create then that's a waste of resource and time, since you can just step through the result set without having to use any temporary variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top