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. 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. Link to comment https://forums.phpfreaks.com/topic/291122-giving-variable-to-function-very-basic/#findComment-1491387 Share on other sites More sharing options...
icor1031 Posted September 17, 2014 Author Share Posted September 17, 2014 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); 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. 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. 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
Archived
This topic is now archived and is closed to further replies.