Jump to content

[SOLVED] Need help with if statement


kts

Recommended Posts

<?php

error_reporting(E_ALL);

header('Content-Type: text/html; charset=UTF-8');

require('includes/phpListGrab.class.php');

readfile('templates/header.html');

if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$phplistgrab = new phpListGrab($_POST['passport'], $_POST['password']);
$ret = $phplistgrab->grab();

if (!$ret)
{
	switch ($phplistgrab->result)
	{
		case ERR_AUTHENTICATION_FAILED:
			echo '<p>Authentication failed.</p>';
			break;

		case ERR_SERVER_UNAVAILABLE:
			echo '<p>Failed to connect to server.</p>';
			break;
	}

	readfile('templates/footer.html');
	exit();
}

$indent = str_repeat("\t", 3);	// This is just to make the HTML pretty, the level of these elements is 3 tabs in.

echo "$indent<h3>Contacts</h3>\n\n$indent<ul>\n";

mysql_connect("x, "x", "x") or die(mysql_error());
mysql_select_db("x") or die(mysql_error());

foreach ($phplistgrab->lists[list_FORWARD] as $contact)
{

$result = "SELECT * from desinscrits WHERE mail LIKE '%".$contact['passport']."%';";
mysql_query($result);
if($result != "")
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


} else {



   echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";

}

            }


echo "$indent</ul>\n";
}
else
{
readfile('templates/form.html');
}

readfile('templates/footer.html');

?>

Link to comment
Share on other sites

Ok, i just realized i edited the code a bit and the result im getting is Resource id #8 I'm not sure why I am getting that I fixed the code a bit to

 

	foreach ($phplistgrab->lists[list_FORWARD] as $contact)
{

$result = "SELECT mail FROM desinscrits WHERE mail LIKE '%".$contact['passport']."%';";
$name = mysql_query($result);

echo $name;


if($result != "")
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


} else {



   echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";

}

            }


echo "$indent</ul>\n";
}

Link to comment
Share on other sites

Ok, i just realized i edited the code a bit and the result im getting is Resource id #8 I'm not sure why I am getting that I fixed the code a bit to

 

	foreach ($phplistgrab->lists[list_FORWARD] as $contact)
{

$result = "SELECT mail FROM desinscrits WHERE mail LIKE '%".$contact['passport']."%';";
$name = mysql_query($result);

echo $name;


if($result != "")
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


} else {



   echo "$indent\t".'<li><a href="http://msn.messanger.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";

}

            }


echo "$indent</ul>\n";
}

 

$name has to be done with a loop

 

$name = mysql_fetch_assoc(mysql_query($result));

 

then use $name[' COLOUMN NAME '];

Link to comment
Share on other sites

Thank you so very much. I love you. I have been boggling myself for hours. Thank you again. And i blanked out the mysql info purposely hehe.

 

Wait, are you sure it worked?

 

This doesnt look right either

 

if($result != "")
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


} 

 

 

Are you trying to check if the variable is empty, or the data within the coloumn? Because I can help you with that too,.

Link to comment
Share on other sites

checking if data is present, if its empty no match so it goes to the else, if its full it uses the if

 

it worked though thank you sir

 

Before you thank me, your script is acutally checking if $result = "YOUR QUERY" is equalled to $result = "".

 

It is not checking wether the information is available or not, its just checking wether the variable is empty or not.

 

change

 

if($result != "")
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


}

 

to

 

$count = mysql_query($result);

if(mysql_num_rows($count) > 0) // checks if the data has more than 1 row available
{

echo "$indent\t".'<li><a href="http://first.com/'.$contact['passport'].'">'.htmlentities($contact['friendlyname']).'</a></li>'."\n";


}

Link to comment
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.