14pulsars Posted May 23, 2008 Share Posted May 23, 2008 Hi folks, I need some help: I'm retrieving data from a DB based on two variables in the SQL query string (a month number and a week number). All records pull up fine for (monthNumber=1 AND weekNumber=1), but any other weekNumber, monthNumber, or any combination thereof pulls a blank. Also, everything shows up with if the query string just includes (weekNumber=n), but the first record of every month is missing is the query string just includes (monthNumber=n) Here is what I have tried: I though that the weekNumber was not an integer, but a string. is_int() told me $weekNumber is not an integer; is_numeric() returned false. Type Casting or intval() did nothing. Placing single quotes around the variables in the query string in every single combination I could think of I ran the exact same queries through PHPMyAdmin and the right records show up I'm at my whit's end here - any help would be greatly appreciated. Here is my code: (The month variable goes through the array for a reason, by the way) $dbh=mysql_connect ("localhost", "DB_NAME", "PASSWORD) or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("TABLE_NAME"); $monthArray = array( 'udhYdh' => 1, 'IUshd8' => 2, 'Cdne92' => 3, 'Cmdiuj' => 4, 'jd83wh' => 5, 'Vmd93f' => 6, 'd9dfOv' => 7, '8dFvhj' => 8, 'lCjuew' => 9, 'mDUfn4' => 10, '9dnjCu' => 11, 'KIDc2m' => 12 ); $errorMsg = 'Sorry, the following error(s) occured:<br />'; if (isset($_GET['month'])) $monthNumber = $monthArray[$_GET['month']]; else $errorMsg = $errorMsg.'- Invalid Month<br />'; if ($_GET['week'] == 1 || $_GET['week'] == 2 || $_GET['week'] == 3 || $_GET['week'] == 4) $weekNumber = $_GET['week']; else $errorMsg = $errorMsg.'- Invalid Week<br />'; if (isset($monthNumber) && isset($weekNumber)){ $data = mysql_query("SELECT * FROM amember_weeks WHERE monthNumber=$monthNumber AND weekNumber=$weekNumber") or die(mysql_error()); $info = mysql_fetch_array($data); } ... page contents were here .... if (isset($monthNumber) && isset($weekNumber)) { while($info = mysql_fetch_array( $data )) { print $info['id']." - ".$info['title'].'<br />'.$info['weekDesc'].'<br /><br />'; } } else { print $errorMsg; } Quote Link to comment https://forums.phpfreaks.com/topic/107003-solved-php-mysql-does-not-reder-any-fields/ Share on other sites More sharing options...
14pulsars Posted May 23, 2008 Author Share Posted May 23, 2008 Did some more digging, and it turns out that my $data variable returns: Resource id #2 for every query string except (monthNumber=1 AND weekNumber=1). Does that tell anyone anything? I will keep looking. Quote Link to comment https://forums.phpfreaks.com/topic/107003-solved-php-mysql-does-not-reder-any-fields/#findComment-548535 Share on other sites More sharing options...
Barand Posted May 23, 2008 Share Posted May 23, 2008 If your query returns only 1 row then nothing will print. You only print from the second row onwards. <?php $data = mysql_query("SELECT * FROM amember_weeks WHERE monthNumber=$monthNumber AND weekNumber=$weekNumber") or die(mysql_error()); $info = mysql_fetch_array($data); // reads first row and ignores it. REMOVE Quote Link to comment https://forums.phpfreaks.com/topic/107003-solved-php-mysql-does-not-reder-any-fields/#findComment-548543 Share on other sites More sharing options...
14pulsars Posted May 23, 2008 Author Share Posted May 23, 2008 If your query returns only 1 row then nothing will print. You only print from the second row onwards. <?php $data = mysql_query("SELECT * FROM amember_weeks WHERE monthNumber=$monthNumber AND weekNumber=$weekNumber") or die(mysql_error()); $info = mysql_fetch_array($data); // reads first row and ignores it. REMOVE That Worked, thank you! I guess the Resource ID#2 was referring to a second row that did not exist, meaning it did not render anything. Is my logic flawed? Anyway, thanks alot Barand. Quote Link to comment https://forums.phpfreaks.com/topic/107003-solved-php-mysql-does-not-reder-any-fields/#findComment-548555 Share on other sites More sharing options...
Barand Posted May 23, 2008 Share Posted May 23, 2008 I guess the Resource ID#2 was referring to a second row that did not exist, meaning it did not render anything. Is my logic flawed? Yes. If a query fails due to an error it returns false. If it works it returns a "Resource". The resource number is just its internal address of the recordset returned by the query. Quote Link to comment https://forums.phpfreaks.com/topic/107003-solved-php-mysql-does-not-reder-any-fields/#findComment-548569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.