Obsession Posted February 22, 2009 Share Posted February 22, 2009 Say for instance, I want to pull out the path of an image stored in the database, by inputting said image's name in the search form? I know I can pull the whole line out with SELECT * FROM but, if I replace the * with any of the database column names I get answer "Resource ID #3" up to "Resource ID #5" (I want to pull out 3 fields, using the name to get the right row. Possible? I know my English isn't perfect, not my mothertongue This si the code- <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); }; mysql_select_db("CriminalDatabase", $con); $CrimName=$_POST['CrimName']; echo $CrimName; $CrimRes = mysql_query("SELECT * FROM criminals WHERE CrimName='$CrimName'"); if (!$CrimRes) { die('Error: ' .mysql_error()); } else echo "Successful Query!"; echo "<div id='CrimImg'>"; echo $CrimRes; echo "</div>"; mysql_close($con); ?> Now, the echo "Successful Query!" prints when I run this code...Anbd where I told it to print the value of the $CrimNameit prints, yet the result of the query is "Resource id #3"... Link to comment https://forums.phpfreaks.com/topic/146383-solved-how-to-select-a-single-value-from-a-table-using-another-value-in-its-row/ Share on other sites More sharing options...
wildteen88 Posted February 22, 2009 Share Posted February 22, 2009 thats because you're not processing the results properly. I am assumming you're doing something like this $query = mysql_query("SELECT img_path FROM your_images WHERE image_name='$YOUR_IMAGE_NAME'"); echo $query; Which is incorrect. What you should do $query = mysql_query("SELECT img_path FROM your_images WHERE image_name='$YOUR_IMAGE_NAME'"); // process the result resource $row = mysql_fetch_assoc($query); echo $row['img_path']; The above is a very cut down version. Link to comment https://forums.phpfreaks.com/topic/146383-solved-how-to-select-a-single-value-from-a-table-using-another-value-in-its-row/#findComment-768566 Share on other sites More sharing options...
Obsession Posted February 22, 2009 Author Share Posted February 22, 2009 Thank you, is sorted now Link to comment https://forums.phpfreaks.com/topic/146383-solved-how-to-select-a-single-value-from-a-table-using-another-value-in-its-row/#findComment-768572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.