Jump to content

Database Issue


hald

Recommended Posts

Hello everyone,

 

I am currently administering a business directory that I'm having a small issue with. We have businesses and nonprofit orgs in the area separated by a 1(for business) or 2(for nonprofit) in a column labeled `type` in our database. I am trying to fix an issue the previous webmaster left. The nonprofits are linked under a separate URL(\nonprofits.php?profile=$theID) from the businesses(\directory.php?profile=$theID), but in the config.php file, only the business URL is listed, so it is used for nonprofits as well, which links to a blank page. I was trying to create an if-then statement where it would read something like:

 

if(type==1){

      $output .= "THE BUSINESS URL";}

else{

      $output .= "THE NONPROFIT URL";

}

 

However, I cannot come up with an SQL statement that will return the value in the column `type`. If anyone thinks they can help, I can explain any questions you have. Please, let me know!

 

I appreciate any help very, very much!

Link to comment
Share on other sites

That syntax is familiar to me. I was trying something like that. IS there a way I can integrate that into a for statement...something like:

 

$type1 = "SELECT * FROM table WHERE type='1'";

$type2 = "SELECT * FROM table WHERE type='2''";

 

for $type1 ($output = x);

for $type2 ($output =y);

Link to comment
Share on other sites

What we have is a (clike here to read more) link. I don't want to change any data, but the links for businesses are different than the ones for nonprofits. Currently, we have a statement that covers both, but because the nonprofits aren't linked to in the same way as businesses, it doesn't work for them. What I want to do is: for all profiles that are type 1, use one type of hyperlink, and for all type 2 profiles, use another.

Link to comment
Share on other sites

<?php
$sql = "SELECT * FROM table";
$result = mysql_query($sql) OR DIE (mysql_error());
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
	// add more variable here to get other column fields
	$type = $row['type'];
	if ($type == 1)
	{
		echo "THE LINK";
	}
	else if ($type == 2)
	{
		echo "THE OTHER LINK";
	}
}
}
else
{
echo "No rows returned.";
}
?>

 

Does that help?

Link to comment
Share on other sites

		$conn = mysql_connect('database','usrname','passwrd');
	mysql_select_db('knoxgreen', $conn);
	$sql = "SELECT * FROM directory";
	$result = mysql_query($sql) OR DIE (mysql_error());
	$length = 50;
	$paragraph = explode(" ", $string);
	if(mysql_num_rows($result) > 0)
	{
	if($length < count($paragraph)){
		for($i = 0; $i < $length; $i++){
			if($i < $length - 1){
				$output .= $paragraph[$i] . " ";
			}else{
				while($row = mysql_fetch_array($result))
				{
				$type = $row['type'];
				if($type == '1'){	
				if($searched==''){
					$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"directory.php?profile=$theID\">( click here to read more )</a></b>";
					break;
				}else{
					$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"directory.php?profile=$theID&searched=$searched\">( click here to read more )</a></b>";
					break;
				}}
			elseif ($type == '2'){$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"nonprofits.php?profile=$theID\">( click here to read more )</a></b>";
			break;
			}
		}}}}
		return $output;
	}
	return $string;
}

 

I think it's getting close, but it still isn't separating the two types.

Link to comment
Share on other sites

	function wordlimit($string, $theID, $searched){
	$conn = mysql_connect('********','*******','*********');
	mysql_select_db('knoxgreen', $conn);
	$sql = "SELECT * FROM directory";
	$result = mysql_query($sql) OR DIE (mysql_error());
	$length = 50;
	$paragraph = explode(" ", $string);
	if(mysql_num_rows($result) > 0){
			if($length < count($paragraph)){
				for($i = 0; $i < $length; $i++){
					if($i < $length - 1){
						$output .= $paragraph[$i] . " ";
					}else{
						while($row = mysql_fetch_array($result))
						{
						$type = $row['type'];
						if($type == '1'){	
							if($searched==''){
								$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"directory.php?profile=$theID\">( click here to read more )</a></b>";
								break;
								}else{
								$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"directory.php?profile=$theID&searched=$searched\">( click here to read more )</a></b>";
								break;
								}
							}
						elseif ($type == '2')
							{$output .= $paragraph[$i] . " ... <b><a class=\"noline\" href=\"nonprofits.php?profile=$theID\">( click here to read more )</a></b>";
							break;
							}
						}
					}
				}			
			}
		return $output;
	}
	return $string;
}

 

I hope that's better :). I've never really had to care about format (although that's probably why my code's always unorganized), so I hope this is a bit more readable.

Link to comment
Share on other sites

So you are testing locally or remotely? did you upload the correct file?

 

I honestly don't see anything in your code that would make $type get set to 1 for every instance. You said that you looked at the data in phpMyAdmin and you can plainly see 2 as a value. Maybe someone else will read this thread and a new pair of eyes will find something I can't.

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.