Jump to content

select a single coloumn from mysql


charles07

Recommended Posts

have you ever wondered how to select a single coloumn from mysql using php & checking whether a value or variable exists in the resulting array... well here is the code

 

$busid = '5412';

$results    =  mysql_query("SELECT `myname` FROM mytable WHERE myuser = 'user'");

        while($rows = mysql_fetch_array($results))

        { 

            $colnames[] = $rows['myname'];

        }

        if(!in_array($busid, $colnames))die("Access denied");

Link to comment
https://forums.phpfreaks.com/topic/253209-select-a-single-coloumn-from-mysql/
Share on other sites

You are selecting an information (MySQL) and then check if something exists in it (PHP). You'd better do it inside MySQL's request.

For example:

SELECT `myname` FROM mytable WHERE myuser = 'user' and myname='5412'

 

Maybe "WHERE myname='5412'" is enough.

 

Send this request and then check just a number of rows in result but not values. It will work faster. The difference could be 10e-3 seconds, of course, or something like this :)

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.