Jump to content

MySQL And PHP Help


n00bl3z

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/226858-mysql-and-php-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/226858-mysql-and-php-help/#findComment-1170576
Share on other sites

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>";

Link to comment
https://forums.phpfreaks.com/topic/226858-mysql-and-php-help/#findComment-1170605
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.