0

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>
2
Contributors
11
Replies
26
Views
3 Years
Discussion Span
Last Post by websponge
0

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

0

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.

0

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

0

Quote:

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

Edited by pritaeas

0

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);
0

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.

0

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?

0

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

0

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>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.