Jump to content

[SOLVED] Declaring an array of unknown size?


scott.stephan

Recommended Posts

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!

$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.

$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 :)

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 ;)

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.