Jump to content

[SOLVED] trying to split an email database query into 2 sections


Recommended Posts

Hello everyone,

 

I had a pretty thorough look around this sites Tutorials, Code snippets and the like but I still can't see to find the answer to my question so I am hoping that someone may be able to assist me.

 

In brief, I am trying to split an email address coming in from a database ($result[2]) into 2 parts: part_a will be all the text before the @ symbol and part_b will be everything after the @ symbol. I have found many references to validating an email but not spliting an email database query. I do not know, and can not seem to find, the proper syntax for this.

 

The idea is to put part_a and part_b (see line 24) into an existing email scramble script (see below). The script works fine up to this point. At the moment it is displaying the email address ($result[2]) twice since I have part_a and part_b as the same.

 

Any guidance would be appreciated. Many thanks!

 

Newbie Zeddeh

----- start code ---------

<?php #memberinfo.php

 

/**

This program accesses a mysql database where it retrieves and displays member

information.

*/

 

require_once ("classes/HtmlTemplate2.class");

require_once ("../../config2.inc");

 

/**SET VARIABLES**/

if($_GET['pa'] == "1") {

$main_page = new HtmlTemplate2 ("php_templates/memberinfo_private.html"); // Create an instance.

}else{

    $main_page = new HtmlTemplate2 ("php_templates/memberinfo.html"); // Create an instance.

    }

   

    //GATHER CONTENT

$query = "SELECT * FROM surveyor where comm_no=".$_GET['member_id']."";

$query_result = mysql_query ($query, $db_connection) or die (mysql_error());

$num_rows = mysql_num_rows($query_result);

$result = @mysql_fetch_array ($query_result, MYSQL_NUM);

 

//this is where I want to split the incoming email address

$part_a = $result[2];

$part_b = $result[2];

 

//FILL TEMPLATES

$main_page->SetParameter("CSS", "class=\"memberInfoLeft\"");

$main_page->SetParameter("CSS2", "class=\"memberInfoRight\"");

$main_page->SetParameter("CSS3", "class=\"memberInfoCenter\"");

$main_page->SetParameter("NAME", $result[5]);

$main_page->SetParameter("EMAIL", "<script>function escramble(){

var a,b,c,d

a='<a href=\"mai'

b='$part_a'

c='\">'

a+='lto:'

b+='@'

d='</a>'

b+='part_b'

 

document.write(a+b+c+b+d)

}

 

escramble()</script>");

// original email query below

//$main_page->SetParameter("EMAIL", $result[2]);

 

$main_page->CreatePage();

 

exit;

?>

----- end code ---------

It should be as simple as using the explode() function in conjunction with the list() function...

 

<?php
$email = "huggiebear@domain.com";
list($before, $after) = explode('@', $email);
?>

 

Regards

Huggie

Hello Huggie,

 

Yep, you're right!

 

It is that simple. I had tried using the "explode" function before but it seems I was trying to make it to complicated.

 

Much appreciated for your help and quick response!

 

Gracias!

 

Zeddeh

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.