blakekr Posted August 27, 2006 Share Posted August 27, 2006 I have a search function I'm trying to adapt, which uses a MYSQL_ASSOC query:[code]function search_perform($terms){ .... $result = mysql_query($sql); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $row[score] = 0; foreach($terms_rx as $term_rx){ $row[score] += preg_match_all("/$term_rx/i", $row[content_body], $null); } $rows[] = $row; } return $rows;}[/code]And when I get the values back, I'm trying to format them, but I can't seem to pull them out of the returned $rows correctly. This works:[code] $result = search_perform($q); $output = "We found " . (count($result)) . " results.<P>\n"; if (count($result)){ foreach($result as $countit) { foreach($countit as $something) { $output .= $something . "<BR>\n"; } }[/code]But I really need to grab the values in $something one at a time so I can format them.Trying variations like $output .= $result[0][0] isn't getting at the data, I'm not calling it right.Hopefully this is easy; any tips? Link to comment https://forums.phpfreaks.com/topic/18807-getting-data-out-of-a-mysql_assoc-query-newbie/ Share on other sites More sharing options...
jvalarta Posted August 27, 2006 Share Posted August 27, 2006 Well, a couple of thoughts:- You are not required to specific MYSQL_ASSOC in the mysql_fetch_array function. If you take it out, you will be able to call variables both ways, i.e. $var and $row[1]- I use the extract function (http://www.php.net/extract) and it works great.Here's a very basic example example:[code] $sql = "SELECT * FROM table"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { extract($row); }[/code] Link to comment https://forums.phpfreaks.com/topic/18807-getting-data-out-of-a-mysql_assoc-query-newbie/#findComment-81152 Share on other sites More sharing options...
blakekr Posted August 28, 2006 Author Share Posted August 28, 2006 Thanks, I greatly appreciate it and that seems to have gotten me over the hump! Link to comment https://forums.phpfreaks.com/topic/18807-getting-data-out-of-a-mysql_assoc-query-newbie/#findComment-81724 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.