View Full Version : How do ı just select the first row ?

09-05-2009, 04:38 PM
I am running a quich search on my transaction file to
pick up the client id number.

the transaction file may have several rows for that client
and I can identify them from another field, the subscription number.

This is the php that I have:

$sql = "select client_id from transactions where subscr_id = '$Db_subscr_id'";
$result = mysql_query($sql) or die("Find Transaction to Modify query failed:". mysql_error());
$num = mysql_num_rows($result);

if ($num == 0) {
Handle the error
} // end if
else {

Now there could be many rows with the same subscrition number
and all of them will have the same client id number.

So after this else I want to gab the first row in the result array
and find out what the client_id value is.

How do I get the first on ?

09-05-2009, 04:40 PM
$sql = "select client_id from transactions where subscr_id = '$Db_subscr_id' LIMIT 1";



09-05-2009, 04:43 PM
... and then

$row = mysql_fetch_array($result);
$client_id = $row['client_id'];

09-05-2009, 04:44 PM
oh good call, I didn't see that part.


09-05-2009, 05:19 PM
Thanks for helping :thumbsup: