Page 1 of 1
mysql functions
Posted: Mon Mar 31, 2003 6:32 pm
by nincha
is there a function that gives the row number where a certain item is located at??
Posted: Mon Mar 31, 2003 8:41 pm
by spammich
Row number? The whole point ot a relational database is that you don't need to worry about rows and stuff, only primary keys.
Code: Select all
$result = mysql_query("SELECT id FROM mytable WHERE mydata=$blahblahblah");
$obj = mysql_fetch_object( $result );
mysql_free_result( $result );
$rownumber = $obj->id;
Or better yet, use PEAR::DB_DatabaseObjects:
http://pear.php.net/manual/en/packages. ... object.php
Hope this helps.
Posted: Mon Mar 31, 2003 8:54 pm
by nincha
can u give the syntax to getting an item using primary keys? i was tinking like
Code: Select all
$result = mysql_query("SELECT $field * FROM $table WHERE id=1");
but thats the wrong syntax for it, can some one tell me the right way of using it.Thnx
Posted: Mon Mar 31, 2003 9:36 pm
by fractalvibes
More like
$sqlstring = "SELECT field1, field2, field3 FROM sometable WHERE id=1";
$sql_result = mysql_query($sqlstring,$conn);
Phil J.
Posted: Mon Mar 31, 2003 10:23 pm
by nincha
i tried that and what i got was Resource id #2 for everything, can some one tell me what this means
Posted: Mon Mar 31, 2003 11:33 pm
by haagen
The $result is just a "pointer" the real data. To fetch it you have to do a
Then the $row is an array. You can reach the data by
Code: Select all
echo $rowї"fieldname"];
or
echo $rowї0]; // field no. 0
Hope this helps. And please, read a database tutorial, before asking.