PHP Web Host - Quality Web Hosting For All PHP Applications Just Great Software
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
7ekno
New Member
New Member


Joined: Dec 22, 2005
Posts: 13

PostPosted: Wed Apr 22, 2009 2:44 am Reply with quote Back to top

Hi ya Smile

Just a quick question, I am trying to convert a few older modules I have laying around the place, and was wondering if there is a better way to do the following:

First, an example of the old code:
Code:
      $tmpOpponentID = mysql_query("SELECT blackPlayer FROM games WHERE gameID = ".$_POST['gameID']);
      $opponentID = mysql_result($tmpOpponentID, 0);


Then the code that I have converted it to that works:
Code:
      $tmpOpponentID = $db->sql_query("SELECT blackPlayer FROM "$.prefix."_chess_games WHERE gameID = ".$_POST['gameID']);
      $row = $db->sql_fetchrow($tmpOpponentID);
      $opponentID = $row[0];


My question is: Is there some other function that I am missing that does the above, without the temporary assignment of $row?!? Is there an equivalent function of mysql_result(), that actually returns a single element from an array of database queries?!?

Thanks,
7
View user's profile Send private message
montego
Former Admin in Good Standing


Joined: Aug 29, 2004
Posts: 9071
Location: Arizona

PostPosted: Wed Apr 22, 2009 6:48 am Reply with quote Back to top

Well, there are a couple of options, such as:

Code:

$row = $db->sql_fetchrow($db->sql_query("SELECT blackPlayer FROM "$.prefix."_chess_games WHERE gameID = ".$_POST['gameID']));
$opponentID = $row[0];


You should also be able to do this:

Code:

list($opponentID) = $db->sql_fetchrow($db->sql_query("SELECT blackPlayer FROM "$.prefix."_chess_games WHERE gameID = ".$_POST['gameID']));


Last edited by montego on Mon Apr 27, 2009 9:41 pm; edited 1 time in total
View user's profile Send private message Visit poster's website
7ekno
New Member
New Member


Joined: Dec 22, 2005
Posts: 13

PostPosted: Wed Apr 22, 2009 11:06 pm Reply with quote Back to top

Thanks Montego,

You rock Smile I didn't realise I could pass a query to _fetchrow !!!

Thanks again Smile
View user's profile Send private message
montego
Former Admin in Good Standing


Joined: Aug 29, 2004
Posts: 9071
Location: Arizona

PostPosted: Mon Apr 27, 2009 9:42 pm Reply with quote Back to top

You can't because I am a goofball!!!!! I have corrected the above examples to include the sql_query... that is what I get for posting in a rush.
View user's profile Send private message Visit poster's website
7ekno
New Member
New Member


Joined: Dec 22, 2005
Posts: 13

PostPosted: Tue Apr 28, 2009 2:18 am Reply with quote Back to top

Hehe Smile

Thanks, did try passing a query to _fetchrow, and when it didn't work, I figured ya meant it like above Razz

I have "standardised" on the list() method for single elements, and just leaving arrays as is via _fetchrow Wink

I have even managed to implement auto table creation in an Administration module for the standalone version of "WebChess v0.8.2" found around the place, all up-to-date and RN2.30.01 compliant!!

7
View user's profile Send private message
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum