Jump to content

Recommended Posts

Hi, I'm having trouble returning a full row count from my database. The following code returns "1" column instead of "24" columns.

 

$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME)

$query = "SELECT * FROM table";	

	if($stmt = $this->conn->prepare($query))
	{
		$stmt->execute();

		if($stmt->fetch())
		{
			if ($stmt->field_count) {
				$result = $stmt->store_result();
			}
			$stmt->close();
			return $result;
		}
	}

You may want to use mysql_num_rows() to count your rows with.

 

http://us.php.net/manual/en/function.mysql-num-rows.php

 

I tried that, but unfortunately get the error: "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource".

You need to store results so you can count them PHP: mysqli::store_result.

 

Edit: actually look at this if you are using prepared statements: PHP: mysqli_stmt::num_rows - Manual

 

Read the Typer85 at gmail dot com's comment at the bottom of the page.

OK, I used "DESCRIBE table" to get it working:

 

$query = "DESCRIBE table";   
      
      if($stmt = $this->conn->prepare($query))
      {
         $stmt->execute();
         $stmt->store_result();
         echo $stmt->num_rows();
         $stmt->close();
      }

 

NOW.. All I need is to return the names of each field...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.