homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Display bound array in PHP

 6:00 pm on Dec 7, 2011 (gmt 0)


The following array is defined in an include file. They represent facilities of one row of a mysql table:






How can I display these on the page of a specific record (recordset)?

Each element of an array is bound to a mysql field (true/false), and I would like to display array elements which are checked in db.
(Sorry for being not too accurate, I'm not so good even in questioning php issues, since I'm just trying to convert an old asp site to php, and I'm much better in VBscript)



 9:15 am on Dec 8, 2011 (gmt 0)

What do you mean by "bound"? How are you 'binding' a boolean field value with non-boolean elements in your array?


 10:17 am on Dec 8, 2011 (gmt 0)

I mean that e.g. $facilitiesgroup1[1]="Red" element is represented in a database table by 'facilitiesgroup1_1', and when it is checked (true), than that property (record) has this facility (Red).

That's what I would like to display in the individual property page in a grouped list, like:

<p><strong>Facilities-Group-1:</strong><br />
echo implode($facilitiesgroup1,', ');?>
<br />
<p><strong>Facilities-Group-2:</strong><br />
echo implode($facilitiesgroup2,', ');?>

Of course the above code alone doesn't do the job, beacuse it lists all facilities defined in the array, regardless of what is checked in that row of the database.


 11:31 am on Dec 8, 2011 (gmt 0)

Assuming your data structure is out of your control, then you can achieve this using variable variables [uk3.php.net]...

// $row is the result set from executing your DB query
$row = array();
$colName = 'facilitiesgroup1_1';
$colValue = '';
$row[$colName] = true; // Dummy data
if ($row[$colName]) {
$colParts = explode('_',$colName);
$colValue = ${$colParts[0]}[$colParts[1]]; // Variable variables
echo $colValue; // "Red"

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved