In the process of converting an old web application I did from MYSQL to MYSQLi and am a bit lost with echoing a result,

This code works in the old app with Mysql:

<textarea  name="dump" style="width:300px; height:400px;">
<?php 
include ("../connect.php");
$content = mysql_query("SELECT $field FROM customer WHERE cusid = '$cusid'") ;
echo mysql_result ($content,0); 
?>
</textarea>

This code does not with Mysqli, i know the syntax is wrong, just dont know were.. thanks

<textarea  name="dump" style="width:300px; height:400px;">
<?php 
include ("../connect.php");
$content ='SELECT $field FROM customer WHERE cusid = "$cusid"';
$content = $db->query($content);
echo mysqli_result ($content);
?>
</textarea>

The query is identical to the one that works? the link you provided is for MYSQL, im now doing this with MYSQLi

the link you provided is for MYSQL

I know... read the warning.

The query is identical to the one that works?

It's not, at least not in the above code snippet. Check the quoting.

Im confused, I know its depreciated as per the warning, thats why Im not using it in the second snippet, just dont know what to use instead,

the query is the same, I just had to lay it out differently so it works with mysqli

Quote:

Alternatives to this function include:
- mysqli_data_seek() in conjunction with mysqli_field_seek() and mysqli_fetch_field()

doesnt work, looks like Ill have to keep using mysql :(

include ("../connect.php");
$content = "SELECT $field FROM customer WHERE cusid = '$cusid'";
$content = $db->query($content);
echo mysqli_fetch_field($content);

Appreciate your assistance, but I tried a few variations of these, but nothing, it just seems daft that mysqli is Improved , yet you need 3 or 4 more lines of code just to echo the returned result!
i tried echo mysqli_free_result($content);no luck there either.

My example in the above link is fully functional. If you change that to be used with your database and table, do you get a result?

here is the code (attempting to follow your example)

<textarea  name="dump" style="width:300px; height:400px;">
<?php 
include ("../connect.php");
$content = "SELECT $field FROM customer WHERE cusid = '$cusid'";
$content = $db->query($content);
if ($content){
while ($recordobj  = $content->fetch_object()){
echo $recordobj;
}
}
?>
</textarea>

Catchable fatal error: Object of class stdClass could not be converted to string in C:\wamp\www\customerdb\wysiwyg\index.php on line 27

Got it!
this now works..

<textarea  name="dump" style="width:300px; height:400px;">
<?php 
include ("../connect.php");
$content = $db->query("SELECT $field FROM customer WHERE cusid = '$cusid'") ->fetch_object()->$field;
print $content;
?>
</textarea>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.