Jump to content
iyeru42

Getting STRING Data from MySQL Query

Recommended Posts

I'm having a problem getting STRING data from a MySQL query.using the following:

		$CFG['maxlen']['username'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='username'"));		$CFG['maxlen']['password'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='password'"));		$CFG['maxlen']['email'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='email'"));

gives me an error later stating that a class cannot be converted to a string.I used this instead:

		$CFG = Array();		$CFG['maxlen'] = mysql_fetch_array(mysql_query("SELECT `data` FROM `maxlen`"));

But $CFG['maxlen']['username'] (a valid row in the select statement above) is not a valid index.I don't NEED to get an array, how do I just parse the data correctly so it doesn't output some useless data like "Resource id #4"?mysql_fetch_object, mysql_fetch_array, mysql_fetch_assoc won't work, they all get arrays and/or rows (and I know specifically WHAT row I want. So I don't NEED to get a row.) Using the plain mysql_query results in resource id #4 even though it should be resulting in 32 (username row value)

$CFG['maxlen']['username'] = mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='username'");

Share this post


Link to post
Share on other sites

using these instead...

	$CFG['maxlen']['username'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='username'"), "data");		$CFG['maxlen']['password'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='password'"), "data");		$CFG['maxlen']['email'] = mysql_fetch_object(mysql_query("SELECT `data` FROM `maxlen` WHERE `name`='email'"), "data");

$CFG = Array();		$CFG['maxlen'] = mysql_fetch_array(mysql_query("SELECT `data` FROM `maxlen`"), MYSQL_ASSOC);

Give out errors:

Fatal error: Class 'data' not found in installDB.php on line 201

Notice: Undefined index: username in installDB.php on line 235Notice: Undefined index: username in installDB.php on line 237

second uses $CFG['maxlen']['username']respectively.

Share this post


Link to post
Share on other sites

I finally got it fixed by using this:

<?phpif( ( $result = mysql_query( "SELECT name,data FROM maxlen" ) ) ){	while( $row = mysql_fetch_assoc( $result ) )	{		$CFG['maxlen'][$row['name']]=$row['data'];	}		mysql_free_result( $result );}?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...