Jump to content

Looping SQL Data into variables with manual arrays


iyeru42

Recommended Posts

Another issue, but it focuses on two variables, one dependant off of a previous one.

	// Load Style Configs...	// Get the default style first!	$sql2 = mysql_query("SELECT `name`,`id` FROM `styles` WHERE `default`='1'");	$row2 = mysql_fetch_array($sql2);		// Grab The style configs for that style.	$sql3 = mysql_query("SELECT `content`,`name` FROM `style_config` WHERE `styleid`='{$row2['id']}'");		$style_cfg = Array();		while($row3 = mysql_fetch_array($sql3)){		$style_cfg[$row3['name']] = $row3['content'];	}		$CFG['style']['table']['bgcolor'] = $style_cfg['tbl-bg'];	$CFG['style']['table']['cella']   = $style_cfg['tbl-cella'];	$CFG['style']['table']['cellb']   = $style_cfg['tbl-cellb'];

These three output blank. Not sure how to modify the loop above to make it work with this. Because, editing it like below...

	// Grab The style configs for that style.	$sql3 = mysql_query("SELECT `content`,`name` FROM `style_config` WHERE `styleid`='{$row2['id']}'");	while($row3 = mysql_fetch_array($sql3)){		if($row3['name'] == "tbl-bg")			$CFG['style']['table']['bgcolor'] = $row3['content'];		else if($row3['name'] == "tbl-cella")			$CFG['style']['table']['cella'] = $row3['content'];		else if($row3['name'] == "tbl-cellb")			$CFG['style']['table']['cellb'] = $row3['content'];	}

still outputs the three as blank. Although I don't really need it right now, since I'm going the roundabout way...

	// Grab The style configs for that style.	$sql3 = mysql_query("SELECT `content`,`name` FROM `style_config` WHERE `name`='tbl-bg' OR `name`='tbl-cella' OR `name`='tbl-cellb' OR `name`='page-bg' OR `name`='forum-bg'");	while($row3 = mysql_fetch_array($sql3)){		if($row3['name'] == "tbl-bg") // Table BG			$CFG['style']['table']['bgcolor'] = $row3['content'];		else if($row3['name'] == "tbl-cella") // Cell A			$CFG['style']['table']['cella'] = $row3['content'];		else if($row3['name'] == "tbl-cellb") // Cell B			$CFG['style']['table']['cellb'] = $row3['content'];		else if($row3['name'] == "page-bg") // Page BG			$CFG['style']['page']['bgcolor'] = $row3['content'];		else if($row3['name'] == "forum-bg") // Forum BG			$CFG['style']['forum']['bgcolor'] = $row3['content'];	}

but it would still be nice to know how to optimize the loop.

Link to comment
Share on other sites

These three output blank. Not sure how to modify the loop above to make it work with this. Because, editing it like below...still outputs the three as blank.
It should be obvious that the database query isn't returning any results. If it was, then they wouldn't be blank. Check your query.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...