Darkmatter5 Posted October 23, 2008 Share Posted October 23, 2008 I have this echo string that isn't giving me what I'm needing. Any help is greatly appreciated! elseif($type=="edit_item") { $query=mysql_query("SELECT cab_name, fol_name, items.* FROM items JOIN folders ON(items.folder_id=folders.folder_id) JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id) WHERE items.item_id=$_GET[item_id] ") or die(mysql_error()); echo "<p> <table class='edit' width='100%' border='1' cellspacing='1' cellpadding='3'> <caption><b>ITEM EDITING</b></caption>"; while($row=mysql_fetch_array($query)) { echo "<tr><td colspan='4'>PATH: $row[cab_name] -> $row[fol_name] -> </td></tr> <tr><td colspan='4'> </td></tr> <tr> <td width='150'>Item Name:</td> <td colspan='3'><input name='item_name' type='text' class='text_boxes' tabindex='12' size='50' maxlength='50' value='$row[item_name]'/></td> </tr> <tr> <td>Item Description:</td> <td colspan='3'><input name='item_description' type='text' class='text_boxes' tabindex='13' size='80' maxlength='300' value='$row[item_description]'/></td> </tr> <tr> <td>Folder:</td> <td colspan='3'><?php $ec->folder_list(14,'',$row[folder_id]); ?></td> </tr>"; } echo "</table>"; } Here's what "View Source" gives me. <table class='edit' width='100%' border='1' cellspacing='1' cellpadding='3'> <caption><b>ITEM EDITING</b></caption><tr><td colspan='4'>PATH: Bills -> Telephone, Cable & Internet -> </td></tr> <tr><td colspan='4'> </td></tr> <tr> <td width='150'>Item Name:</td> <td colspan='3'><input name='item_name' type='text' class='text_boxes' tabindex='12' size='50' maxlength='50' value='something'/></td> </tr> <tr> <td>Item Description:</td> <td colspan='3'><input name='item_description' type='text' class='text_boxes' tabindex='13' size='80' maxlength='300' value='lhhklhjlh'/></td> </tr> <tr> <td>Folder:</td> <td colspan='3'><?php (14,'',2); ?></td> </tr> </table> How can I get it to output the "$ec->folder_list" part? Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/ Share on other sites More sharing options...
aeonsky Posted October 23, 2008 Share Posted October 23, 2008 Think it should be... <td colspan='3'>".$ec->folder_list(14,'',$row[folder_id])."</td> Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673062 Share on other sites More sharing options...
DarkWater Posted October 23, 2008 Share Posted October 23, 2008 Exit out of the string and concatenate the function in there. Example: echo "something something something" . microtime() . "something"; Also, I'd personally just exit out of PHP for that whole HTML block and go back in to echo things, because it looks really sloppy and confusing in an echo. Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673063 Share on other sites More sharing options...
Darkmatter5 Posted October 23, 2008 Author Share Posted October 23, 2008 Okay that all makes sense, but also another problem I'm now encountering is that this php segment is inside a php function that is called from a regular page. Now if I'm wanting to call my list_folders function how can I call it when it's not defined inside this function? How can I call a function from within another function? Do I simply have to include the following code inside the function to define list_folder()? require('library/ecabinet_funcs.php'); $ec = new ecabinet(); Also I have all my functions inside the file ecabinet_funcs.php, so if the first echo segment (which is inside a function named show_filing) is in the same file as the folder_list function, am I able to define a function from the same page I'm in? If that doesn't make sense let me know. Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673092 Share on other sites More sharing options...
DarkWater Posted October 24, 2008 Share Posted October 24, 2008 Elaborate a little please. >_< Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673336 Share on other sites More sharing options...
Darkmatter5 Posted October 24, 2008 Author Share Posted October 24, 2008 Okay, I have a file named ecabinet_funcs.php. It contains all my functions, each individual page that's displaed on my site require this ecabinet_funcs.php file. In a file named res_edit.php I call a function from ecabinet_funcs.php with this code "$ec->show_filing(edit_item);". This function is below: show_filing(); function show_filing($type) { include 'library/config.inc.php'; $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbnamemain); elseif($type=="edit_item") { $query=mysql_query("SELECT cab_name, fol_name, items.* FROM items JOIN folders ON(items.folder_id=folders.folder_id) JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id) WHERE items.item_id=$_GET[item_id] ") or die(mysql_error()); echo "<p> <table class='edit' width='100%' cellspacing='1' cellpadding='3'> <caption><b>ITEM EDITING</b></caption>"; while($row=mysql_fetch_array($query)) { echo "<tr><td colspan='2'><b>ITEM_ID: </b>$row[item_id]</td></tr> <tr><td colspan='2'><b>PATH: </b><a title='Cabinet'><font color='#BF1E36'>$row[cab_name]</font></a> -> <a title='Folder'><font color='#CEC013'>$row[fol_name]</font></a> -> </td></tr> <tr><td colspan='2'><b>FILE: </b>$row[file_name]</td></tr> <tr><td colspan='2'><hr></td></tr> <tr> <td width='150' align='right'>Item Name:</td> <td><input name='item_name' type='text' class='text_boxes' tabindex='12' size='50' maxlength='50' value='$row[item_name]'/></td> </tr> <tr> <td align='right'>Item Description:</td> <td><input name='item_description' type='text' class='text_boxes' tabindex='13' size='80' maxlength='300' value='$row[item_description]'/></td> </tr> <tr> <td align='right'>Folder:</td> <td> /*.folder_list(14,'',$row[folder_id]).*/ </td> </tr> <tr> <td align='right'>Type:</td> <td> /*.type_list(15,'',$row[folder_id]).*/ </td> </tr> <tr> <td colspan='2'> <fieldset> </fieldset> </td> </tr>"; } echo "</table>"; } mysql_close($conn); } Now as you can see in the above code, in the commented out part, I'm wanting to call another function named type_list(). This function I'm wanting to call (type_list()) also resides in the file ecabinet_funcs.php. So both functions are in the file ecabinet_funcs.php. So my dilemma is how can I call this type_list() function? Thanks! Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673682 Share on other sites More sharing options...
Darkmatter5 Posted October 24, 2008 Author Share Posted October 24, 2008 Here's another update to this, I tried putting "$ec=new ecabinet();" after "mysql_select_db($dbnamemain);" in the show_filing() funtion and then changed ".folder_list(14,'',$row[folder_id])." to ".$ec->folder_list(14,'',$row[folder_id])." but the dropdown lists that is correctly generated is generated and displayed before the table, not in the cell the code is written in. Why is it not displayed there? Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673693 Share on other sites More sharing options...
Darkmatter5 Posted October 24, 2008 Author Share Posted October 24, 2008 Well I fixed it sort of, Instead of using <td>" .$ec->folder_list(14),',$row[item_id]);. "</td> I'm now using <td>"; echo $ec->folder_list(14,'',$row[item_id]); echo "</td> So I broke out the function call completely from the echo. Link to comment https://forums.phpfreaks.com/topic/129833-solved-how-to-echo-php-code-inside-an-echo-weird-sounding-i-know-just-look-youll-see/#findComment-673839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.