n00bl3z Posted February 6, 2011 Share Posted February 6, 2011 Alrite, i can successfully connect to my server an db, open a connection, but when i retrieve data using $sqlNAME = "select name from `".$table."` where id = '".$id."' "; $scriptName = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); the outcome is always something like 'Resource ID #5' (where #5 is a different number for each item) My main question is how would i retrieve the actual Name, and later on i will be retrieving the url and ID, and displaying both. My Database was set up using this SQL command: CREATE TABLE `scripts` (`id` INT( 8 ) NOT NULL AUTO_INCREMENT , `name` VARCHAR( 12 ) NOT NULL , `url` VARCHAR( 100 ) NOT NULL , PRIMARY KEY ( `name` ) , INDEX ( `id` ) ); If you need any more info/code i'll be happy to give it. Quote Link to comment Share on other sites More sharing options...
Riparian Posted February 6, 2011 Share Posted February 6, 2011 Try this ... too many "" $sqlNAME = "select name from $table where id = '$id' "; $scriptName = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); Quote Link to comment Share on other sites More sharing options...
n00bl3z Posted February 6, 2011 Author Share Posted February 6, 2011 Try this ... too many "" $sqlNAME = "select name from $table where id = '$id' "; $scriptName = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); Nope, the output is still: Script found for ID: Resource id #7; The name is Resource id #5; The url is Resource id #6 Quote Link to comment Share on other sites More sharing options...
n00bl3z Posted February 6, 2011 Author Share Posted February 6, 2011 Try this ... too many "" $sqlNAME = "select name from $table where id = '$id' "; $scriptName = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); Nope, the output is still: Script found for ID: Resource id #7; The name is Resource id #5; The url is Resource id #6 SOLVED; My Solution is: Instead of only handing the raw Resource ID, I needed to fetch the array also. So, My fix is: Instead of just: $scriptName1 = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); $sqlNAME = "select name from $table where id = '$id' "; I needed to add: while($row = mysql_fetch_array($scriptName1)) { $scriptName = $row['name']; } To the end of my script. Thanks for all the help Finished Code: $sqlNAME = "select name from $table where id = '$id' "; $sqlURL = "select url from $table where id = '$id' "; $sqlID = "select id from $table where id = '$id' "; $scriptName1 = mysql_query($sqlNAME) or die ("Failed to get Script Name because ".mysql_error()); $scriptUrl1 = mysql_query($sqlURL) or die ("Failed to get Script Name because ".mysql_error()); $scriptId1 = mysql_query($sqlID) or die ("Failed to get Script Name because ".mysql_error()); while($row = mysql_fetch_array($scriptName1)) { $scriptName = $row['name']; } while($row = mysql_fetch_array($scriptUrl1)) { $scriptUrl = $row['url']; } while($row = mysql_fetch_array($scriptId1)) { $scriptId = $row['id']; } echo "Script found for ID: {$scriptId}; The name is {$scriptName}; Would you like to <a href='{$scriptUrl}'>Download Now?</a>"; 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.