Jump to content


MySQL and String Functions

  • Please log in to reply
2 replies to this topic

#1 fingerbob

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 16 September 2005 - 05:36 PM


I'm using the following query to return formatted infomation from a table:

SELECT SUBSTRING (`name`, LOCATE('.',`name`)+2) as newname FROM `mytable`

This query works when I use it though phpMyadmin, but I get error messages when I try to use it through php.

I've been trying to update a field in another table with the results of this query but with no success.

Can anyone help?


#2 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 September 2005 - 05:53 PM

What are the messages you're getting and can we see your code?


#3 fingerbob

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 September 2005 - 08:49 AM

Hi Ken,

My Code is


$db = mysql_connect("localhost", "user", "pass")
or die("Could not connect : " . mysql_error());

mysql_select_db("mydb") or die("Could not select database");

$result = mysql_query("SELECT SUBSTRING (`name`, LOCATE(\'.\',`name`)+2) as newname FROM `mytable`") or die('Error.....' . mysql_error());

while ($row = mysql_fetch_array($result)) {

echo $newname;
echo "<br>";}


The error message says there is
"an an error in your SQL syntax"

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users