SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: mysql_fetch_array problem

  1. #1
    Evil Genius MilchstrabeStern's Avatar
    Join Date
    Nov 2003
    Location
    Arizona
    Posts
    1,131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_fetch_array problem

    ? Im getting this error:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mplionhe/public_html/phptesting/memberbands.php on line 26

    However it doesnt seem to be affecting anything, besides displaying the error. Its happening on line 26 and line 26 starts at "while"



    PHP Code:
    $query="SELECT * FROM symphonic LIMIT 0, 5";
    $result=mysql_query($query);
     
    $i 1;
    while(
    $my_info mysql_fetch_array($result))
    {
       
    $var "sdate_" $i;
       $
    $var $my_info['date'];
       
    $var "supdate_" $i;
       $
    $var $my_info['update'];
       
    $var "slink_" $i;
       $
    $var $my_info['link'];
        
    $var "sfull_" $i;
       $
    $var $my_info['full'];
       
    $i++;

    ]

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    Hi Milch!

    I'm sure you know to

    $dbcnx = @mysql_connect('host', 'user', 'pass');
    and
    @mysql_select_db('db')

    Other than that, your code looks fine! On second thought, "LIMIT 0"? Try changing that to "LIMIT 1,5".

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    $this->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Dec 2003
    Location
    Federal Way, Washington (USA)
    Posts
    1,522
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it might also be fussing at some of your variable names. Change $$var to $var everywhere that occurs and see if it helps.

    BTW, David, "LIMIT 0, 5" is fine like it is. PHP is one of those languages that actually starts the result set at record 0, not record 1. Weird, ain't it?
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    Showcase your music collection on the Web

  4. #4
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try just doing this:
    PHP Code:
    $result=mysql_query($query) or die(mysql_error()); 
    and see what that gets ya. Better error reporting may help in debuggin this.

    vinyl-junkie
    The resultset is an array and arrays in PHP are 0 based unless explicitly made to start at another index. 0 is always the first row of an array
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...

  5. #5
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hai,
    I think the problem is with you argument,
    while($my_info = mysql_fetch_array($result))
    {
    }
    i think here you are wrong
    try

    while($my_info = mysql_fetch_array($result,MYSQL_BOTH))
    {
    }
    or
    while($my_info = mysql_fetch_array($result,MYSQL_NUM))
    {
    }
    refer php tutorial also
    ArunKumar
    Where there is a will there is a way
    ArunKumar

  6. #6
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP defaults to MYSQL_BOTH though, unless he's using a very old version I've never developed on

    Milch, try phpster's suggestion. It sounds like the query is failing to me.
    Mike
    It's not who I am underneath, but what I do that defines me.

  7. #7

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arunkumar
    hai,
    I think the problem is with you argument,
    while($my_info = mysql_fetch_array($result))
    {
    }
    i think here you are wrong
    try

    while($my_info = mysql_fetch_array($result,MYSQL_BOTH))
    {
    }
    or
    while($my_info = mysql_fetch_array($result,MYSQL_NUM))
    {
    }
    refer php tutorial also
    ArunKumar
    No, the call is okay.

  8. #8
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hai drzoid,

    i have come across the same problem and i tried with argument i got the result,
    Is there is not neccessary to give argument.
    ArunKumar
    Where there is a will there is a way
    ArunKumar

  9. #9

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arunkumar
    Hai drzoid,

    i have come across the same problem and i tried with argument i got the result,
    Is there is not neccessary to give argument.
    ArunKumar
    http://www.php.net/manual/en/functio...etch-array.php
    The optional second argument result_type in mysql_fetch_array() is a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH. This feature was added in PHP 3.0.7. MYSQL_BOTH is the default for this argument.

  10. #10
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hai drzoid,
    i am using 4.2.2 is it require to give the argument compulsary,if not why got error in my program,Please tell me,Sine iam new to php.
    ArunKumar
    Where there is a will there is a way
    ArunKumar

  11. #11

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    No, it is not

  12. #12
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u r right drzoid,Thanks for u now i tried and learn a new thing.
    ArunKumar
    Where there is a will there is a way
    ArunKumar

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,314
    Mentioned
    15 Post(s)
    Tagged
    2 Thread(s)
    vinyl,

    Thanks, Pat, I'll go brush up on MySQL (and rethink my "afterthoughts" before posting).

    Quote Originally Posted by mysql.com
    The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must be integer constants.

    With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1)
    Regards,

    DK
    Last edited by dklynn; Feb 17, 2005 at 14:21. Reason: MySQL LIMIT info
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    Updated mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  14. #14
    Evil Genius MilchstrabeStern's Avatar
    Join Date
    Nov 2003
    Location
    Arizona
    Posts
    1,131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Stupidity has knocked me on my butt for the 3rd time in a row lol. I figured out after adding that piece of code that I had not created a table for the 2nd query. The code uses two queries from two different tables however i wasnt using the variables from the 2nd one yet, so I hadnt made the table. Thats what was going on. RETARDED lol.
    ]

Bookmarks

Posting Permissions

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