designersx
asked on
please correct the syntax
please correct the syntax
$field is dynamic, there is a problem of quotes.
$field is dynamic, there is a problem of quotes.
<?php while($rec=mysql_fetch_array($qid)){
echo $rec['$field'];
?>
$field is not correct, "field" might be database field where you are trying from the result
If the $field is dynamic and you have defined and set value for it in advance, then the code should be like below:
<?php while($rec=mysql_fetch_array($qid)){
echo $rec[$field];
?>
ASKER
logudotcom: sir this is where the trick is
$field is not static. it contains the field names which are dynamic, can be changed any time.
so we can't write as you said.
coolersport: as u said to write me , error is Cannot use object of type stdClass as array
$field is not static. it contains the field names which are dynamic, can be changed any time.
so we can't write as you said.
coolersport: as u said to write me , error is Cannot use object of type stdClass as array
ASKER
sir actually i have dynamic field names and i am displaying the dynamic field names , that is ok and now i want to display the record of those fields. that's why i wrote
while($rec=mysql_fetch_arr ay($qid)){
$rec[''] // i know that here we write the field name whose record we want to display but suppose if someone changes the field name then there would be a problem , that's why i asked you to tell me the syntax
}
i m increasing the marks of this question.
while($rec=mysql_fetch_arr
$rec[''] // i know that here we write the field name whose record we want to display but suppose if someone changes the field name then there would be a problem , that's why i asked you to tell me the syntax
}
i m increasing the marks of this question.
not sure
try likw this
echo $rec[ +"'" + $field+ "'"];
concatinate ''
try likw this
echo $rec[ +"'" + $field+ "'"];
concatinate ''
not sure
try likw this
echo $rec[ ."'" + $field . "'"];
concatinate ''
try likw this
echo $rec[ ."'" + $field . "'"];
concatinate ''
ASKER
hope u got me once again, i need to write
$rec[ // write dynamic field name here and not static ];
$rec[ // write dynamic field name here and not static ];
Try this:
<?php while($rec=mysql_fetch_array($qid))
foreach($rec as $fieldname => $fieldvalue)
echo $fieldvalue; // or echo $fieldname, it is up to you at this point
?>
ASKER
with first code
Cannot use object of type stdClass as array
with ur second code
Parse error: syntax error, unexpected '.', expecting ']'
Cannot use object of type stdClass as array
with ur second code
Parse error: syntax error, unexpected '.', expecting ']'
LOL, can you post the whole php code of this file?
ASKER
code
<form action="javascript:save()" method="post" name="frm">
<table border="1" bgcolor="#CCCCCC" width="80%"><tr><td colspan="2" align="center">Form</td></tr>
<tr><?php
$sql="select * from `$tname`";
$qid=mysql_query($sql) or die("could not select".mysql_error());
$i = 1;
while($rec=mysql_fetch_array($qid)){
while ($i < mysql_num_fields($qid)) {
$rec = mysql_fetch_field($qid, $i);
$field = $rec->name;
?><td><?php echo $field; ?></td>
<td><?php echo $rec[ +"'" + $field+ "'"]; ?></td>
<?php $i++; } } ?>
</tr></table></form>
ASKER
actually the concept is i want to fetch the field name ans then fetch the record of that field. all are dynamic , that's why?
ASKER
ur above code will show the record and field name as same , that is not my requirement sir
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
if u will see in my code, i am trying to fetch a field name somehow inside the record fetching.
ASKER
yes it worked, thanks coolersport: sir
No worries. That's why we need the whole context. Not just a snippet of it. Good luck.
If I am not out of point, php parser does not get inside a string surrounded by single quotes, thus:
<?php while($rec=mysql_fetch_arr ay($qid)){
echo $rec[$field];
?>
<?php while($rec=mysql_fetch_arr
echo $rec[$field];
?>
Open in new window