Jump to content
phpsane

Mysqli - Can You Not Do These Short-Cuts ?

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 />";
	

 

 

 

Edited by phpsane

Share this post


Link to post
Share on other sites
48 minutes ago, Barand said:

Why don't you RTFM for a change instead of asking us to read it to you?

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

Did you ? :D

Edited by phpsane

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
17 hours ago, ginerjm said:

PS - There are no 'shortcuts' in php. 

What about

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

versus

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

 

  • Thanks 1

Share this post


Link to post
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 . . . 

Share this post


Link to post
Share on other sites

It isn't a ternary in the second example, it's php7's new coalesce operator.

BTW you could

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

 

Share this post


Link to post
Share on other sites

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.