Re: Problem creating array from MySql query

From: Date: Mon, 17 Feb 2003 15:31:17 +0000
Subject: Re: Problem creating array from MySql query
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-135839@lists.php.net to get a copy of this message
Thanks for taking a look at this. <?php mysql_connect (wwww, xxxx, yyyy); mysql_select_db (zzzz); $result = mysql_query("SELECT * FROM clubs WHERE id=$id"); $row = mysql_fetch_array($result); print "Reading affiliations..."; $affiliation_result = mysql_query("SELECT affiliation FROM club_affiliations WHERE club_id=$id"); print "Building array..."; $affiliations = array(); print "Populating array..."; //place affiliation data into an array that we can search later while($affiliation_row = mysql_fetch_array($affiliation_result)) { print $affiliation_row["affiliation"]; $affiliations[] = $affiliation_row["affiliation"]; } //while print "Dumping array..."; $count = count($affiliations); print "Affiliations:"; for ($i=0;i<$count;$i++) { print $affiliations[$i]; } ?> It does print the affiliations in "print $affiliation_row["affiliation"];" and it works properly (except for getting the affiliations field) if the line "$affiliations[] = $affiliation_row["affiliation"];" is commented out. Rick Emery wrote: > > It helps if you show us all your code, not just what you think we might need. > > For isntance, what does your mysql_query() statement look like? Does it have an "or > die(mysql_error()))" clause? > > ----- Original Message ----- > From: "Janyne Kizer" <janyne_kizer@ncsu.edu> > To: <php-general@lists.php.net> > Sent: Monday, February 17, 2003 9:04 AM > Subject: [PHP] Problem creating array from MySql query > > What we are trying to do is build an array from a query. I don't > understand why but this is failing on the line "$affiliations[] = > $affiliation_row["affiliation"];" Basically there are two tables in the > database, since clubs can have multiple affiliations and the > affiliations are not set in stone, there is one table only for > affiliations. We are trying to pull the data out of the table for > editing. Any tips would be appreciated. Thanks! > > $affiliation_result = mysql_query("SELECT affiliation FROM > club_affiliations WHERE club_id=$id"); > > $affiliations = array(); > > print "Populating array..."; > //place affiliation data into an array that we can search later > while($affiliation_row = mysql_fetch_array($affiliation_result)) { > print $affiliation_row["affiliation"]; > $affiliations[] = $affiliation_row["affiliation"]; > } //while > > -- > Janyne Kizer -- Janyne Kizer CNE-3, CNE-4, CNE-5 Systems Programmer Administrator I NC State University, College of Agriculture & Life Sciences Extension and Administrative Technology Services

« previous php.general (#135839) next »