SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast kerim's Avatar
    Join Date
    Mar 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    :confused: Help with PHP/MySQL syntax!!!

    I am completely dumbfounded. For hours I couldn't figure out why this wouldn't work:

    $result*=*mysql_query( "SELECT***FROM*files");

    while ($row = mysql_fetch_array($result)) {
    $ID = $row["ID"];
    $filename = $row["filename"];
    $num = $row["num"];
    }

    I kept getting parse errors. But now this works:

    $filelist = mysql_query("SELECT * FROM files");

    while ($row = mysql_fetch_array($filelist)) {
    $id = $row["id"];
    $category = $row["filename"];
    $num = $row["num"];
    }

    Is it just me, or are these not exactly the same except for the name assigned to the query. Does it really matter?

    But wait, there is more - and this is where my problems begin, because I don't know how to fix this. While the above works, I am trying to get something of this sort:

    $filelist = mysql_query(
    "SELECT * FROM files WHERE*id='$id'");

    while ($row = mysql_fetch_array($filelist)) {
    $id = $row["id"];
    $category = $row["filename"];
    $num = $row["num"];
    }

    I have also seen:

    $sql*=*mysql_query("SELECT***FROM*download_list*WHERE*id='$id'");

    while*($row*=*mysql_fetch_array($sql))*{

    extract*($row);
    }

    Of course, there is more afterwards - but I keep the following error pointing to the 'while" line:

    Supplied argument is not a valid MySQL result resource

    Any ideas?

    Thanks.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well your query is failing for some reason, here is a trick you can use to figure out why it is failing.

    PHP Code:
    $result mysql_query"SELECT * FROM files") or DIE(mysql_error()); 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast kerim's Avatar
    Join Date
    Mar 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, this is even more strange. The following works fine, outputting results:

    <?PHP

    include("downlogin.php");

    $result = mysql_query( "SELECT * FROM files");

    while ($row = mysql_fetch_array($result)) {
    $id = $row["id"];
    $category = $row["filename"];
    $num = $row["num"];

    echo "$id $category $num <p>";
    }


    ?>

    But doing what you said, as listed below, results only in a "parse error" at that line. So it seems to make things worse rather than solving the problem. I don't understand why . . .

    <?PHP

    include("downlogin.php");

    $result*=*mysql_query(*"SELECT * FROM files")*or*DIE(mysql_error());

    while ($row = mysql_fetch_array($result)) {
    $id = $row["id"];
    $category = $row["filename"];
    $num = $row["num"];

    echo "$id $category $num <p>";
    }


    ?>

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First off that should not be producing an error, are you sure you got the last ) at the end of the line in your actual code. Also in your first post yo usaid assigning the query to $result resulted in errors, but in your last post you say it works using $result. So what exactly is the problem, are you able to get results back?
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast kerim's Avatar
    Join Date
    Mar 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, very strange. The code is copied and pasted from BBEdit, so what you see is what I used. And yes, I was able to get $result to work this time - so it is very strange that it wasn't working before.

    I wonder if something is happening to the code on upload from interarchy? But when I download it looks the same to me . . .

    kerim

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure to upload in ascii mode not binary.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  7. #7
    SitePoint Enthusiast kerim's Avatar
    Join Date
    Mar 2001
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I got it to fix the parse error. I looked at the file in BBEdit with "show invisibles" turned on, and low and behold - there were many "space" characters that were not "real" spaces. By turning them into real spaces, the thing parsed correctly. Now if I only knew why this was happening. . . probably something to do with my Chinese software.

    kerim


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
  •