scott.stephan Posted June 8, 2009 Share Posted June 8, 2009 Basically, I need an array to capture the PO num of every record that has a Status of "1". I have no idea how many records that is. I tried to do $po_array=array();, but it doesn't seem to work. Code below. I am dumb. Make me smart! I can't belive I've gotten this far: Code: $queryall="SELECT po_num FROM new_batch WHERE isStatus = 1"; $result=mysql_query($queryall) or die(mysql_error()); $counter=0; $unack=array(); while($row=mysql_fetch_array($result)){ $unack[$counter]=$row[$po_num]; echo "Counter: $counter <br/>"; echo "Row: $row[po_num] <br/>"; echo "UnAck: $unack[$counter] <br/>"; $counter++; UnAck(x) always returns nothing. I'm guessing I'm using arrays wrong (It has been a long, long time), but it's driving me crazy! Thoughts? Also, thanks a ton for the help! Quote Link to comment https://forums.phpfreaks.com/topic/161436-solved-declaring-an-array-of-unknown-size/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 8, 2009 Share Posted June 8, 2009 $row[$po_num] references a non-existant variable $po_num. You probably meant the index named 'po_num'. You should be using quotes (single-quotes whenever possible) around array index names and you should also be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you with mistakes like this one. There would have been an error concerning an undefined variable $po_num or an undefined index for $row. Quote Link to comment https://forums.phpfreaks.com/topic/161436-solved-declaring-an-array-of-unknown-size/#findComment-851936 Share on other sites More sharing options...
scott.stephan Posted June 8, 2009 Author Share Posted June 8, 2009 $row[$po_num] references a non-existant variable $po_num. You probably meant the index named 'po_num'. You should be using quotes (single-quotes whenever possible) around array index names and you should also be developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you with mistakes like this one. There would have been an error concerning an undefined variable $po_num or an undefined index for $row. Mind=Blown. I'm getting there. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/161436-solved-declaring-an-array-of-unknown-size/#findComment-851938 Share on other sites More sharing options...
gevans Posted June 8, 2009 Share Posted June 8, 2009 see if this does the trick <?php $queryall = "SELECT `po_num` FROM `new_batch` WHERE `isStatus` = 1"; $result = mysql_query($queryall) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $unack[] = $row['po_num']; } foreach($unack as $k => $v) { echo "$k: $v<br />"; } UPDATE:: I didn't see PFMaBiSmAd's post. If you want to figure this out yourself (which I strongly suggest) ignore my post Quote Link to comment https://forums.phpfreaks.com/topic/161436-solved-declaring-an-array-of-unknown-size/#findComment-851939 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.