Jump to content

Recommended Posts

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

[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't

and if that doesn't help
go to your DB itself to the weddings table
and make sure that the directory field has a value like 'YES' or 'NO' in it
If none of the rows say YES in them, especially that particular one where user_id = whatever
then 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

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

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

What's this supposed to accomplish btw..
What's the goal output

Are you just wanting a list the directory for Glen or for every user

What I'm getting at is you could probably do better with a JOIN
SELECT 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.