RE: [PHP] Trying to add table prefix variable to query
[snip] This is my query: ?php ... include(config.php); $open = mysql_pconnect($hostname,$user,$password); mysql_select_db($db,$open); $result = mysql($db,SELECT * FROM . $table_prefix . teams WHERE username = 'admin'); $i = 0; $total_rows = mysql_numrows($result); ... ? This is my config file: ?php $db = sports; $hostname = localhost; $password = mypassword; $user = myuser; $table_prefix = ccl_; ? This is my table name: ccl_teams [/snip] You're query reads like this now SELECT * FROM ccl_ teams WHERE username = 'admin' You need to concatenate the variable with the text (remove the space); SELECT * FROM . $table_prefix . teams WHERE username = 'admin' Here is a useful troubleshooting method; if the query returns an error, print it out. You can generally find errors quite easily. HTH! Jay Guys have feelings too. But, like who cares? * * Texas PHP Developers Conf Spring 2003* * T Bar M Resort Conference Center* * New Braunfels, Texas * * Contact [EMAIL PROTECTED] * * * * Want to present a paper or workshop? Contact now! * * -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Trying to add table prefix variable to query
Maybe you should assign the query to is's own value doing your string concatenation... i.e. $query = select * ...; then echo out the query: echo $query; I think you will see the problem them, I would guess that when you are adding the table_prefix to the table name that you are getting an extra space in there... So, try that out, and see if it helps -Brad This query worked until I tried to add support for a table prefix in the config file. Now it can¹t seem to find the table. Any pointers to what I am doing wrong? Thanks, v Original query: ?php include(config.php); $open = mysql_pconnect($hostname,$user,$password); mysql_select_db($db,$open); $result = mysql($db,SELECT * FROM teams WHERE username = 'admin'); $i = 0; $total_rows = mysql_numrows($result); ? This is my query: ?php include(config.php); $open = mysql_pconnect($hostname,$user,$password); mysql_select_db($db,$open); $result = mysql($db,SELECT * FROM . $table_prefix . teams WHERE username = 'admin'); $i = 0; $total_rows = mysql_numrows($result); ? This is my config file: ?php $db = sports; $hostname = localhost; $password = mypassword; $user = myuser; $table_prefix = ccl_; ? This is my table name: ccl_teams This is the error: Warning: Supplied argument is not a valid MySQL result resource in... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Trying to add table prefix variable to query (solved)
Doh,... Thanks to all who replied so promptly with similar answers. :) vern On 9/10/02 9:13 AM, Jacob Miller [EMAIL PROTECTED] wrote: Make sure you don't have a space before the 2nd half of the table name Wrong: .. FROM . $table_prefix . teams this will produce FROM ccl_ teams Right: .. FROM . $table_prefix . teams this will product FROM cc_teams - jacob -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php