Avatar of blknyella
blknyella
 asked on

PHP MYSQL QUERY

Ok, i've got the code working and a table is coming up after the exec-process runs. Issue i'm having is that i can't get the username slashed down to just the username.

i.e. - username@demo.test.com

TIA

<?php

include 'connect.php';

$part1 = $_POST['participant1'];
$part2 = $_POST['participant2'];

$query = "select fromJID, toJID, body, sentDate, from_unixtime(sentDate/1000) as msgSentDate from ofMessageArchive where fromJID like '".$part1."%' or toJID like '".$part1."%'";

$sql = mysql_query($query) or die(mysql_error());

echo "<table border='1' cellpadding='5'>";
echo "<tr> <th>Date</th> <th>From</th> <th>To</th> <th>Body</th>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($sql)){
	
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['msgSentDate'];
	echo "</td><td>";
	echo $row['fromJID'];
	echo "</td><td>";
	echo $row['toJID'];
	echo "</td><td>";
	echo $row['body'];
	echo "</td></tr>";
}
echo "</table>";
?>

Open in new window

PHPMySQL ServerSQL

Avatar of undefined
Last Comment
Derokorian

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Derokorian

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Sandeep Kothari

$str = username@demo.test.com

$uname = substr($str,0,strpos("@",$str)-1); // output : username
blknyella

ASKER
FANTASTIC MY MAN....
Derokorian

You could also do this in your mysql query as such:

$query = "select substring_index(fromJID,'@',1) as fromJID, substring_index(toJID,'@',1) as toJID, body, sentDate, from_unixtime(sentDate/1000) as msgSentDate from ofMessageArchive where fromJID like '".$part1."%' or toJID like '".$part1."%'";

Open in new window

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck