Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules
Author Message
7ekno
New Member
New Member



Joined: Dec 22, 2005
Posts: 13

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

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
Site Admin



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

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

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']));

_________________
Where Do YOU Stand?
HTML Newsletter::ShortLinks::Mailer::Downloads and more...

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







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

Thanks Montego,

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

Thanks again Smile
 
montego







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

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.
 
7ekno







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

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
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules

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
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©