[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Running a db query, outputting as HTML table, but need to add 2 additional columns. How?

Asked by eddo9696 in PHP Scripting Language, PHP and Databases, PHP for Windows

Tags: database query table columns add image

Hello,
I am running a query against a mysql db and the output is sent to a function that creates a html table. It works, but now I need to be able to add two additional columns. One of the columns needs to contain a submit button(no functionality necessary), the other a link to an image that is stored locally. The file name of the image is stored in the database and I've written a function to change the file name into an img tag in html.  I believe that the key to solving this is editing my function for the html table but am not quite sure how to do it. I've attached my img tag function and html table loop. Any suggestions are appreciated. Thanks.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
/***********************************************************************
* Function to print query as table
*
* Argument(s): 
* $result 		- Result from SQL query
***********************************************************************/ 
function dbtable($result) 
{
  ?><table border="1" width="80%"><tr><?php
  	if(! $result) 
		{ 
		?><th>result not valid</th><?php 
		}
  	else 
		{
		$i = 0;
		while ($i < mysql_num_fields($result)) 
		{
		  $meta = mysql_fetch_field($result, $i);
		  ?><th style="white-space:nowrap"><?=$meta->name?></th><?php
		  $i++;
		}
    ?></tr><?php
    if(mysql_num_rows($result) == 0) 
		{ 
		?><tr><td colspan="<?=mysql_num_fields($result)?>">
		<strong><center>no result</center></strong>
		</td></tr><?php 
		} 
	else
		while($row=mysql_fetch_assoc($result)) 
		{
		?><tr style="white-space:nowrap"><?php
			foreach($row as $key=>$value) 
			{ 
			?><td><?=$value?></td><?php 
			}
			?></tr><?php
		 }
  }
  ?></table><?php
} 

/***********************************************************************
* Function to create HTML image tag
*
* Argument(s): 
*	$imagename	string	- Name of image file
*
* Returns: Image link
***********************************************************************/ 
function nametoimage($imagename)
{
  if ($imagename != null)  
  {
    $result = "<img src=\"images/{$imagename} \" />" ;
  }
echo $result;  
}
[+][-]11/08/09 05:12 AM, ID: 25770357Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 10:33 AM, ID: 25771311Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 01:07 AM, ID: 25774343Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/09 01:21 AM, ID: 25774417Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625