what will be the output of below queries if $option='name'
where 'name' is a coloumn name of a database table which contains the value "GHTY_bbbb"

1.LOCATE('_', '$option');
2.SUBSTR('$option',0,LOCATE('_', '$option'));

i need to fetch the value before "_" from "GHTY_bbbb".if any error in above query please provide me the correct query.


thanks

Recommended Answers

All 3 Replies

Why don't you try php code.

<?
	$temp = explode('_', $option);
	unset($temp[count($temp)]);
	$option = implode('_', $temp);	
?>

Here is your query.

SELECT name,SUBSTRING(name,1,LOCATE('_',name)-1) FROM `student`
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.