Jump to content

Storing MYSQL values into an Array


truegilly

Recommended Posts

Hi Guys  :D

 

wonder if anyone would be kind enough to help me ?  :P

 

Ive got a basic MYSQL query that is returning data and i want to store it in an indexed array so i can get at the individual values easily.

 

in my code i have used the list() function.

 

heres my code....

 

$query3 = "SELECT VC10_Risk_Id, Risk_Name, Confirmation_Description FROM vc10_risk WHERE RAFPerId = '$userid' AND Confirmed = 'yes'";
$result3 = mysql_query($query3) or die('Query failed: ' . mysql_error());

while ($row3 = mysql_fetch_row($result3)) {
	echo"<table width='100%' border='1' >";
	echo"<tr>";
	while (list($fieldColumnName, $fieldDbValue) = each ($row3))
			{
			echo"<td class='style2'><a href='VC10_Risk_display.php?prevVal=$fieldDbValue'>$fieldDbValue</a></td>";
			}
	echo"</tr>";
	echo"</table>";
}

 

each time the page iterates through the while loop, 3 values are returned. Is there a way i can store the 3 values in an array every time an iteration occurs ?  ???

 

the while loop, loops through twice, returning 6 values in total. I would like to store each of the 6 values in an array.

 

many thanks  :D

 

Truegilly  :-*

Link to comment
https://forums.phpfreaks.com/topic/43157-storing-mysql-values-into-an-array/
Share on other sites

try

<?php
$query3 = "SELECT VC10_Risk_Id, Risk_Name, Confirmation_Description FROM vc10_risk WHERE RAFPerId = '$userid' AND Confirmed = 'yes'";
$result3 = mysql_query($query3) or die('Query failed: ' . mysql_error());

$results = array();

while ($row3 = mysql_fetch_row($result3)) {
    $results[] = $row3;
}

// view the array
echo '<pre>', print_r($results, true), '</pre>';
?> 

Hey thanks for that !!  :D

 

this is what was returned...

 

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => Leona not starting 100% of the time
            [2] => testing
        )

    [1] => Array
        (
            [0] => 6
            [1] => Issue with mess heating
            [2] => I agree the mess is well cold, ill get an engineer to sort it out next week
        )

    [2] => Array
        (
            [0] => 10
            [1] => issue with slow computers
            [2] => we are getting new computers in very soon
        )

    [3] => Array
        (
            [0] => 12
            [1] => test risk
            [2] => ok thanks for your imput
        )

)

 

one last question.... If i wanted to get the value from [3] and [1] which is 'test risk' how would i do that in PHP ?? would it be something like Array[3][1] ?

 

thank you so much  :-*

 

Truegilly

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.