ManOnScooter Posted October 25, 2007 Share Posted October 25, 2007 I get just 1 value for the select query... I just want to display the returned value Where did i go wrong ?? <?php $con = mysql_connect("localhost","root","administrator"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT details FROM test where first_name like "%Scooter%""); $row = mysql_fetch_row($result); echo $row; mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/ Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 i am also new to php. You have return the value correctly as far as i can see. Are you sure there is more than one record containing the characters 'scooter'. Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377726 Share on other sites More sharing options...
rajivgonsalves Posted October 25, 2007 Share Posted October 25, 2007 Please use echo $row[0]; Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377728 Share on other sites More sharing options...
ManOnScooter Posted October 25, 2007 Author Share Posted October 25, 2007 yes, there is only 1 record !! Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377729 Share on other sites More sharing options...
ManOnScooter Posted October 25, 2007 Author Share Posted October 25, 2007 Rajiv, did that.. same error Could you give me a sample code, to try it? Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377731 Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 well thats why you only get one result back. Do you want to display all the information of any record that has scooter in it? What are you exactly wanting from the result? Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377732 Share on other sites More sharing options...
ManOnScooter Posted October 25, 2007 Author Share Posted October 25, 2007 adam, all i need to display is the data in the "details" column. The query returns only one row and I want to display only data from "details" column. Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377733 Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 if you just want everything from the details column with no search creteria just do <?php $con = mysql_connect("localhost","root","administrator"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT details FROM test); $row = mysql_fetch_row($result); echo $row; mysql_close($con); ?> i think that will return everything from the details column. I am not sure as i cant test it as i am at work Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377742 Share on other sites More sharing options...
ManOnScooter Posted October 25, 2007 Author Share Posted October 25, 2007 adam, that dint work.. This one worked <?php $con = mysql_connect("localhost","root","administrator"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $result = mysql_query("SELECT details FROM test WHERE first_name LIKE '%scooter'"); while($row = mysql_fetch_array($result)) { echo $row['details']; } mysql_close($con); ?> is there a way to do it without the while loop?? Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377746 Share on other sites More sharing options...
adam291086 Posted October 25, 2007 Share Posted October 25, 2007 like i said i am new to this. I dont this you can do it without the while loop. This is because the while loop is saying that while there is information in the table to be displayed echo it. All tutorials i have looked at always have the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377750 Share on other sites More sharing options...
ManOnScooter Posted October 25, 2007 Author Share Posted October 25, 2007 ok, I guess i got it.. Thanks anyways... Quote Link to comment https://forums.phpfreaks.com/topic/74717-solved-where-did-i-go-wrong-new-to-php/#findComment-377755 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.