Jump to content

Recommended Posts

Hi again all

 

my php/mysql project is coming along a treat now but ive hit a snag-my function which shouldnt EVER be able to return 0 or '', is returning '' (nothing)

 

here is the code

 

<?php

$research_levels_query = "SELECT * FROM research WHERE username = '$username' AND password = '$password'";
$activate_query = mysql_query($research_levels_query) or die(mysql_error());
$research_levels = mysql_fetch_assoc($activate_query) or die(mysql_error());

//base build times for all vehicles in seconds//
$light_ore_miner_base_build_time = 600;
$light_fuel_miner_base_build_time = 720;
$light_crystal_miner_base_build_time = 900;
$light_wood_farmer_base_build_time = 660;
$light_wave_sub_base_build_time = 840;
$light_atmospheric_filterer_base_build_time = 960;
$medium_ore_miner_base_build_time = 3000;
$medium_fuel_miner_base_build_time = 3420;
$medium_crystal_miner_base_build_time = 3900;
$medium_wood_farmer_base_build_time = 3300;
$medium_wave_sub_base_build_time = 3540;
$medium_atmospheric_filterer_base_build_time = 4020;
$heavy_ore_miner_base_build_time = 7800;
$heavy_fuel_miner_base_build_time = 8400;
$heavy_crystal_miner_base_build_time = 9000;
$heavy_wood_farmer_base_build_time = 8100;
$heavy_wave_sub_base_build_time = 8700;
$heavy_atmospheric_filterer_base_build_time = 9600;

//----------------------------------------------CREATE FUNCTION------------------------------------------------------------//
function vehicle_build_times($vehicle_base_build_time,$research_level)
{
    if ($research_level >= 1)
	{
        $vehicle_build_time = $research_level * $vehicle_base_build_time;
    }
	else
    {
	    $vehicle_build_time = $vehicle_base_build_time;
	}
}
//-------------------------------------------------------------------------------------------------------------------------//
//Light Ore Miner//
$light_ore_miner_build_time = vehicle_build_times($light_ore_miner_base_build_time,$research_levels['simple_ore_drill_turbines']);
//---------------//
?>

 

now the thing is-in the database-ALL the $research_levels fields in the database have 0 in them-so that means when the function is called from this file (inc_vehicle_stats.inc.php) after it has been included in the main file, it should execute the else part of the code-which obviously means in this case with the $light_ore_miner_base_build_time variable it should be returning 600

 

what is the prob-i know its gona be a simple thing to correct probably but can u explain it as well please :)

 

thank you for reading

 

Pudgemeister

 

p.s. i know im using insanely long variable names-this is just so i can understand everythin and not get lost-once everything is finished i will hopefully be sizing them all down (oh that will be fun :S )

Link to comment
https://forums.phpfreaks.com/topic/46839-solved-pudgemeister-returns/
Share on other sites

Hints in the name..

 

 

in a function you need to say what to return

change

<?php
function vehicle_build_times($vehicle_base_build_time,$research_level)
{
    if ($research_level >= 1)
	{
        $vehicle_build_time = $research_level * $vehicle_base_build_time;
    }
	else
    {
	    $vehicle_build_time = $vehicle_base_build_time;
	}
}

return $vehicle_build_time; // <-----ADD THIS
?>

 

i did the same thing when i started.. curse the VB syntax

yes i did notice ye ol vb syntax feeling coming over me

 

and u wandered why i was turning emo while coding this part XD jks

 

cheers-all works fine now :)

 

Pudgemeister

 

p.s. i shall no doubt be back with more function problems in the future as the next part to this project includes mainly functions-i only learnt how to use the basics of them 2 days ago XD

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.