Jump to content

Giving variable to function (very basic)


Go to solution Solved by 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

  • Solution

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

Edited by icor1031

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.

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.