/    Sign up×
Community /Pin to ProfileBookmark

Get a result date from sql with php?

hi, i have a date on mysqli and i am tryying to get it with php with this code

[code=php]
$queryt = mysqli_query($link,”SELECT mest FROM inventario WHERE user = ‘$id'”);
[/code]

but this dont return nothing, then i used a fetch arrayy but just returned the word “array” someone know the function for get the result of a date on mysqli ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 17.2018 — mysqli_query() does not return a value or even a result row. For a select query, it either returns a mysqli_result object, or false if there was some error. So you could do something like:
[code=php]
$result = mysqli_query($link,"SELECT mest FROM inventario WHERE user = '$id'");
if($result == false) {
error_log(mysqli_error($link));
die("DB error, error message logged");
}
if(($row = mysqli_fetch_row($result)) != false) {
$queryt = $row[0];
}
else {
// whatever you want to do if no match was found
}
[/code]
Copy linkTweet thisAlerts:
@PachiMcauthorJan 17.2018 — mysqli_query() does not return a value or even a result row. For a select query, it either returns a mysqli_result object, or false if there was some error. So you could do something like:
[code=php]
$result = mysqli_query($link,"SELECT mest FROM inventario WHERE user = '$id'");
if($result == false) {
error_log(mysqli_error($link));
die("DB error, error message logged");
}
if(($row = mysqli_fetch_row($result)) != false) {
$queryt = $row[0];
}
else {
// whatever you want to do if no match was found
}
[/code]
[/QUOTE]



ty i couldnt find on w3school information but worked, btw what mean the row[0] ? because is not an array is only 1 value right ?
Copy linkTweet thisAlerts:
@NogDogJan 18.2018 — The result row is an array, but since you only selected one field, it's an array with only one element, thus the zeroth element of that array.

The PDO database extension has a fetchColumn() method which makes it simpler in that sort of case (only need that one method call to get that one column), but it does not appear that the mysqli_result object has the same sort of thing, so it takes that extra step to actually grab the value of interest.

.
Copy linkTweet thisAlerts:
@PachiMcauthorJan 18.2018 — The result row is an array, but since you only selected one field, it's an array with only one element, thus the zeroth element of that array.

The PDO database extension has a fetchColumn() method which makes it simpler in that sort of case (only need that one method call to get that one column), but it does not appear that the mysqli_result object has the same sort of thing, so it takes that extra step to actually grab the value of interest.

.[/QUOTE]


o tyy, but i am not studyng pdo yet i dont see necessary ty !;D
Copy linkTweet thisAlerts:
@NogDogJan 18.2018 — Not saying you have to use PDO -- though personally I prefer it. ? I find it a bit cleaner to use, along with the benefit that you can generally use the same code flow/methods regardless of whether you use MySQL or any other supported DBMS. (I happen to use PostgreSQL a lot.) One step at a time is fine, however. ?
×

Success!

Help @PachiMc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...