Link to home
Start Free TrialLog in
Avatar of cxs410
cxs410

asked on

Calling PHP inside of ''

Below i have attached a code snippit.

i'm having a problem doing this:
$data .= '<tr class="<? tablerowswitch(); ?>">

How can get get this to work.. I don't think i can call the php inside of another function..?
$data .= '<tr class="<? tablerowswitch(); ?>">
						<td id="ws_sub_table_level">'.$row['level_code'].'</td>
						<td id="ws_sub_table_part">'.$row['related_part_number'].'</td>
				  		<td id="ws_sub_table_desc">'.$row['description'].'</td>
				  		<td id="ws_sub_table_used">'.$row['qty'].' '.$row['unit_measure'].'</td>
				  		<td id="ws_sub_table_stock">'.$row_help['qty'].'</td>
					  </tr>'

Open in new window

Avatar of littleknown
littleknown

$data .= ''

Try that. It's been a little while since I've bothered with PHP. I'm used to Rails' hash replacement.
Here is your problem...  best illustrated with an example.

The result of $somevariable will be:
$sampletext How are you today?

The result of $anothervariable will be:
Hi Mum! How are you today?

Using single quotes will not parse any variables.

Hope this makes sense!
<? php
 
$sampletext = 'Hi mum!';
 
// Using singles quotes ' to enclose the string
$somevariable = '$sampletext How are you today?';
 
// Using double quotes " to enclose the string
$anothervariable = "$sampletext How are you today?";
 
?>

Open in new window

Avatar of cxs410

ASKER

arse error: parse error, unexpected '<'
May I ask what this code snippet below returns?
$data = '<tr class="' . tablerowswitch() . '">';
 
echo $data;

Open in new window

Avatar of cxs410

ASKER

What it should return is either the value odd or even, however the exact code you posted doesn't return anything it causes the same < error, (because the closing ' and ;) but when i remove the ' and ; it processes but basically breaks the page so the long and short.. the returned value shoudl look like

or
Avatar of cxs410

ASKER

this is part of a bigger function (attached)

function items_table($part_number)
	{
		global $connect;
		$data = '<br><table id="mytable2">
					<thead>
                          <tr>
                          	<th id="ws_th_sub_table_level">level</th>
                            <th id="ws_th_sub_table_part">part #</th>
                            <th id="ws_th_sub_table_desc">description </th>
                            <th id="ws_th_sub_table_used">used per</th>
                            <th id="ws_th_sub_table_stock">stock</th>
                          </tr>
					</thead>';
		$select="SELECT level_code,description,unit_measure,qty,related_part_number FROM sfc_relation_table,sfc_itemMaster  WHERE fk_part_number='".$part_number."' AND related_part_number=part_number";
		if (!$result = mysql_query($select, $connect))
		{
			echo $select;
			echo mysql_error();
			exit;
		}
		while($row = mysql_fetch_assoc($result))
		{
			$select="SELECT qty FROM sfc_current_stocks WHERE fk_part_number='".$row['related_part_number']."'";
			if (!$result_stock = mysql_query($select, $connect))
			{
				echo $select;
				echo mysql_error();
				exit;
			}
			$row_help = mysql_fetch_assoc($result_stock);
			if(empty($row_help))
				$row_help['qty'] = (float)0;
			$data .= '<tr class="<? tablerowswitch(); ?>">
						<td id="ws_sub_table_level">'.$row['level_code'].'</td>
						<td id="ws_sub_table_part">'.$row['related_part_number'].'</td>
				  		<td id="ws_sub_table_desc">'.$row['description'].'</td>
				  		<td id="ws_sub_table_used">'.$row['qty'].' '.$row['unit_measure'].'</td>
				  		<td id="ws_sub_table_stock">'.$row_help['qty'].'</td>
					  </tr>';
		}
		$data .= '</table><br/><br/>';
		return $data;
		
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lordgobbledegook
Lordgobbledegook

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cxs410

ASKER

That seems like it comes close to working:  
<table id="mytable">
			<caption>Current Demand</caption> 
			<col >
			<col >
 
			<col >
			<col >
			<col >
			<col >
			<col >
			<thead>
                          <tr>
                            <th id="ws_th_part" >part #</th>
 
                            <th id="ws_th_description" >description </th>
                            <th id="ws_th_batch" >batch</th>
                            <th id="ws_th_total" >tot dem.</th>
							<th id="ws_th_hot" >hot dem</th>
                            <th id="ws_th_possible" >possible</th>
                            <th id="ws_th_status" >status</th>
 
                          </tr>
            </thead>
						         <tbody>
                          <tr class="odd">
						  	<!--
                            <td><a href="#selection" onclick="xajax_show_item('1400-0071');">1400-0071</a></td>
							-->
							<td id="ws_part_number"><a href="#" onclick="disappear('divNote1400-0071');return false;">1400-0071</a></td>
                            <td id="ws_description">Cross Support 30.0 - Welded</td>
                            <td id="ws_batch">0.00</td>
 
                            <td id="ws_total">
								91							</td>
							<td id="ws_hot"><span style="color:#FF0000"><strong>86</strong></span></td>
                            <td id="ws_possible">3</td>
                            <td id="ws_status"><a href="#selection" onclick="xajax_show_item('1400-0071');">Not Assigned</a></td>
                          </tr> 
						  <tr>
 
						  	<td></td>
							<td colspan="6"><div id="divNote1400-0071" style="display:none">evenoddeven<br><table id="mytable2">
					<thead>
                          <tr>
                          	<th id="ws_th_sub_table_level">level</th>
                            <th id="ws_th_sub_table_part">part #</th>
                            <th id="ws_th_sub_table_desc">description </th>
 
                            <th id="ws_th_sub_table_used">used per</th>
                            <th id="ws_th_sub_table_stock">stock</th>
                          </tr>
					</thead><tr class="">
						<td id="ws_sub_table_level">Sub-Process</td>
						<td id="ws_sub_table_part">1400-0076</td>
				  		<td id="ws_sub_table_desc">Rect.Tube 1.5 x 1.0 x 16ga x 24.50 - Saw</td>
 
				  		<td id="ws_sub_table_used">1.000000 Ea</td>
				  		<td id="ws_sub_table_stock">100.00</td>
					  </tr>

Open in new window

Avatar of cxs410

ASKER

Note: What is happening is that there are two seperate tables at play here.  The second one is nested inside of the 1st and appears when the value in like 28 is clicked on.

Note like 42 that is what is returned from the piece of code i pasted.  It should nto be appearing here.

Additionaly on line 52 where it should appear (either even or odd) class= is blank! :)
I'm not sure what you mean?  Lines 28 and 42 are blank.

If line 52 is not showing even or odd - well, it's hard to say.  My first call would be checking the code within the tablerowswitch() function.
Avatar of cxs410

ASKER

Thanks for your effort!