www.webdeveloper.com
Results 1 to 4 of 4

Thread: cant take a data from row variable

  1. #1
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189

    cant take a data from row variable

    the following code can't take my data from database. what could be the problem. here's the sample code:

    PHP Code:
    <?php

    mysql_connect
    ('localhost','root','1234') or die("Unable to connect to MySQL");
    mysql_select_db(mris) or die("Unable to select a database");

    $query "select mrisno,mdate from mrishead where mdate<'$datestart' and status='Approved' and appname<>'' and lastupdate>='$datestart'"

    $result mysql_query($query) or die("Error in query");
    if(
    mysql_num_rows($result)>0)
    {
       while(
    $row=mysql_fetch_row($result))
       {
        echo 
    $row['mrisno'].'<br/>';
        echo 
    $row['mdate'].'<br/>';
       }        
    }

    ?>
    There's seems to be no problem or error message. when i try to replace $row['mrisno'] with $row[0] it works well. But i want it to be a fieldname not a number for me not to have a hard coding but this isn't working. what seems to be the problem? thank you in advance for any information guys..

  2. #2
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    instead of using mysql_fetch_row($result) it should be mysql_fetch_array($result). I got it now.. =)

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,637
    Or mysql_fetch_assoc(), which might be nano-seconds faster and save a couple bytes of memory if you are only going to use the named (associative) array keys.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    May 2010
    Location
    Manila, Philippines
    Posts
    189
    wow..thanks for that advice..ill try it..=)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles