0

Hi, this is my query

$result = mysql_query("SELECT SUM(`qty`) FROM sims_ac WHERE region ='North'");

How I can show this

$result[0]

without using While loop or any other loop.

5
Contributors
6
Replies
35
Views
7 Years
Discussion Span
Last Post by scaiferw
1

You need to use a function to extract the result array from the $result resource. If you are only interested in the first result you get from your query, you can just use this:

$row = mysql_fetch_array($result);

EDIT: $row will contain the first row of results returned by the database. If you want just the data for the first field from that first result, then you only need to access $row[0]

Edited by EvolutionFallen: Just to clarify.

Votes + Comments
Great answer
0

You can actually do this with a single line of code:

// mysql_result() function is used to pull a single value from the database
$value = mysql_result(mysql_query("SELECT value FROM table WHERE condition = 'met'"), 0);
0
SELECT count(*),Code FROM `lims_cmt` group by code having count(*)>1 LIMIT 0, 30 ;

Coutt more then 1

Edited by mike_2000_17: Fixed formatting

-1

i write query

<?php
  $query=select username from table_name where username=$username;
  $query_result=mysql_query($query) or die("Sorry there is no value" .mysql_error());
   while($row=mysql_fetch_object($query_result)){
     echo $row->username;

}
?>

Edited by Ezzaral: Snipped &quot;fake sig&quot; link. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.

0

Waseem12, are you asking a question? You may want to start a new thread if you are, and I'm sure people will be happy to help.
The code you have above will not run.

Edited by scaiferw: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.