Jump to content

Giving variable to function (very basic)


icor1031

Recommended Posts

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

It was because I didn't use $lastPIDreduced when I called the function, oops! :shrug:

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);

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.