phpsane Posted February 3, 2019 Share Posted February 3, 2019 (edited) 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 February 3, 2019 by phpsane Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/ Share on other sites More sharing options...
Barand Posted February 3, 2019 Share Posted February 3, 2019 Why don't you RTFM for a change instead of asking us to read it to you? 1 Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564188 Share on other sites More sharing options...
phpsane Posted February 3, 2019 Author Share Posted February 3, 2019 (edited) 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 ? Edited February 3, 2019 by phpsane Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564193 Share on other sites More sharing options...
requinix Posted February 3, 2019 Share Posted February 3, 2019 4 hours ago, phpsane said: I did not find these shortcuts I mention in the FM. Did you ? 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. Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564202 Share on other sites More sharing options...
ginerjm Posted February 4, 2019 Share Posted February 4, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564217 Share on other sites More sharing options...
requinix Posted February 4, 2019 Share Posted February 4, 2019 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. Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564219 Share on other sites More sharing options...
Barand Posted February 5, 2019 Share Posted February 5, 2019 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; 1 Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564255 Share on other sites More sharing options...
ginerjm Posted February 5, 2019 Share Posted February 5, 2019 Under this identity or all? Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564256 Share on other sites More sharing options...
Psycho Posted February 6, 2019 Share Posted February 6, 2019 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 . . . Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564265 Share on other sites More sharing options...
Barand Posted February 6, 2019 Share Posted February 6, 2019 It isn't a ternary in the second example, it's php7's new coalesce operator. BTW you could $amount = trim( $_GET['amount'] ?? 0 ); Quote Link to comment https://forums.phpfreaks.com/topic/308269-mysqli-can-you-not-do-these-short-cuts/#findComment-1564266 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.