Jump to content

Recommended Posts

Hi,

 

MySQL Server version is : 5.0.67

php 5.2.6

 

Basicall I have a query on a single table that I *know* works and returns the result I want, however retrieving that in php is giving me headaches and I cannot fathom for the life of me why.

 

I tried the following just to get everything out of the result

 

<?php
$query = "SELECT MIN(expiry) FROM entries WHERE expiry != 0";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
  foreach ($row as $key => $value)
  {
    echo '$row["'.$key.'"] : '.$value.'<br/>';
  }
}
?> 

 

And all I get back is

 

$row["0"] :

$row["MIN(expiry)"] :

 

This is so frustrating! Like I say, if I run this query in MySQL is returns a single row/column wit the desired number. If someone could tell me what I am doing wrong I would be much obliged.

 

Link to comment
https://forums.phpfreaks.com/topic/127521-solved-retrieving-result-from-min-query/
Share on other sites

If all you need is the minimum number you can use this:

 

$result = mysql_query('SELECT MIN(expiry) FROM entries');
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
echo "<br>";
echo "<br>";
while (list($expiry) = mysql_fetch_row($result))
{
echo "$expiry";
}

I want the minimum as long as it's not 0, because that has a special meaning. I'll test the code tonight. I stress that the issue here isn't with the query as such, because if I login in to MySQL and the command prompt and run it it gives me the result I want. The issue is that when I run the same query in php I get back a resource where the response to the query is null? 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.