glenelkins Posted November 6, 2006 Share Posted November 6, 2006 Ok the following code is taking the mick,[code]<?ob_start();session_start(); include ("db_setup.php"); //$search_for = $_POST['search_box'];$search_for = "Glen"; echo "SEARCH FOR: " . $search_for; $sql = "SELECT * FROM profiles";$result = mysql_query($sql) or die (mysql_error()); $c = 0;while ($search = mysql_fetch_array($result)) { $sql = "SELECT directory FROM weddings WHERE user_id=" . $search['user_id']; $result2 = mysql_fetch_array(mysql_query($sql)) or die (mysql_error()); if (strstr(ucwords($search['bride']),ucwords($search_for)) or strstr(ucwords($search['bridegroom']),ucwords($search_for))) { // Found the string // Check for directory if ($result2[0] == "YES") { $results[$c] = $search['user_id']; $c++; } }}echo $results[0];?>[/code]it finds the results when $result2[0] == "YES" it then adds to the $results array and increases the counter...but when it comes to the echo line at the bottom nothing is displayed...yet if i put the echo line within the nested if statements (before the $c++;) it displays them fine... Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/ Share on other sites More sharing options...
Jenk Posted November 6, 2006 Share Posted November 6, 2006 [code=php:0]var_dump($results);[/code]copy and paste output. Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120377 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 There appears to be nothing in the $results variable, it does not make sense as the search term does find an item Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120380 Share on other sites More sharing options...
Zane Posted November 6, 2006 Share Posted November 6, 2006 [quote]$result2[0] == "YES" it then adds to the $results array and increases the counter...but when it comes to the echo line at the bottom nothing is displayed[/quote]Then perhaps $result2[0] doesn't equal YES, you have no check for if it doesn'tand if that doesn't helpgo to your DB itself to the weddings tableand make sure that the directory field has a value like 'YES' or 'NO' in itIf none of the rows say YES in them, especially that particular one where user_id = whateverthen you won't get any desired output Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120388 Share on other sites More sharing options...
alpine Posted November 6, 2006 Share Posted November 6, 2006 Have you tried ob_end_flush() to output your buffer... Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120392 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 All the tables and such are fine and the results are fine, the script worked until recently, then just for some reason stopped. I havent tried ob_end_flush() i will try it now and let you know Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120397 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 ob_end_flush(); makes no difference! Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120399 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 even if i take out the line if ($result2[0] == "YES") it does not work, could it be a server issue?I just tested by putting: echo $search['user_id'] above the array line: $results[$c] = $search['user_id'], and its finding the values perfectly. Also if i put echo $results[$c] directly under $results[$c] = $search['user_id'] it displays ok as well Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120401 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 I just changed the code as follows, it seems to get stuck on the third nested If. This is really strange[code]while ($search = mysql_fetch_array($result)) { $sql = "SELECT directory FROM weddings WHERE user_id=" . $search['user_id']; $result2 = mysql_fetch_array(mysql_query($sql)) or die (mysql_error()); if (strstr(ucwords($search['bride']),ucwords($search_for)) or strstr(ucwords($search['bridegroom']),ucwords($search_for))) { // Found the string // Check for directory if ($result2[0] == "YES") { if ($header_url == "") { $header_url = "Location: index.php?page=3&userids=" . $search['user_id']; } else { $header_url .= "," . $search['user_id']; } } }}echo $header_url;[/code] Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120414 Share on other sites More sharing options...
Zane Posted November 6, 2006 Share Posted November 6, 2006 What's this supposed to accomplish btw..What's the goal outputAre you just wanting a list the directory for Glen or for every userWhat I'm getting at is you could probably do better with a JOINSELECT weddings.directory FROM weddings INNER JOIN profiles.user_id ON weddings.user_id = profiles.user_id GROUP BY weddings.user_id;i don't have anything to test that with so I can't guarentee that'll work Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120418 Share on other sites More sharing options...
glenelkins Posted November 6, 2006 Author Share Posted November 6, 2006 The output sends the header accross with all the found user ids with matching search text seperated by commas. Link to comment https://forums.phpfreaks.com/topic/26332-this-is-silly/#findComment-120427 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.