Jump to content

Recommended Posts

Problem:

 

I'm trying to make it so the array responds to the integer of status in the database. So, to check if it's one, I try this:

 

$get["status"]["1"] = "Message here...";

 

But, on my result, I'm just getting WWTT - And the value in the database for the ticket is 0. I'm not sure if I'm using the array correctly.

 

My full code:

 

<?php
session_start();
include("../includes/mysql.php");
include("../includes/config.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../style.css" rel="stylesheet" type="text/css" />
<title><?php echo $title; ?></title>
</head>

<body>
<div id="container">
<div id="content">
	<div id="left">
		<div class="menu">
			<?php include("../includes/navigation.php"); ?>
			<div class="menufooter"></div>
		</div>
		<?php include("../includes/menu.php"); ?>
	</div>
	<div id="middle">
		<?php
		$existing = $_POST['existing'];

		$query = mysql_query("SELECT COUNT(id),id,status,date,question,title FROM tickets WHERE id='$existing'");
		$get = mysql_fetch_assoc($query);

		if(!$existing)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>You have not enetered in a ticket ID. Please go back and do so.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		elseif($get['COUNT(id)'] < 1)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		else
		{
		$get["status"]["0"] = "Waiting for support...";
		$get["status"]["1"] = "Waiting for user...";
		$get["status"]["2"] = "Ticket Closed...";
		$get["status"]["3"] = "Ticket Opened...";

		echo 
		'
		<div class="post">
			<div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div>
			<div class="postcontent">
				<p>Title: '. $get["title"] .' - Posted on: '. $get["date"] .'</p>
				<p>Ticket Status: '. $get["status"] .'</p>
				<p>Question: '. nl2br($get["question"]) .'</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';

		}
		?>
		</div>
	</div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/
Share on other sites

You're not displaying your status properly as these variables

			$get["status"]["0"] = "Waiting for support...";
		$get["status"]["1"] = "Waiting for user...";
		$get["status"]["2"] = "Ticket Closed...";
		$get["status"]["3"] = "Ticket Opened...";

Will overwrite the value from your database . Instead of using $get['status'] name your array as $status, eg

			$status[0] = "Waiting for support...";
		$status[1] = "Waiting for user...";
		$status[2] = "Ticket Closed...";
		$status[3] = "Ticket Opened...";

Now change

					<p>Ticket Status: '. $get["status"] .'</p>

to

					<p>Ticket Status: '. $status[$get["status"]] .'</p>

Now it should echo out the correct status message depending on the value of the status field.

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1095318
Share on other sites

Thank you guys!

 

And one more question, since I don't need to create a new topic:

 

$query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' users.username='$username'");

 

How do I get it so it selects data from the table tickets where id='$existing', but I also want to get a user's (who is viewing the ID) position (rank). $username is a session. So, any thoughts on how I would do so?

 

My updated code:

 

<?php
session_start();
include("../includes/mysql.php");
include("../includes/config.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../style.css" rel="stylesheet" type="text/css" />
<title><?php echo $title; ?></title>
</head>

<body>
<div id="container">
<div id="content">
	<div id="left">
		<div class="menu">
			<?php include("../includes/navigation.php"); ?>
			<div class="menufooter"></div>
		</div>
		<?php include("../includes/menu.php"); ?>
	</div>
	<div id="middle">
		<?php
		$existing = $_POST['existing'];
		$ip = $_SERVER['REMOTE_ADDR'];
		$username = $_SESSION['user'];

		$query = mysql_query("SELECT COUNT(tickets.id),tickets.id,tickets.status,tickets.date,tickets.question,tickets.title,users.position FROM tickets,users WHERE tickets.id='$existing' OR users.username='$username'");
		$get = mysql_fetch_assoc($query);

		if(!$existing)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>You have not enetered in a ticket ID. Please go back and do so.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		elseif($get['COUNT(id)'] < 1)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		elseif($get['tickets.ip']==$ip || $get['user.position'] >= 1)
		{
		$status["tickets.status"]["0"] = "Waiting for support...";
		$status["tickets.status"]["1"] = "Waiting for user...";
		$status["tickets.status"]["2"] = "Ticket Closed...";
		$status["tickets.status"]["3"] = "Ticket Opened...";

		echo 
		'
		<div class="post">
			<div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div>
			<div class="postcontent">
				<p>Title: '. $get["tickets.title"] .' - Posted on: '. $get["tickets.date"] .'</p>
				<p>Ticket Status: '. $status[$get["tickets.status"]] .'</p>
				<p>Question: '. nl2br($get["tickets.question"]) .'</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';

		}
		else
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>This is not your ticket. You only have permission to view your tickets. Please go back.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		?>
		</div>
	</div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1095319
Share on other sites

You're not displaying your status properly as these variables

			$get["status"]["0"] = "Waiting for support...";
		$get["status"]["1"] = "Waiting for user...";
		$get["status"]["2"] = "Ticket Closed...";
		$get["status"]["3"] = "Ticket Opened...";

Will overwrite the value from your database . Instead of using $get['status'] name your array as $status, eg

			$status[0] = "Waiting for support...";
		$status[1] = "Waiting for user...";
		$status[2] = "Ticket Closed...";
		$status[3] = "Ticket Opened...";

Now change

					<p>Ticket Status: '. $get["status"] .'</p>

to

					<p>Ticket Status: '. $status[$get["status"]] .'</p>

Now it should echo out the correct status message depending on the value of the status field.

 

It doesn't work. :(

 

		$status["status"][0] = "Waiting for support...";
		$status["status"][1] = "Waiting for user...";
		$status["status"][2] = "Ticket Closed...";
		$status["status"][3] = "Ticket Opened...";

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1095747
Share on other sites

not sure that im reading this correctly  but your pulling an value from a database, to control the error message?

 

does this work?

 

<?php
//status messgaes
$get["status"]["0"] = "Waiting for support...";
$get["status"]["1"] = "Waiting for user...";
$get["status"]["2"] = "Ticket Closed...";
$get["status"]["3"] = "Ticket Opened...";

//value pulled from database i.e. $a = row['value'], from a request $a = $_GET['value']
$a =1;

echo "<p>Ticket Status: ".$get["status"][$a]."</p>";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1095760
Share on other sites

You're not displaying your status properly as these variables

			$get["status"]["0"] = "Waiting for support...";
		$get["status"]["1"] = "Waiting for user...";
		$get["status"]["2"] = "Ticket Closed...";
		$get["status"]["3"] = "Ticket Opened...";

Will overwrite the value from your database . Instead of using $get['status'] name your array as $status, eg

			$status[0] = "Waiting for support...";
		$status[1] = "Waiting for user...";
		$status[2] = "Ticket Closed...";
		$status[3] = "Ticket Opened...";

Now change

					<p>Ticket Status: '. $get["status"] .'</p>

to

					<p>Ticket Status: '. $status[$get["status"]] .'</p>

Now it should echo out the correct status message depending on the value of the status field.

 

It doesn't work. :(

 

		$status["status"][0] = "Waiting for support...";
		$status["status"][1] = "Waiting for user...";
		$status["status"][2] = "Ticket Closed...";
		$status["status"][3] = "Ticket Opened...";

Get rid of ["status"]

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1096013
Share on other sites

You're not displaying your status properly as these variables

			$get["status"]["0"] = "Waiting for support...";
		$get["status"]["1"] = "Waiting for user...";
		$get["status"]["2"] = "Ticket Closed...";
		$get["status"]["3"] = "Ticket Opened...";

Will overwrite the value from your database . Instead of using $get['status'] name your array as $status, eg

			$status[0] = "Waiting for support...";
		$status[1] = "Waiting for user...";
		$status[2] = "Ticket Closed...";
		$status[3] = "Ticket Opened...";

Now change

					<p>Ticket Status: '. $get["status"] .'</p>

to

					<p>Ticket Status: '. $status[$get["status"]] .'</p>

Now it should echo out the correct status message depending on the value of the status field.

 

It doesn't work. :(

 

		$status["status"][0] = "Waiting for support...";
		$status["status"][1] = "Waiting for user...";
		$status["status"][2] = "Ticket Closed...";
		$status["status"][3] = "Ticket Opened...";

Get rid of ["status"]

 

If I get rid of status, it wont know what I'm trying to grab from the database...

 

<?php
session_start();
include("../includes/mysql.php");
include("../includes/config.php");

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="../style.css" rel="stylesheet" type="text/css" />
<title><?php echo $title; ?></title>
</head>

<body>
<div id="container">
<div id="content">
	<div id="left">
		<div class="menu">
			<?php include("../includes/navigation.php"); ?>
			<div class="menufooter"></div>
		</div>
		<?php include("../includes/menu.php"); ?>
	</div>
	<div id="middle">
		<?php
		if(!$_POST['existing'])
		{
		$existing = $_GET['existing'];
		}
		else
		{
		$existing = $_POST['existing'];
		}

		$reply = $_POST['answer'];
		$ip = $_SERVER['REMOTE_ADDR'];
		$username = $_SESSION['user'];

		$query_user = mysql_query("SELECT position FROM users WHERE username='$username'");
		$get_position = mysql_fetch_assoc($query_user);

		$query = mysql_query("SELECT COUNT(id),id,status,date,question,title,username FROM tickets WHERE id='$existing'");
		$get = mysql_fetch_assoc($query);

		if(!$existing)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>You have not enetered in a ticket ID. Please go back and do so.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		elseif($get['COUNT(id)'] < 1)
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>The ticket ID you are trying to use doesnt exist. Please go back or submit another ticket.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		elseif($get['ip']==$ip || $get_position['position'] >= 1)
		{
		$get["status"][0] = "Waiting for support...";
		$get["status"][1] = "Waiting for user...";
		$get["status"][2] = "Ticket Closed...";
		$get["status"][3] = "Ticket Opened...";

		if($username==$get["username"])
		{
			$message = "<p><a href='view.php?close=". $get['id'] ."&existing=". $get['id'] ."'>[CLOSE]</a></p>";
		}

		echo 
		'
		<div class="post">
			<div class="postheader"><h1>View Ticket Status - ID '. $get["id"] .'</h1></div>
			<div class="postcontent">
				'. $message .'
				<p>Title: '. $get["title"] .'<br/>Posted on: '. $get["date"] .'<br/>Posted by: '. $get["username"] .'</p>
				<p>Ticket Status: '. $get["status"]['. $get["status"] .'] .'</p>
				<p>Question: '. nl2br($get["question"]) .'</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
			if(!$reply)
			{
			if(!$_GET['reply'])
			{

			echo 
			'
			<div class="post">
				<div class="postheader"><h1>Replies</h1></div>
				<div class="postcontent">
				<p><a href="view.php?reply='. $get["id"] .'&existing='.  $existing .'">Reply</a></p>
			';

			$replies = mysql_query("SELECT username,date,message FROM replies WHERE tid='{$get["id"]}'");
			while ($row = mysql_fetch_assoc($replies))
			{
				echo '<p>Username: '. $row["username"] .' Post Date: '. $row["date"] .'<br/>
				'. nl2br($row["message"]) .'
				</p>';
			}

			echo
			'
				<p><a href="view.php?reply='. $existing .'&existing='. $existing .'">Reply</a></p>
				</div>
				<div class="postfooter"></div>
			</div>
			';

			}
			else
			{
			echo '
				<div class="post">
				<div class="postheader"><h1>Post a reply</h1></div>
				<div class="postcontent">
				<p>Replying to Ticket ID '. $get["id"]. '...</p>

				<center><form action="view.php" method="POST"><table border="0">
				<input type="hidden" name="existing" value="'.  $existing .'">
				<tr><th>Reply/Answer</th><td><textarea name="answer" rows="10" cols="25" maxlength="1000"></textarea></td></tr>
				<tr><th></th><td><input type="submit" value="Submit"></td></tr>
				</center></table></form>
				</div>
				<div class="postfooter"></div>
			</div>
			';
			}
			}
			else
			{
			$date = date("m-d-y");
			mysql_query("INSERT INTO replies VALUES ('', '$existing', '$date', '$reply', '$username')");

			echo '	<div class="post">
				<div class="postheader"><h1>Posted</h1></div>
				<div class="postcontent">
				<p>Your reply has been added! <a href="view.php?existing='. $existing .'">Return to Ticket</a></p>
				</div>
				<div class="postfooter"></div>
			</div>
			';
			}
		}
		else
		{
		echo 
		'
		<div class="post">
			<div class="postheader"><h1>Error</h1></div>
			<div class="postcontent">
				<p>This is not your ticket. You only have permission to view your tickets. Please go back.</p>
			</div>
			<div class="postfooter"></div>
		</div>
		';
		}
		?>
		</div>
	</div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1096508
Share on other sites

You've got it all wrong.

			$get["status"][0] = "Waiting for support...";
		$get["status"][1] = "Waiting for user...";
		$get["status"][2] = "Ticket Closed...";
		$get["status"][3] = "Ticket Opened...";

Here you're overwriting the value coming from your database ($get['status']) as you're redefining the variable $get['status'] to an array, variables with the same name cannot store two different values.

 

This is why I suggested you to define your various status messages within a separate array ($status), as I posted earlier

			$status[0] = "Waiting for support...";
		$status[1] = "Waiting for user...";
		$status[2] = "Ticket Closed...";
		$status[3] = "Ticket Opened...";

 

Now the variable $get['status'] holds the array index that corresponds to a status message within the $status array. To display the status message you'd use

echo $status[$get['status']];

 

So if $get['status'] is set to the value of 2, then the above will display "Ticket Closed...", if it was set to 1 then it'll display "Waiting for user..." etc.

Link to comment
https://forums.phpfreaks.com/topic/209835-array-for-status/#findComment-1096562
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.