Page 1 of 1

Basic question..

Posted: Wed Sep 19, 2007 2:12 pm
by Teck
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello everyone!

I just have a quick question, I'm trying to get a variable $tech1 to be represented as another variable which is always changing i.e.:

Code: Select all

if($tech == "Chris") {
	$chris = "chris@blah.com";
	while($tech1 == $chris);
	} else { 
		if($tech == "Karyn") {
			$karyn = "karyn@blah.com";
			while($tech1 == $karyn);
				} else { 
					if($tech == "Kelly") {
						$kelly = "kelly@blah.com";
						while($tech1 == $kelly);
						} else {
							if($tech == "Jonathan") {
								$jonathan = "jonathan@blah.com";
								while($tech1 == $jonathan);
								} else {
									if($tech == "Hector") {
										$hector = "hector@blah.com";
										while($tech1 == $hector);
										} else {
											if($tech == "Osvaldo") {
												$osvaldo = "osvaldo@blah.com";
												while($tech1 == $osvaldo);
												} else {
													if($tech == "Scott") {
														$scott = "scott@blah.com";
														while($tech1 == $scott);
														} else {
															if($tech == "Travis") {
																$travis = "travis@blah.com";
																while($tech1 == $travis);
																}
													}  
                                                    
                                                   $to = $tech1;
Pretty sure I shouldn't use while() but I'm still relatively new to php..

Thanks in advance!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]

Posted: Wed Sep 19, 2007 2:47 pm
by maliskoleather
just do this

Code: Select all

if($tech == "Chris") {
    $tech1 = "chris@blah.com";
}
elseif($tech == "Karyn") {
    $tech1 = "karyn@blah.com";
}

Posted: Wed Sep 19, 2007 3:04 pm
by Teck
Ah thank you!

I think I've been staring at it too long my logic calculator is off lol

Posted: Wed Sep 19, 2007 3:45 pm
by Zoxive
Or you can use a switch

Code: Select all

switch($tech){
	case 'Joey': 	$tech1 = 'Joey@gmail.com'; break;
	case 'Katie':	$tech1 = 'Katie@gmail.com'; break;
	case 'Test': 	$tech1 = 'Test@gmail.com'; break;
	default:
		echo 'Error None Found';
}

dont you need a database??

Posted: Wed Sep 19, 2007 8:18 pm
by yacahuma
dont you need a database for all that info? Do you have m ore data than that???

Posted: Wed Sep 19, 2007 10:45 pm
by Christopher
I'd prefer:

Code: Select all

$tech_emails = array(
     "Chris" => "chris@blah.com",
     "Karyn" => "karyn@blah.com",
     );

$email = $tech_emails[$tech];
Even better: mock it behind a Gateway interface and you can change the datasource without having to change the code that uses the Gateway.

Posted: Fri Sep 21, 2007 12:32 pm
by Teck
Having one more issue with my script now, other than it not sending e-mails (need to configure my mail server still)

On the page that sends the e-mail I have it setup to input the data into the database, then repull the data so that I can get the ID row that goes with the submission I had just put in (which is deemed the ticket #)

Code: Select all

$sql = "SELECT * FROM $table ORDER BY time DESC";
	$fetch = @mysql_query($sql, $connection) or die(mysql_error());
	
		while($row = mysql_fetch_array($fetch) ) {
				$id = $row['id'];
				$ltagm = $row['ltag'];
				$username = $row['fname'];
				$techm = $row['tech'];
				$times = $row['time']; 
				
					if($times == $time) {
						$id = $ids;
						
				}
and the output html:

Code: Select all

echo "<html>";
													 echo "<body>";
													 echo "<br><br><br><br><br><center><img src='img/GA-AS22I.jpg'></center><br><br>";
													 echo "<font face='verdana' size='3'>";
													 echo "<center>Thank you for your submission, $fname.</center><br>";
													 echo "<center>Your ticket number is <font color='#FF0000' size='4'>$ids</font></center><br>";
													 echo "<center>A technician will contact you in the order your ticket was received.</center>";
													 echo "</font>";
													 echo "</body>";
													 echo "</html>";
which comes out looking like:

Code: Select all

Thank you for your submission, test.


Your ticket number is 45


A technician will contact you in the order your ticket was received.
And the ticket number it's pulling from the database is always '45' the database is incrementing properly..

Posted: Fri Sep 21, 2007 12:55 pm
by Zoxive

Code: Select all

echo "<center>Your ticket number is <font color='#FF0000' size='4'>$ids</font></center><br>";
You have $ids, when in your loop you have

Code: Select all

$id = $row['id'];
without the s.

And then theres this..

Code: Select all

if($times == $time) {
    $id = $ids;
Why are you setting $id, when your echo is echoing ids?

Either this was a bad/copy paste, or you missing a closeing braket also.

Posted: Fri Sep 21, 2007 2:45 pm
by Teck
Here's what I was thinking when I did that..

If I queried the database by the time submitted, it would pull the information from the table and then if it were submitted at the time from the form on the previous page--it would pull that specific record and I could then echo the id, I was trying to find a way around it pulling '45' all the time and displaying the actual ticket number for the ticket that was just submitted.

Is there a way to query the database search for the last 'x' amount of records then sort those records by something and pull the information needed out of a column?