note 27462 added to function.mysql-field-flags
| From: | justin at rack1 dot php dot net | Date: | Fri, 06 Dec 2002 16:36:20 +0000 |
| Subject: | note 27462 added to function.mysql-field-flags | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40429@lists.php.net to get a copy of this message | ||
Sometimes, when writing a generic function or class, you want your script to be able to determine
what the primary key of a table is.
/* usual MySQL stuff */
$query="DESC UsersTable";
$results=mysql_query($query);
while ($row=mysql_fetch_array($results))
{
if ($row[Type]="PRI")
{
print "I found the primary key! <br>";
$UserKey=$row[Field];
print $row[Field];
/* drop out , as we've found the key */
exit;
}
}
..... later on we might have something like
< some sort of loop through records >
print "<a href='View_User_record.php?userkey=$UserKey'> Users Name
</a>";
<end loop>
What's also interesting is the useful data you can get from
a DESC query.
The following prints out the array values grabbed by mysql_fetch_array on a DESC query - VERY useful
stuff!!!
/* usual MySQL stuff */
$query="DESC UsersTable";
$results=mysql_query($query);
while ($row=mysql_fetch_array($results))
{
print "<pre>";
print_r ($row);
print "</pre>";
}
--
http://www.php.net/manual/en/function.mysql-field-flags.php
http://master.php.net/manage/user-notes.php?action=edit+27462
http://master.php.net/manage/user-notes.php?action=delete+27462
http://master.php.net/manage/user-notes.php?action=reject+27462