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? Quote Link to comment 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] Quote Link to comment 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.