Basic question..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Teck
Forum Newbie
Posts: 5
Joined: Wed Sep 19, 2007 2:01 pm

Basic question..

Post 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]
User avatar
maliskoleather
Forum Contributor
Posts: 155
Joined: Tue May 15, 2007 2:19 am
Contact:

Post by maliskoleather »

just do this

Code: Select all

if($tech == "Chris") {
    $tech1 = "chris@blah.com";
}
elseif($tech == "Karyn") {
    $tech1 = "karyn@blah.com";
}
Teck
Forum Newbie
Posts: 5
Joined: Wed Sep 19, 2007 2:01 pm

Post by Teck »

Ah thank you!

I think I've been staring at it too long my logic calculator is off lol
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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';
}
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

dont you need a database??

Post by yacahuma »

dont you need a database for all that info? Do you have m ore data than that???
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post 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.
(#10850)
Teck
Forum Newbie
Posts: 5
Joined: Wed Sep 19, 2007 2:01 pm

Post 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..
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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.
Teck
Forum Newbie
Posts: 5
Joined: Wed Sep 19, 2007 2:01 pm

Post 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?
Post Reply