Re: problems with a select query in informix
| From: | David Robley | Date: | Thu, 06 Jul 2000 00:40:21 +0000 |
| Subject: | Re: problems with a select query in informix | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5123@lists.php.net to get a copy of this message | ||
On 5 Jul, stephan.schoell@chhos.mail.abb.com wrote:
>
>
> Interesting! I've had the same problem with mysql on apache/cobalt linux. the
> mysql function max() returned 0 no matter what data was in the table. Locally on
> my Win95/apache/mysql system, everything worked fine. My solution (also very
> ugly and slow but...): I made a loop through all the rows and looked for the max
> value in my php script.
>
> $max=0;
> while ($row=mysql_fetch_array(......)) {
> if ($max<$row['whatever_value']) {$max=$row['whatever_value']}
> }
>
> I'm sure, there are better solutions, either in mysql or in php.
>
> --Steff
> webmaster@posh.ch
> www.posh.ch
>
> hello, I got a problem, and I think it has to do with my low knowledge about
> how php treats arrays.
> What I do is this:
>
> 1) I do an insert to the articulo table with some data.
>
> 2) I run the hack below to read the biggest integer in articulo.a_id for
> later use. articulo.a_id is a SERIAL.
>
> $q_id_identi=ifx_query("SELECT MAX (a_id) FROM articulo",$conn_id);
> $q_ar_identi=ifx_fetch_row($q_id_identi);
> echo(sprintf("<br> %d <br>",$q_ar_identi[a_id]));
>
> The problem is that the echo you see above give me 0. But if I make the query
> directly in dbaccess (an informix program which lets throw querys) and the
> answer is diferent.
>
> What am I doing wrong???
>
You may find it useful to assign the MAX value to an alias, and then get
the value of the alias. For mysql, something like this:
$result = mysql_db_query($database,"SELECT MAX(a_id) AS mavxal FROM
articulo",$conn_id);
$row = mysql_fetch_array($result);
$biggestnum = $row["maxval"];
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA