Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate array and print data in a table cell 1

Status
Not open for further replies.

kitfox69

Technical User
Aug 6, 2008
36
0
0
US
I am writing a tagging template for our company and have run into ome trouble printing a list of database balues in a single cell.

Code:
<?php

$itemidpass = $_GET['itemid'];

$username="test";
$password="tester";
$database="test";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT * FROM sample WHERE item_id = '$itemidpass' ";
$result = mysql_query($query);

if (!$result) {
    echo 'Could not run query: ' . mysql_error();
    exit;
}
    $item = mysql_fetch_row($result);
    $desc = $item[5] . ' ' . $item[2];
    $imgsrc = ' ' . 'src="/rugtags/images/surya/' .$item[1] .'" alt="" width="250" height="158"';

    $query2 = "SELECT item_sizes FROM sizes WHERE item_id = '$itemidpass' ";

    $result2 = mysql_query($query2);
    
    function sizes()
    {
        WHILE($row = mysql_fetch_assoc($result2)){
        echo $row[0];
    }
    }

echo '<table align="center" border="0" bordercolor="#000000" cellpadding=0>';
echo '<tr>';
echo '<td colspan=5 width=800 height=40 bgcolor="#000066"></td>';
echo '</tr>';
echo '<tr>';
echo '<td rowspan=5 width = 16></td>';
echo '<td colspan=4 width=785 valign="bottom"><font face="Verdana" size="4"><u>' .$item[0] .'</u><big>_______________________________________</big></font></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=4 width=785 valign="top"><font face="Verdana" size="4">' .$desc .'</font></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=4 width=785 height=65></td>';
echo '</tr>';
echo '<tr>';
echo '<td width=250 height=158 rowspan=2 align=top><img' .$imgsrc .'  /></td>';

echo '<td rowspan=2 width=16 style="font-size:96px; align:right"><font face="Impact"><b>$</b></font></td>';

echo '<td align=right rowspan=2 height=190 style="font-size:1000%; align:left"><font face="Impact"><b>' .$item[3] .'</b></font></td>';
echo '<td style="font-size:96px; align:left"><font face="Impact"><b>' ,$item[4] .'</b></font></td>';
echo '</tr>';
echo '<tr>';
echo '<td>' .$item[0] .'</td></tr>';
echo '</table>';
echo '<br /><br /><br /><br /><br /><br /><br /><br />';
echo '<table align="center" border="0" bordercolor="#000000" cellpadding="0">';
echo '<tr>';
echo '<td width=200 align=center><font face="Verdana" size="4"><u>COLLECTION</u></font></td>';
echo '<td width=200 align=center><font face="Verdana" size="4"><u>DESIGN</u></font></td>';
echo '<td width=200 align=center><font face="Verdana" size="4"><u>DETAILS</u></font></td>';
echo '<td width=200 align=center><font face="Verdana" size="4"><u>SIZES</u></font></td>';
echo '</tr>';
echo '<tr>';
echo '<td width=200 height=35 valign=bottom align=center><font face="Verdana" size="4">' .$item[5] .'</font></td>';
echo '<td width=200 height=35 valign=bottom align=center><font face="Verdana" size="4">' .$item[6] .'</font></td>';
echo '<td width=200 height=35 valign=bottom align=center><font face="Verdana" size="4">' .$item[7] .'</font></td>';
echo '<td rowspan=5 height=500 width=200 valign=top align=center><font face="Verdana" size="3">' .sizes () .'</td>';
echo '</tr>';
echo '<tr>';
echo '<td width=200 height=35 align=center></td>';
echo '<td width=200 height=35 align=center></td>';
echo '<td width=200 height=35 align=center>' .$item[8] .'</td>';
echo '</tr>';
echo '<tr>';
echo '<td width=200 height=35 align=center><font face="Verdana" size="4">MONTAGE&nbsp;PLANS</font></td>';
echo '<td width=200 height=35 align=center></td>';
echo '<td width=200 height=35 align=center>' .$item[9] .'</td>';
echo '</tr>';
echo '<tr>';
echo '<td margin-left=12px align=left colspan=3 width=200 height=100 align=center><font face="Verdana" size="3">MFSARG00299 - UP TO $299 covered for only $49.99<br />MFSARG00799 - UP&nbsp;TO&nbsp;$799 covered for only $79.99<br />MFSARG01299 - UP&nbsp;TO&nbsp;$1299 covered for only $129.99<br />MFSARG04999 - UP&nbsp;TO&nbsp;$4999 covered for only $199.99<br />MFSARG20000 - UP&nbsp;TO&nbsp;$20000 covered for only $399.99</font></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan=3 width=200 height=100 align=center><font face="Verdana" size="3"><b>FOR SPECIAL ORDERS</b> - Use <b>ZSU-SPECIAL</b> and add Collection, Design, Size and Price into sales notes</font></td>';
echo '</tr>';
echo '</table>';
?>

My problem is on line 23 through 32 creating the function to call the list and line 71 where i echo the statement for the particular cell and want to call the function.

Currently it shows my last effort and doesn't work. Either I have parameter problems with the array or I have no errors but also no print for that cell.

Can anyone point me at a function that will fetch a one column, multiple row array and then how to print the list in that one cell, one value on top of another in a one column list?

kitfox
 
read up about variable scope. $result2 is not a variable that is accessible within the function scope. you would need to globalise it.

read up also in the heredoc syntax. it is much easier to debug code if the blocks are properly congruent.

Code:
<?php

$itemidpass = $_GET['itemid'];

$username="test";
$password="tester";
$database="test";

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

/** get item data **/
$query = "SELECT * FROM sample WHERE item_id = '" . mysql_real_escape_string($itemidpass) . "' ";
$result = mysql_query($query) or die('Could not run query: ' . mysql_error());

$item = mysql_fetch_row($result);
$desc = $item[5] . ' ' . $item[2];
$imgsrc = ' src="/rugtags/images/surya/' . $item[1] .'" alt="" width="250" height="158" ';
/** end get item data **/

/**   get sizes **/
$query2 = "SELECT item_sizes FROM sizes WHERE item_id = '" . mysql_real_escape_string($itemidpass) . "' ";
$result2 = mysql_query($query2) or die(mysql_error());
$sizes = array(); 
while($row = mysql_fetch_assoc($result2)):
	$sizes[] = $row['item_sizes'];
endwhile;
$sizes = implode (', ', $sizes);
/**   end get sizes **/

/** output table **/

echo <<<HTML
<table align="center" border="0" bordercolor="#000000" cellpadding=0>
    <tr>
        <td colspan=5 width=800 height=40 bgcolor="#000066">
        	&nbsp;
        </td>
    </tr>
    <tr>
        <td rowspan=5 width=16>
        	&nbsp;
        </td>
        <td colspan=4 width=785 valign="bottom">
            <font face="Verdana" size="4">
                <u>
                    {$item[0]}
                </u>
                <big>
                    _______________________________________
                </big>
            </font>
        </td>
    </tr>
    <tr>
        <td colspan=4 width=785 valign="top">
            <font face="Verdana" size="4">
                $desc
            </font>
        </td>
    </tr>
    <tr>
        <td colspan=4 width=785 height=65>
        </td>
    </tr>
    <tr>
        <td width=250 height=158 rowspan=2 align=top>
            <img src="$imgsrc"/>
        </td>
        <td rowspan=2 width=16 style="font-size:96px; align:right">
            <font face="Impact">
                <b>$</b>
            </font>
        </td>
        <td align=right rowspan=2 height=190 style="font-size:1000%; align:left">
            <font face="Impact">
                <b>{$item[3]}</b>
            </font>
        </td>
        <td style="font-size:96px; align:left">
            <font face="Impact">
                <b>{$item[4]}</b>
            </font>
        </td>
    </tr>
    <tr>
        <td>
            {$item[0]}
        </td>
    </tr>
</table>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<table align="center" border="0" bordercolor="#000000" cellpadding="0">
    <tr>
        <td width=200 align=center>
            <font face="Verdana" size="4">
                <u>
                    COLLECTION
                </u>
            </font>
        </td>
        <td width=200 align=center>
            <font face="Verdana" size="4">
                <u>
                    DESIGN
                </u>
            </font>
        </td>
        <td width=200 align=center>
            <font face="Verdana" size="4">
                <u>
                    DETAILS
                </u>
            </font>
        </td>
        <td width=200 align=center>
            <font face="Verdana" size="4">
                <u>
                    SIZES
                </u>
            </font>
        </td>
    </tr>
    <tr>
        <td width=200 height=35 valign=bottom align=center>
            <font face="Verdana" size="4">
                {$item[5]}
            </font>
        </td>
        <td width=200 height=35 valign=bottom align=center>
            <font face="Verdana" size="4">
                {$item[6]}
            </font>
        </td>
        <td width=200 height=35 valign=bottom align=center>
            <font face="Verdana" size="4">
                {$item[7]}
            </font>
        </td>
        <td rowspan=5 height=500 width=200 valign=top align=center>
            <font face="Verdana" size="3">
            $sizes
        </td>
    </tr>
    <tr>
        <td width=200 height=35 align=center>
        </td>
        <td width=200 height=35 align=center>
        </td>
        <td width=200 height=35 align=center>
            {$item[8]}
        </td>
    </tr>
    <tr>
        <td width=200 height=35 align=center>
            <font face="Verdana" size="4">
                MONTAGE&nbsp;PLANS
            </font>
        </td>
        <td width=200 height=35 align=center>
        </td>
        <td width=200 height=35 align=center>
            {$item[9]}
        </td>
    </tr>
    <tr>
        <td margin-left=12px align=left colspan=3 width=200 height=100 align=center>
            <font face="Verdana" size="3">
                MFSARG00299 - UP TO $299 covered for only $49.99
                <br/>
                MFSARG00799 - UP&nbsp;TO&nbsp;$799 covered for only $79.99
                <br/>
                MFSARG01299 - UP&nbsp;TO&nbsp;$1299 covered for only $129.99
                <br/>
                MFSARG04999 - UP&nbsp;TO&nbsp;$4999 covered for only $199.99
                <br/>
                MFSARG20000 - UP&nbsp;TO&nbsp;$20000 covered for only $399.99
            </font>
        </td>
    </tr>
    <tr>
        <td colspan=3 width=200 height=100 align=center>
            <font face="Verdana" size="3">
                <b>FOR SPECIAL ORDERS</b>
                - Use <b>ZSU-SPECIAL</b>
                and add Collection, Design, Size and Price into sales notes
            </font>
        </td>
    </tr>
</table>
HTML;
?>
 
Thank you so much.

I admit I feel a bit embarrassed now for not commenting and structuring this before posting and want to extra thank you for taking the time to do that.

That said, I do see the listing now under my sizes column. It is printed correctly for each value but this did not put them in a vertical list... the values run on until they reach the border then start a new line. How would I change that portion to display the values like the below...

Value1
Value2
Value3

Also interested in knowing how I might add another column of data into that array so it might look like this...

Value1 - Price1
Value2 - Price2
Value3 - Price3

I was also just asked if I could use a custom font we are planning on purchasing and installing on the server this will be running from. Impact URW BOLD CONDENSED. How would I call something like that in HTML/PHP?
 
change this line
Code:
$sizes = implode (', ', $sizes);
to
Code:
$sizes = implode ('<br/>', $sizes);

for the remainder I invite you to establish separate threads in the appropriate forum
 
TY jpadie I will change that and test later tonight and post my other questions appropriately.
 
kitfox
You can help others spot this as a helpful post if you click on the "Thank jpadie for this valuable post!" link at the bottom of his reply to you.


If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top