Jump to content

[SOLVED] No idea whats going on? ??? - MySQL SELECT - no error, wrong data.


MasterACE14

Recommended Posts

Evening,

 

I use my own Custom functions for querying my database but for some reason my function is only working for SELECTing from my `cf_users` table and not my `cf_users2` table.

 

here's my selecting function:

<?php
// Select fields from the user table
function player_table($select){
    $where = $_SESSION['playerid'];
    $sql = "SELECT `" . what_table($select) . "`.`" . $select . "` FROM `cf_users` INNER JOIN `cf_users2` ON (`cf_users2`.`id` = `cf_users`.`id`) LIMIT 1";
    $rs = mysql_query($sql) or die('Query:<br />' . $sql . '<br /><br />Error:<br />' . mysql_error());
    while($row = mysql_fetch_assoc($rs)){
        if(isset($row[$select])){return $row[$select];}
    }
};

/* and what_table(); function used for working out to select from cf_users or cf_users2 */

// Check if the column in the database is in 1 table or another
function what_table($column) {

$fields = mysql_list_fields("database", "cf_users");
       
$columns = mysql_num_fields($fields);
       
for ($i = 0; $i < $columns; $i++) {
    $field_array[] = mysql_field_name($fields, $i);
}
       
if(!in_array($column, $field_array)) {
$table = "cf_users2";
}
elseif(in_array($column, $field_array)) {
$table = "cf_users";
}

return $table;

};

 

here's my user details for my account in `cf_users2`, showing column name then value:

level_supplysize - 2 | amount_supplysize - 200 | price_supplysize - 500

 

and this is what is being echo'd onto the page, use the player_table(); function:

level_supplysize - 1 | amount_supplysize - 100 | price_supplysize - 250

 

I have no idea why this is happenning, but I really need to get this fixed ASAP,

any and all help is greatly appreciated  :)

 

Regards ACE

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.