Jump to content

Function to return a single value from a sql query.


solidstan

Recommended Posts

I am very new to PHP and SQL, and enjoying learning through W3School.I need alittle help with my function, to return a single value from a sql database.

function lineData($con,$num,$row){    $Result = mysqli_query($con,"SELECT Line FROM DriverList WHERE DriverNumber = $num");         $output =  mysql_query($Result);      return $output   }

Hope you can see what i'm trying to do. Any help and tips, would be appreciated..

 

Thanks in advance!

Link to comment
Share on other sites

These examples all seem to be returning arrays. (way above my head).

 

I was hoping someone could show me a simple function to returm a SINGLE value and set that value as my varaible OUTPUT.

My query will always only have 1 possible value.

 

Note.. 1 SINGLE value. NOT a row of data.

Link to comment
Share on other sites

Arrays are pretty fundamental to programming. Like a scalar variable holds a single value, an array holds multiple values. Arrays are so fundamental that the mysqli extension does not even have a way to get the value of a single field. You can get an entire row as either an array or an object, and get the field from that. The fetch_field method, for example:

 

http://www.php.net/manual/en/mysqli-result.fetch-field.php

 

does not return a value in a field, it returns information about the field itself (data type, length, etc). Look at the examples on the manual page for fetch_assoc, they show getting values of the fields pretty clearly.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...