Jump to content

[SOLVED] Brain Over Load! D= (Function use)


Twister1004

Recommended Posts

Hey everyone! How are you all doing? Well, I'm back again with another issue I can't seem to logicaly figure out (Probably thinking too hard).

 

Objective: I'm making a ticket system for a group I'm with, and what I want to do is kinda tricky. Well to me anyways.

 

Issue: I can't seem to logically think out how to increase the ticket number available by the user's name. Meaning, a person can only have a max number of 5 tickets. So I am trying to figure out in a function how to check for a user's name and increase its value.

 

File I've made. (Note: It's not the whole file. This is the part of the file that is only affecting this.)

$_SESSION['pname'] = "Twister";
function ticketNumber(){
$countID = 0;
$countTickets = mysql_query("SELECT COUNT(*) FROM `cype_tickets` WHERE `name` = 'Twister'");
while($countTicks = mysql_fetch_array($countTickets)){
	++$countID;
	return $countID;
}
}
echo ticketNumber();
$gettickets = mysql_query("SELECT * FROM `cype_tickets` WHERE `name` = '{$_SESSION['pname']}' ORDER BY `ticketid` DESC LIMIT 6")or die(mysql_error());
		$getnumber = mysql_num_rows($gettickets);
		$opentick = mysql_fetch_array($gettickets);
		while($tickets = mysql_fetch_array($gettickets)){
			echo "
			<table border=\"1\">
				<tr>
					<th>
						" . $tickets['ticketid'] . "
					</th>
					<td>
						<a href =\"?cype=main&page=ticket&a=$tickets[ticketid]&v=yes\">
							" . $tickets['title'] . "
						</a>
					</td>
					<td>
						" . $tickets['date'] . "
					</td>
					<th>
						" . $tickets['status'] . "
					</th>
				</tr>
			";
		}
	echo "
	</table>";
	if($getnumber >= 5 && $opentick['status'] == "Open"){
		echo "<b><center>Please wait until one of your tickets is solved before creating another one.</center></b>";
	} else{
	echo "
		<center>
			<input type=\"button\" value=\"Create Ticket\" onclick='parent.window.location = \"?cype=ucp&page=ticket&ticket=create\"' />
		</center>
		";
	}

 

Thank you for your help.

Link to comment
https://forums.phpfreaks.com/topic/143645-solved-brain-over-load-d-function-use/
Share on other sites

So you're just looking to have 5 not be a static variable? i.e. they can have 7 tickets or 100 tickets etc...?

 

What I do is I create a table for defaults and have a column for what you're going after. (ticketMax column = whatever maximum number)

 

Unless, you aren't going to reuse it somewhere else you could always create a variable up top for ticket max and input it in your code

 

<?php

$ticketMax = 10; // or pull the maximum from the db if you do it that way.

if($getnumber >= $ticketMax && $opentick['status'] == "Open"){

    echo "<b><center>Please wait until one of your tickets is solved before creating another one.</center></b>";

}

 

I hope that is what you were asking.

Archived

This topic is now archived and is closed to further replies.

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