SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP!!!!!!!!!!! code bug

    Please tell me what is wrong with this code!!

    $id is passed from a form on the previous page.
    Yes, the database has valid entries in it that SHOULD be SELECTed, but aren't.

    $temp = explode ("-", $id);
    $page_id = $temp[0];

    $result = mysql_query("SELECT name FROM soccer_pics WHERE page_id = '$page_id'") or die("Mysql Error");

    $i = 1;

    if (mysql_affected_rows() || die("No results returned"))
    {
    while($row = mysql_fetch_row($result))
    {
    $name = $row[0];
    echo '<div id="Layer'.$i.'" style="position:absolute; z-index:'.$i.'; visibility: hidden; width:640; height:480"><img src="http://www.zikes.com/soccer/pics/'.$name.'" height="480" width="640"></div>';

    $name_array[] = $name;
    $i++;
    }
    }
    else
    {
    die("Error.");
    }

    It produces "No results returned"

    HELP!!

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change mysql_affected_rows() to mysql_num_rows($result). affected_rows is for INSERT, REPLACE, UPDATE, DELETE statements, not SELECTs.

  3. #3
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no change

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tend you use my browser as a debug window when developing a script. If you suspect certain variables are not being set correctly, the best thing is to echo them to screen to see what their values are during run time). Thus I would write this:
    PHP Code:
    $result mysql_query("SELECT name FROM soccer_pics WHERE page_id = '$page_id'") or die("Mysql Error"); 
    as
    PHP Code:
    $sql "SELECT name FROM soccer_pics WHERE page_id = '$page_id'";
    echo 
    "<br>$sql<br>";
    $result mysql_query($sql); 
    That way you can see what the sql statement that is being sent to the mysql server looks like. My guess is that $page_id contains an emptly string for some reason. Also, as freddydoesphp taught me, you can then copy and paste the actual sql statement from your browser and run it in the sql server from the command line to see whether the problem is with your database schema or data state (ie, whether the data you think should be in the database is there).

  5. #5
    SitePoint Member
    Join Date
    Nov 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man for the help.

    It turned out that for some reason, $page_id wasn't passed from the previous from. So I changed the form from POST to GET and it works.

    Thanks again.


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
  •