SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot dcgamers's Avatar
    Join Date
    Dec 2005
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Valid Mysql Query Returns Nothing

    I have a perfectly valid mysql query:
    Code:
    SELECT * FROM `defense_queue` WHERE `pid`='22'
    ...which returns 1 row when in phpmyadmin, but NOTHING in php.

    Here is the php code which executes this query:
    PHP Code:
    $where_id mysql_query("SELECT * FROM `defense_queue` WHERE `pid` ='22'");
    $where_id $where_id[id];
    echo 
    $where_id
    and here is the SQL code which creates this table:
    Code:
    CREATE TABLE IF NOT EXISTS `defense_queue` (
      `id` int(11) NOT NULL auto_increment,
      `uid` int(11) NOT NULL,
      `pid` int(11) NOT NULL,
      `s1` varchar(225) NOT NULL default '0' COMMENT 'defense_id,number,timestarted',
      `s2` varchar(225) NOT NULL default '0',
      `s3` varchar(225) NOT NULL default '0',
      `s4` varchar(225) NOT NULL default '0',
      `s5` varchar(225) NOT NULL default '0',
      `s6` varchar(225) NOT NULL default '0',
      `s7` varchar(225) NOT NULL default '0',
      `s8` varchar(225) NOT NULL default '0',
      `s9` varchar(225) NOT NULL default '0',
      `s10` varchar(225) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
    Before you ask, I have looked far and wide already for a solution to this problem on many forums on the internet. Every one I could come across did not solve the problem.

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Nova Scotia, Canada
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $where = mysql_query("SELECT * FROM `defense_queue` WHERE `pid` ='22'");
    $where_row = mysql_fetch_assoc($where);
    $where_id = $where_row['id'];
    echo $where_id;

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_query returns a result resource, not an array. Also no need for single quotes around '22' if it's a numeric data type.

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
              while ($row=mysql_fetch_array($result)) {
                  
    $array_of_values[]=$row;
              }
              return 
    $array_of_values;
          } 
    That will loop through the results set and add each row of the results set to an array in turn. If your going to use a foreach loop act on the array then just before the above code add:

    PHP Code:
    $array_of_values=array(); 
    That will set up as an array so that if there are no matches, the foreach loop will still see $array_of_values as being an array, albeit an empty one.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


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
  •