Hey guys,

Really hope someone can help me out here! I've been going smoothly on creating this new site with my MySQL database, but for some reason, on the current file I am making, the query gets executed but:

mysql_fetch_array($result, MYSQL_ASSOC)

only returns an empty array. To throw another spanner in to the works:

$num = mysql_num_rows($result);

Correctly returns one (1) row, while copy/pasting the echo'd query, phpBuilder executes the query and returns the row in question as it is supposed to be returned to the $row[] array.

After research, I have come across the page:

http://bugs.php.net/bug.php?id=41303

has exactly the same issue being pointed out - but supposeably it is not a bug, or has just never been re-visited..? The method I have used is no different to what all of the other files I have made in this project...

Suggestions anyone?

Cheers,
Jess.

    JessePHP wrote:

    The method I have used is no different to what all of the other files I have made in this project...

    Let's see the code then.

      Here is where it is not working:

      		include 'dblinks.php';
      		mysql_select_db("DB_NAME");
      
      	$date_exp = explode("-",$dateSel);
      	$time_exp = explode(":",$timeSel);
      
      	$c = mktime($time_exp[0],$time_exp[1],$time_exp[2],$date_exp[1],$date_exp[2],$date_exp[0]);
      
      	$d = ($c + (60 * getServValue($businessID, $serviceID,"duration")));
      
      	$time_exp = explode(":",getBizValue($businessID,strtolower(date("l",$dateSel)."_start")));
      	$start = mktime($time_exp[0],$time_exp[1],$time_exp[2],$date_exp[1],$date_exp[2],$date_exp[0]);
      
      	$time_exp = explode(":",getBizValue($businessID,strtolower(date("l",$dateSel)."_finish")));
      	$finish = mktime($time_exp[0],$time_exp[1],$time_exp[2],$date_exp[1],$date_exp[2],$date_exp[0]);
      
      	if (($c >= $start) && ($c <= $finish) && ($d <= $finish) && (getBizValue($businessID,strtolower(date("l",$dateSel)."_closed")) == 'F')) {
      		$query = "SELECT * FROM `TABLE_NAME` ";
      		$query .= "WHERE `business_id` = ".$businessID." and ";
      		$query .= "`date_main` = '".$dateSel."' ";
      		$query .= "ORDER BY `time_main`";
      
      		$result = mysql_query($query, $sql);
      		$num = mysql_num_rows($result);
      		echo 'Number of Rows: '.$num.'<BR>';
      		if ($num > 0) {
      			$arrDepth = array(); 
      			while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      				echo 'The date returned is: '.$row["date_main"].'<BR>';
      

      And here is an example of where it is:

      $query = "SELECT * FROM `TABLE_NAME` WHERE `business_id` = " . $_SESSION["login_id"];
      		$result = mysql_query($query, $sql);
      		$num = mysql_num_rows($result);
      		if ($num > 0) {
      			while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
      				// Spit it out
      				echo '<OPTION Value="' . $row["id"] .  '">' . $row["name"] . '</OPTION>';	
      			}
      		}
      

      In the first example, the date_main field returns null, the number of rows returns is one, so it does go in to the loop. While phpMyAdmin can show all fields in this same query. If I use:

      sizeof($row)
      

      This returns 0. How can that be when I use "SELECT *", and the mysql_num_rows returns the correct value of 1??? 😕

      Cheers,
      Jess.

        Hey guys,

        Good news, found a way to fix. Not as elegant as I'd hope, as it doesn't follow the same method as I have used in the site to date, but a fix is a fix.

        Instead of using mysql_fetch_array($result, MYSQL_ASSOC), I have used the default result type of MYSQL_BOTH.

        This didn't seem to allow the use of the field name still, but it was no longer empty and sizeof($row) correctly returned 1, just like mysql_num_rows.

        So I tried the index number of the field I needed to return and presto! 🙂

        Hope this helps someone down the line - I have no idea why I needed to switch in this instance...

        Cheers,
        Jess.

          Yes, I did try that to - no luck... Peculiar, huh? :queasy:

            What do your column names look like? (I'm just wondering if there is some particular string format that PHP does not recognize as an array key.)

              Write a Reply...