Link to home
Create AccountLog in
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

ASKER CERTIFIED SOLUTION
Avatar of Derokorian
Derokorian
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
$str = username@demo.test.com

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

ASKER

FANTASTIC MY MAN....
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