icor1031 Posted September 17, 2014 Share Posted September 17, 2014 I can't figure out how I'm messing up so badly. Anyway, I have: $con=mysqli_connect("removedforsecurity"); $finderCleanup = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 1"); $finderCleanupArray = mysqli_fetch_array($finderCleanup); $integerCleanup = $finderCleanupArray['PID'] - 40; $lastPID = $finderCleanupArray['PID']; $lastPIDreduced = $finderCleanupArray['PID'] - 8; When I var_dump $lastPID, it returns INT with a number (it works correctly.) Then, I have this: function getResults($con,$lastPIDreduced) $con works correctly in the function, but $lastPIDreduced is "undefined." What is my sin? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/ Share on other sites More sharing options...
Barand Posted September 17, 2014 Share Posted September 17, 2014 Your sin is not showing us what the function does and how it is being called. Quote Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/#findComment-1491387 Share on other sites More sharing options...
Solution icor1031 Posted September 17, 2014 Author Solution Share Posted September 17, 2014 (edited) It was because I didn't use $lastPIDreduced when I called the function, oops! function getResults($con,$lastPIDreduced) { $y = 0; echo $lastPIDreduced; $results = mysqli_query($con, "SELECT * FROM Entries ORDER BY PID DESC LIMIT 0,8"); while ($rowFp = mysqli_fetch_array($results)) { echo "<br /><br />" . $rowFp['Title'] . "<br />" . $rowFp['remoteTime'] . "<br /><br />" . $rowFp['PID']; } } getResults($con); Edited September 17, 2014 by icor1031 Quote Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/#findComment-1491388 Share on other sites More sharing options...
cyberRobot Posted September 17, 2014 Share Posted September 17, 2014 It was because I didn't use $lastPIDreduced when I called the function... It looks like you got the issue figured out. Should the topic be marked as solved? If the script still doesn't work, the next thing I would look for is to make sure the function is called after $lastPIDreduced is defined. Quote Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/#findComment-1491389 Share on other sites More sharing options...
icor1031 Posted September 17, 2014 Author Share Posted September 17, 2014 It looks like you got the issue figured out. Should the topic be marked as solved? If the script still doesn't work, the next thing I would look for is to make sure the function is called after $lastPIDreduced is defined. It works, and I believe it's marked as solved now. Thanks, gentlemen. Quote Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/#findComment-1491390 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.