For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2004 > Re[2]: [PHP-DB] Empty query result









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re[2]: [PHP-DB] Empty query result
Pablo M. Rivas

2004-07-26, 3:56 pm

Hello Philip,

read:
http://www.php.net/manual/en/function.mysql-result.php

when you do $queryResult = mysql_result($queryResult,0) you get
the error... so, you can do something like this:

function getMysqlSelectResultForUsername($identif
ier, $userName, $link)
{
$queryResult = mysql_query("select $identifier from theTable where
username = '$userName'", $link);
if ($queryResult) {
$queryResult = mysql_result($queryResult, 0);
}
return $queryResult;
}

$hall = getMysqlSelectResultForUserName('buildin
gID', $_userName,$link);
if (!$hall) die ("error")
....

or you can do:

function getMySqlSelectResultForUserName($identif
ier,
$userName,$link) {
return mysql_query("select $identifier from TheTable where
username='$userName'",$link);
}

$hall= getMysqlSelectResultForUsername('buildin
gID', $_userName, $link);
if (!$hall) die("not found building!!!");
$roomNum = getMysqlSelectResultForUsername('roomNum
', $_userName,$link);
$phone1 = getMysqlSelectResultForUsername('phone1'
, $_userName, $link);
$phone2 = getMysqlSelectResultForUsername('phone2'
, $_userName, $link);
$lastLogin = getMysqlSelectResultForUsername('lastLog
in', $_userName,$link);

if ((!$roomNum) or (!$phone1) or (!$phone2) or (!$lastLogin)) {
echo "data is missing";
.... ....
} else {
.......
}

PT> Pablo,



--
Best regards,
Pablo
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com