6

The below code show warning undefined index for my database field name 'zatitle' spelling is correct in both code and database. I can not find out the error please help.

    include('connect.php');
    dbConnect(); 

    $myquery=mysql_query("SELECT zaid,zatext, MAX(zatitle) FROM announcements") or die(mysql_error());
     if (mysql_num_rows($myquery) == '1') {
     $asession=mysql_fetch_array($myquery);
     $ses = $asession['zatitle'];
       if($ses=='1'){
        $one='2013-2014';
       }elseif($ses=='2'){
        $one='2014-2015';
       }elseif($ses=='3'){
        $one='2015-2016';
       }elseif($ses=='4'){
        $one='2016-2017';
       }

For this code the warning is problem given below

Notice: Undefined index: zatitle in C:\xampp\htdocs\home\home.php on line 9

2 Answers 2

3

Use alias for column with MAX.

$myquery=mysql_query("SELECT zaid,zatext, MAX(zatitle) as zatitle FROM announcements") or die(mysql_error());
                                                       ^^^^^^^^^^
Sign up to request clarification or add additional context in comments.

Comments

3

I think you want a query like this

$myquery=mysql_query("SELECT zaid,zatext, MAX(zatitle) as zatitle FROM announcements")

because if you select Max(zatitle) then the result will also come as Max(zatitle)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.