Jump to content

Mysqli - Can You Not Do These Short-Cuts ?


phpsane

Recommended Posts

Long Version Associative Array:

	/* associative array */
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
echo $row["name"]." ".$row["author_name"]." ".$row['price'];
	

Short Version Associative Array:

	($row = mysqli_fetch_assoc($result))
	

As in:

	 while ($row = mysqli_fetch_assoc($result)) {
        echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />";
	

Q1. Correct ?

 

Q2. Long Version Numeric Array:

	/* numeric array */
$row = mysqli_fetch_array($result, MYSQLI_NUM);
echo $row[0]." ".$row[1]." ".$row[2];
	

Can you not do short Version like this :

	($row = mysqli_fetch_num($result))
	

As in:

	 while ($row = mysqli_fetch_num($result)) {
        echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />";
	

 

Q3. Long Version "Both":

	/* associative and numeric array */
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
echo $row[0]." ".$row["author_name"]." ".$row[2];
	

Can you not do short Version like this:

	($row = mysqli_fetch_both($result))
	

As in:

	 while ($row = mysqli_fetch_both($result)) {
        echo $row["name"]." ".$row["class"]." ".$row['roll_no']."<br />";
	

 

 

 

Link to comment
Share on other sites

4 hours ago, phpsane said:

I did not find these shortcuts I mention in the FM.

Did you ? :D

I did. Because I'm not looking for some damned "shortcuts" in the manual. I'm looking for information about the functions you don't understand how to use.

Link to comment
Share on other sites

Agreeing with the others I find you annoying.  I will probably get a censure for my comment but after just dealing with one of your other posts under one of your other identities I cannot understand why you exist since it is obviously not for any need to get real tasks done since all you do is ask stuff that YOU SHOULD ALREADY KNOW if you had any gumption.

PS - There are no 'shortcuts' in php.  Stop using that term.  Try and learn that.

Link to comment
Share on other sites

2 hours ago, ginerjm said:

Agreeing with the others I find you annoying.  I will probably get a censure for my comment but after just dealing with one of your other posts under one of your other identities I cannot understand why you exist since it is obviously not for any need to get real tasks done since all you do is ask stuff that YOU SHOULD ALREADY KNOW if you had any gumption.

PS - There are no 'shortcuts' in php.  Stop using that term.  Try and learn that.

FYI don't expect a reply from him. He won't be making any more of those.

Link to comment
Share on other sites

On 2/5/2019 at 1:41 AM, Barand said:

What about


$amount =  (isset($_GET['amount'])) ? $_GET['amount'] : 0;

versus


$amount = $_GET['amount'] ?? 0;

Mind blown! I never knew the ternary operator could be used like that. I typically use it for defining a variable from POST/GET data similar to that. However, I typically trim() the value within the true condition, so it may not be as useful as I would like, but still . . . 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.