New Posts
Welcome guest, is this your first visit?
  • Login:
TruePoker.eu Affiliate Program
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 15
  1. #1
    Member
    My Status
     

    Add as a friend
    Join Date
    Oct 2009
    Location
    US
    Posts
    52
    Feedback Score
    1 (100%)

    Default Best way to extract php variables

    I am trying to figure out the best way to pull define variables from a mysql database, and it just seems like there is a simpler way that I am not thinking of. I have a db of like 5 columns and 15 rows. For each row I need to define a variable for each column, but has to be defined individually so a while statement will not work. This is what I am thinking

    PHP Code:
    $row db_fetch_array(db_query(SELECT FROM poker_sites WHERE site_name='pokerstars'));

    if (
    extract($row)) {

     
    //define variables


    Then I would just repeat that process for each row. That just seems like a lot and that there should be an easier way. Any thoughts would be great.

  2. #2
    #!/usr/bin/mikebrad
    My Status
     

    Add as a friend
    Join Date
    Nov 2008
    Location
    USA
    Posts
    622
    Feedback Score
    8 (100%)

    Default

    mysql_fetch_row, if you are trying to do it individually

    PHP: mysql_fetch_row - Manual

    EDIT: Are you using MySql? Or is this drupal?

    db_fetch_object | Drupal API

  3. #3
    Member
    My Status
     

    Add as a friend
    Join Date
    Oct 2009
    Location
    US
    Posts
    52
    Feedback Score
    1 (100%)

    Default

    Quote Originally Posted by Mike View Post
    mysql_fetch_row, if you are trying to do it individually

    PHP: mysql_fetch_row - Manual

    EDIT: Are you using MySql? Or is this drupal?

    db_fetch_object | Drupal API
    This is drupal.

    How is using the db_fetch_object() really different the what I was doing? Wouldn't i still have to repeat this for each individual row in order to define the variables?

  4. #4
    #!/usr/bin/mikebrad
    My Status
     

    Add as a friend
    Join Date
    Nov 2008
    Location
    USA
    Posts
    622
    Feedback Score
    8 (100%)

    Default

    but has to be defined individually
    Yes, you would have to repeat this for each individual row. I thought that was what you wanted to do. Maybe if you posted exactly what you are trying to do and what your db structure is, I could help more.

  5. #5
    Member
    My Status
     

    Add as a friend
    Join Date
    Oct 2009
    Location
    US
    Posts
    52
    Feedback Score
    1 (100%)

    Default

    Quote Originally Posted by Mike View Post
    Yes, you would have to repeat this for each individual row. I thought that was what you wanted to do. Maybe if you posted exactly what you are trying to do and what your db structure is, I could help more.
    Sorry, I'll try to be more clear. there is about 7 columns that I want to pull from with 15 rows. So one column might be rake_percentage and then there would be all of the poker sites that would each have a value.

    What about this

    PHP Code:
    $query db_query(SELECT rake_percentage FROM poker_sites);

    $row db_fetch_array($query);

    $ft_percentage .= $row[0];
    $doyle_percentage .= $row[1];
    //ect... 
    Then I would do that for each column, which seems easier then doing it for each row. What do you think?

  6. #6
    Member
    My Status
     

    Add as a friend
    Join Date
    Mar 2009
    Location
    Asia
    Posts
    98
    Feedback Score
    1 (100%)

    Default

    Also be mindful that Drupal has variable_set() and variable_get() available to you.

    I'm not clear of the context here but this is probably a good way to accomplish what you're after. Otherwise, utilise the node system (with views), it's wonderful.

  7. #7
    Member
    My Status
     

    Add as a friend
    Join Date
    Oct 2009
    Location
    US
    Posts
    52
    Feedback Score
    1 (100%)

    Default

    Ok, this is what I have come up with that seems to work and I am able to declare all variables in the same while loop

    PHP Code:
       $query db_query("SELECT * FROM site_info_s");
       while(
    $row[] = mysql_fetch_array($query)) { 
       
       
    $ft_name $row[0][0];
       
    $stars_name $row[1][0];
     
       } 
    I had to use the mysql_fetch_array() instead of db_fetch_array because for some reason it will not let me use [0][0] to search for the field. I will have to make a post and find out why it does not function the same.

  8. #8
    #!/usr/bin/mikebrad
    My Status
     

    Add as a friend
    Join Date
    Nov 2008
    Location
    USA
    Posts
    622
    Feedback Score
    8 (100%)

    Default

    Oh, I see what you are trying to do now. You needed to get multiple rows, then yes, you definitely want to remove the WHERE statement from your query.

    Just a tip, if you want to do assign ALL variables by using ONE while loop AND be able to use these variables later, you could just assign one cell as the variable.

    For instance:

    If your db is setup like this

    Room Name | Rake_Percent | Bonus_Amount
    fulltilt | 30% | $600
    absolute | 27% | $150


    PHP Code:
      $query db_query("SELECT * FROM site_info_s"); 
       while(
    $row mysql_fetch_array($query)) {  
        
       $
    $name $row[0]; 
       
    $name.'_rake' $row[1]; 
       
    $name.'_bonus' $row[2]; 
      
       } 
    Then you could just call the variables $fulltilt_rake, $absolute_rake, $fulltilt_bonus, $absolute_bonus whenever you wanted to within the page.

    I know you had it figured out, just offering another way to do it that may be a little more user friendly than nested arrays.

  9. #9
    Member
    My Status
     

    Add as a friend
    Join Date
    Oct 2009
    Location
    US
    Posts
    52
    Feedback Score
    1 (100%)

    Default

    Hey Mike,

    Thanks for the help. I think your way is easier, but I tried to implement it and got a syntax error stating an unexpected '='

    What do you think?

  10. #10
    Senior Member
    My Status
     

    Add as a friend
    Join Date
    Jan 2009
    Location
    Fortunate Son
    Posts
    680
    Feedback Score
    10 (100%)

    Default

    Its the $$name. Should be 1 $. I'm pretty sure.


 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Powered by vBulletin® Version 4.1.5
Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.
SEO by vBSEO 3.6.0
Affiliate Program Consultant
Live threads provided by AJAX Threads (Lite) - vBulletin Mods & Addons Copyright © 2012 DragonByte Technologies Ltd. Runs best on HiVelocity Hosting.