Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/
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.

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.

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.

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

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.