How to "Echo" a "Resource Id #6" from a MySQL Response in PHP

How do i echo a Resource id #6 from a MySql response in PHP?

You need to use a fetch function. for example:

$result = mysql_query(sprintf("SELECT TIMEDIFF(NOW(), '%s') as time_delta", $row['fecha']));
if($result){
$data = mysql_fetch_assoc($result);
echo $data['time_delta'];
}

However, i wouldnt use the mysql functions unless absolutely necessary. the mysql extension is NOT recommended for use in new projects. Instead you should use PDO with PDO_mysql or mysqli.

Get Resource id #5 instead of mySQL result

You are print a resource, not a result set.

Results are attached to it, but, its not an actual result set.

You need to fetch the result set by looping over the result set.

E.g.

$sql = "select bidang.idRel from relationship, bidang where relationship.idRel = bidang.idRel";
$result = mysql_query($sql);
if (mysql_num_rows($result)) {
while($row = mysql_fetch_assoc($result)) {
print_r($row);
}
}

Note: Don't use mysql_ functions. They are deprecated and will be removed in future PHP versions. Use mysqli_ instead.

Mysql query returning resource id #8 instead of desired value

mysql_query returns a resource. You need to get a row from it:

$query = mysql_query($selectShoeRatingQuery);
$row = mysql_fetch_row($query);
$shoeRating = $row[0];

And, unless you have no choice - don't use the mysql_ set of extensions! They're deprecated, and PDO et al. are better. And your query is vulnerable.

mySQL query returning Resource id #5

"Resource id #5: 0" is not an error. It means that you tried to echo $res instead of trying to use the $row variable, such as $row[column] for fetch_assoc, $row[0] for fetch_row, either/both for fetch_array.

The other answers explain the use of mysql_fetch_*

Also, mysql_* is deprecated. You should use mysqli_* or PDO functions instead.

Resource id returned when querying in php

Read the manual

Return Values

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning
resultset, mysql_query() returns a resource on success, or FALSE on
error.

So what you are seeing is expected behaviour.

If you're trying to get the results of your query you need to use one of the many functions available such as mysql_fetch_assoc().

FYI, you shouldn't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

PHP , SQL Resource id #10 . How can i get the value?

Why are you using echo before $result=??? this is what is showing ResourceId.

try this:

$result = mysql_query("SELECT car.currentkm FROM car INNER JOIN details ON car.id= ".$_REQUEST['cartype']." AND details.cartype = ".$_REQUEST['cartype']."");
if (mysql_num_rows($result)) {
$old = mysql_fetch_assoc($result);
echo $old['currentkm'];
}
else {
echo 1;
}

N.B.:

1- using $_REQUEST directly inside queries like you're doing makes your code WIDE open for sql injection. You need to clean your variables before using them inside queries.

2- mysql_* functions are deprecated and will be removed in later php versions, you should start using PDO or mysqli, additionally using prepared statements in one of these drivers will protect your code against sql injection without you having to clean the variables.



Related Topics



Leave a reply



Submit