Jump to content

Taking multiple results from a mysql query and storing them in php variables


bruckerrlb

Recommended Posts

Hello, I'm trying to pull data from my mysql query, which I know how to do, but I'm finding it a hard to specifify which data I'd like to show, to give you an example, my query and display results are below

		$query_customfield = mysql_query("SELECT  * FROM `swusers` LEFT JOIN `swcustomfieldvalues` ON swusers.userid = swcustomfieldvalues.typeid") or die(mysql_error());

			while($info = mysql_fetch_array($query_customfield))
			{

				$aonumber = $info['customfieldid'];
					$aoname = $info['fullname'];
					$fieldvalue = $info['fieldvalue'];



				Print "<table><tr>";
				Print "</td><b>Name:</b> ".$aoname . "</td>";
				Print "<td><b>Number:</b> ".$aonumber . "</td> "; 
				Print "<td><b>Number:</b> ".$fieldvalue . "</td> "; 
				Print "</tr></table><br><br><br>";

			}

The main question here is how can I make the following a variable using 51 as the sample value of customfieldid

$_POST['customfieldid'] == '51'

A little update on what I'm trying to do here, can someone show me how to do it, I'm trying to take the following sql query and get the individual results from the table joins to display in a while table

		$query_customfield = mysql_query("SELECT  userid, fullname, phase.fieldvalue, aonumber.fieldvalue, das.fieldvalue, address.fieldvalue, city.fieldvalue, state.fieldvalue, zip.fieldvalue, phone.fieldvalue, custom.fieldvalue FROM `swusers` 
									 LEFT JOIN `swcustomfieldvalues` as phase ON swusers.userid = phase.typeid
									 LEFT JOIN `swcustomfieldvalues` as aonumber ON swusers.userid = aonumber.typeid
									 LEFT JOIN `swcustomfieldvalues` as das ON swusers.userid = das.typeid
									 LEFT JOIN `swcustomfieldvalues` as address ON swusers.userid = address.typeid
									 LEFT JOIN `swcustomfieldvalues` as city ON swusers.userid = city.typeid
									 LEFT JOIN `swcustomfieldvalues` as state ON swusers.userid = state.typeid
									 LEFT JOIN `swcustomfieldvalues` as zip ON swusers.userid = zip.typeid
									 LEFT JOIN `swcustomfieldvalues` as phone ON swusers.userid =  phone.typeid
									 LEFT JOIN `swcustomfieldvalues` as custom ON swusers.userid = custom.typeid
									 WHERE aonumber.customfieldid='51' AND das.customfieldid='52' AND address.customfieldid='22' AND city.customfieldid='5' AND state.customfieldid='6' AND zip.customfieldid='30' AND phone.customfieldid='7' AND custom.customfieldid='34' LIMIT 10 ") or die(mysql_error());

 

What I'd like to get is the fields such as aonumber.customfieldid, das.customfieldid, address.customfieldid and so on for each user. The while statement I have now returns a particular user, but returns the user for all the different custom fields

	while($info = mysql_fetch_array($query_customfield))
			{

				$aonumber = $info['userid'];
					$aoname = $info['fullname'];
					$fieldvalue = $info['fieldvalue'];



				Print "<table><tr>";
				Print "</td><b>Company:</b> ".$aoname . "</td>";
				Print "<td><b>variable ao number:</b> ".$aonumber . "</td> "; 
				Print "<td><b>field value:</b> ".$fieldvalue . "</td> "; 
				Print "</tr></table><br><br><br>";

			}

 

An example of the output would be

Company: Mikes
variable ao number: 27	field value: nextel



Company: Mikes
variable ao number: 27	field value: 00411497



Company: Mikes
variable ao number: 27	field value:

 

What I'm trying to do is something like this

Company: Mikes
variable ao number: 27	
fieldone: nextel
fieldtwo: value2
fieldthree: value3
field4: value4
field5: value5


Company: company2
variable ao number: 55	
fieldone: verizon
fieldtwo: value2
fieldthree: value3
field4: value4
field5: value5

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.