PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
langleyv
Forum Newbie
Posts: 6 Joined: Tue Aug 19, 2014 10:38 am
Post
by langleyv » Tue Aug 19, 2014 10:45 am
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++;
}
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Aug 19, 2014 11:01 am
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.
langleyv
Forum Newbie
Posts: 6 Joined: Tue Aug 19, 2014 10:38 am
Post
by langleyv » Tue Aug 19, 2014 10:18 pm
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.