Page 1 of 1

Newbie Help with array from mySQL query

Posted: Tue Aug 19, 2014 10:45 am
by langleyv
Hi, I am trying to make a multi dimensional array with the results of a query and then $_post the array to another page. I am obviously missing something in creating my array. Dumb question, but can someone take a quick look and let me know how to fix this ?

Thanks

Code: Select all

$strSQL = "SELECT * FROM `t_Questions` WHERE qu_Survey_ID = '".$survey_ID."' ORDER BY RAND() LIMIT 5";
$rs = mysql_query($strSQL);

$i=0;

//Set up global entry items
$ID="";
$Survey_num=$survey_ID;
$Dealer_ID=1002;
date_default_timezone_set('America/Toronto');
$Date=date('Y-m-d H:m:s');


//Now Loop through entries to get rest of array elements

while ($row= mysql_fetch_array($rs))
{
	$count=$i+1;
	
	$surQ = $row['qu_text'];
	$surQ_number = trim($row['qu_Survey_Q_number']);
	$surMinLabel = $row['qu_bottom_label'];
	$surMaxLabel = $row['qu_top_label'];
	$showScale = $row['qu_scale_visible'];
	$showScale = trim($showScale);
	
	$questionGroup=$row['q_Q_Group'];
	
$DataToPost=array($Dealer_ID,$Survey_num,$surQ_number,"GUID",$surQ,$questionGroup,$showScale,$surMaxLabel);



	$i++;
}

Re: Newbie Help with array from mySQL query

Posted: Tue Aug 19, 2014 11:01 am
by Celauran
Create the $DataToPost array outside your loop and append to it inside the loop.

Code: Select all

$DataToPost = [];
while ($row = mysql_fetch_array($rs)) {
    $count = $i+1;
    
    $surQ        = $row['qu_text'];
    $surQ_number = trim($row['qu_Survey_Q_number']);
    $surMinLabel = $row['qu_bottom_label'];
    $surMaxLabel = $row['qu_top_label'];
    $showScale   = trim($row['qu_scale_visible']);
    
    $questionGroup = $row['q_Q_Group'];
   
	$DataToPost[] = array($Dealer_ID,$Survey_num,$surQ_number,"GUID",$surQ,$questionGroup,$showScale,$surMaxLabel);

    $i++;
}
Also, you really shouldn't be using mysql_ functions, but that's another issue.

Re: Newbie Help with array from mySQL query

Posted: Tue Aug 19, 2014 10:18 pm
by langleyv
Thanks so Much. This part works great, and ya, PDO will be the next upgrade to this OLD code I had done some time ago, after I get the demo to work.