djbuddhi Posted February 15, 2008 Share Posted February 15, 2008 how to xtract the data in a sql before the || tags ex: jason || tommy || bull above text was appearing in a sql query and i want to extract jason,tommy and bull from the quey how to do it , i use php with mysql Quote Link to comment Share on other sites More sharing options...
Northern Flame Posted February 15, 2008 Share Posted February 15, 2008 <?php $host = "localhost"; // your mysql host $user = "username"; // your mysql username $pass = "password"; // your mysql password $db = "database"; // your mysql database $conn = mysql_connect($host, $user, $pass); mysql_select_db($db, $conn); $table = "table_name"; // your table name $query = mysql_query("SELECT * FROM $table")or die(mysql_error()); while($row = mysql_fetch_array($query)){ echo $row['name'] . " || "; // replace name with column name } mysql_close($conn); ?> Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted February 15, 2008 Author Share Posted February 15, 2008 hey this is not i want i want to get the data without the || , the above test is in the test field out put should be jason tommy bull Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted February 15, 2008 Share Posted February 15, 2008 Why dont use explode function or get some substrings of the resulted row? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 15, 2008 Share Posted February 15, 2008 why you got || in the database firstly..... <?php $host = "localhost"; // your mysql host $user = "username"; // your mysql username $pass = "password"; // your mysql password $db = "database"; // your mysql database $conn = mysql_connect($host, $user, $pass); mysql_select_db($db, $conn); $table = "table_name"; // your table name $query = mysql_query("SELECT * FROM $table")or die(mysql_error()); while($row = mysql_fetch_array($query)){ $result=str_repalce("||"," ",$row['name']); echo $result; } mysql_close($conn); ?> look up str_replace(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.