Jump to content

Help with mysqli_fetch_array


nca
Go to solution Solved by benanamen,

Recommended Posts

I am trying to rewrite a script from php 5 to php 7. Can someone help me see why this is not working? Thank you!!

$db_connection = mysqli_connect($host, $user, $password, $database);
$sql = "SELECT BIN FROM listofbins WHERE PENDING='1' LIMIT 1";
$result = mysqli_query($db_connection,$sql);
$owew = mysqli_fetch_array($result, MYSQLI_ASSOC);
if ($owew[BIN] > '100') {
echo "Pending BIN over the number 100: $owew[BIN]";
exit;
}

 

Link to comment
Share on other sites

If you need to find the record with the value of PENDING equaling 1, why do you need a limit?  And is PENDING  an integer or a text value?  You make it appear to be a text one.

In your query you have a field called BIN.  Yet in your reference to the values retrieved from the query result you seem to be looking for a constant named BIN.  Which is it?  And again - is BIN an integer or is it a string?

So many questions.

Here is a sample of how I would write your query to do some error checking.  You need to address my questions tho.

if (!$db_connection = mysqli_connect($host, $user, $password, $database))
{
	echo "Could not make db connection";
	exit();
}
$sql = "SELECT BIN FROM listofbins WHERE PENDING='1' LIMIT 1";
if (!$result = mysqli_query($db_connection,$sql))
{
	echo "Error running query: $sql<br>";
	exit();
}
$owew = mysqli_fetch_array($result, MYSQLI_ASSOC);
if ($owew['BIN]' > '100') 
{
	echo "Pending BIN over the number 100: ". $owew['BIN'];
}
exit();

 

Link to comment
Share on other sites

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.