Field List Retreival and edit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devain
Forum Commoner
Posts: 25
Joined: Wed May 10, 2006 9:00 pm
Contact:

Field List Retreival and edit

Post by devain »

Hello



I am having a little trouble with some coding that I am trying to do and was wondering if someone can help here is my delima


I have one database table (web_site_info) that consists of one entry with the ID(1) and one FIELD for that ID(1) called info.


When the Admin of the site modifies the page that inserts fields into the database it would consist of the new entry

ID FIELD/ EMPTY VALUE FIELD/ EMPTY VALUE

1 INFO HOMEPAGE


the fields dont exist until the user ads it each field on id(1) will eventually contail html code here is where my problem comes in

I do not know the fields till they are created and I need to dynamically list all fields without knowing the field names except or the id that the fields are contained in.


I want to be able to get a list of the fields and their values so I can parse them to a page to be edited. here is a example of some code I did where the field names are known is there a way to modify this if the field names are not known until they are created to be able to edit the fields







Any help would be appericated


Code: Select all

In the code that I am looking for the values are not known and are created and removed on the fly with another page. I was assuming that you could do the below with a 

(select * from website_info where id=1) but I am not sure how to go about the rest 


$res = mysql_query("select nondesignerhome,eyeglasseshome,sunglasseshome,special,price,quality,warranty,shipping,payment_methods,how_to_order,contact_info,track_orders,returns_info,faqs,links,terms,homepage,contactlenses,restrictions from website_info where id='1'") or die(mysql_error());
$special= mysql_result($res, 0, "special");
$price= mysql_result($res, 0, "price");
$quality= mysql_result($res, 0, "quality");
$shipping= mysql_result($res, 0, "shipping");
$payment= mysql_result($res, 0, "payment_methods");
$returns= mysql_result($res, 0, "returns_info");
$howto= mysql_result($res, 0, "how_to_order");
$tracking= mysql_result($res, 0, "track_orders");
$contact= mysql_result($res, 0, "contact_info");
$warranty= mysql_result($res, 0, "warranty");
$faqs= mysql_result($res, 0, "faqs");
$links= mysql_result($res, 0, "links");
$terms= mysql_result($res, 0, "terms");
$homepage= mysql_result($res, 0, "homepage");
$contactlenses= mysql_result($res, 0, "contactlenses");
$restrictions= mysql_result($res, 0, "restrictions");
$sunglasseshome= mysql_result($res, 0, "sunglasseshome");
$eyeglasseshome= mysql_result($res, 0, "eyeglasseshome");
$nondesignerhome= mysql_result($res, 0, "nondesignerhome");

echo("
<table>
<tr>

<td></td>
<td width=100% valign=top>


 <TABLE align=center class=topic style=\"BACKGROUND: #138b9f\" cellSpacing=1 cellPadding=0 width=\"80%\">
                          <TBODY>
                          <TR>
                            <TH style=\"BACKGROUND: #000000; COLOR: #ffffff\" 
                            colSpan=2>Special Promo Area</TH>
                         </TR>
                          <TR>
                            <TD class=image width=95%>
<span class=\"tRegPriBold\"></span>
<form method=post action=edit_website_info.php?edit=special>
				<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" ID=\"Table6\">
				

	<tr>

						<td align=\"right\" width=150>Promo Text:</td>
						<td>
                                 <textarea name=special cols=70 rows=20>$special</textarea>
					   </td>
		<tr>



						<td align=\"right\" width=150></td>
						<td>
						<hr>
					   </td>
					</tr>

						<tr>
						<td align=\"right\"></td>
						<td>
							<input type=\"submit\" value='Update' size=\"20\"/>
					   </td>
					</tr>	

</table></table>


</TD></form>
</TR>



</table><br><BR>

");


Thanks
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I'm confused...

you want to dynamically name fields on the database table? That doesn't make any sense.
devain
Forum Commoner
Posts: 25
Joined: Wed May 10, 2006 9:00 pm
Contact:

Post by devain »

I want to pull the existing fields to be editable by a user. and want the new ones to show up also without any extra coding or having to edit the file. meaning users users have the ability to remove and categories but once new categorie is added I have to edit the code to make it show up and when one is removed from the database it gives mysql errors on this page due to the fact that the field does not exist.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

but why are you allowing user input to change the structure of the database? that's a huge no-no. you need to look at some normalization techniques and restructure your db so that structure changes aren't a requirement. if you can outline your scenario a little bit better (just map it out) I can help you with this.
devain
Forum Commoner
Posts: 25
Joined: Wed May 10, 2006 9:00 pm
Contact:

hello

Post by devain »

Its not users of the site its the admin that makes changes. Here is how its layed out here is the first part of the code that actually creates the database field and file needed for the html template..


This is the first part of the code that has its own file. This part of the code creates a file and a database entry. the Database entry will contain the admin html code which will be editable in the above code. I am wanting to know how to do the above code and pull the entries as they are created by the admin without knowing the entries ahead of time.

Code: Select all

//  This adds the categorie for the admin along with creating the file for the site


if($add=='topcategories') {
mysql_query("insert into main_categories (name,status,type) values ('$toplevel_name','$status','$type')");


$data ="file";

$ourFileName = "/home/eye123/public_html/MainTemplate/$toplevel_name.php";
$fh = fopen($ourFileName, 'w') or die("can't open file");

fclose($fh); 



$ourFileName = "/home/eye123/public_html/MainTemplate/$toplevel_name.php";
$fh = fopen($ourFileName, 'w') or die("can't open file");



$stringData = "<?php\n";
fwrite($fh, $stringData);

$stringData = "include('$DOCUMENT_ROOT/dbconnect.php');\n\n\n";
fwrite($fh, $stringData);
$stringData = "include('$DOCUMENT_ROOT/template/top.php');\n\n\n";
fwrite($fh, $stringData);


$stringData = "$$data=mysql_query('select $toplevel_name from website_info_main where id=1');\n\n\n";
fwrite($fh, $stringData);

$stringData = "$$toplevel_name=mysql_result($$data,0,'$toplevel_name');\n\n\n";
fwrite($fh, $stringData);


$stringData = "include('$DOCUMENT_ROOT/template/bottom.php');\n\n\n";
fwrite($fh, $stringData);


fclose($fh);

// This part of the code creates the table for the html code there is only one entry in the database ID 1 which contains multiple fields as follows

ID =            FIELD =

1        HOMEPAGE        INFO         ETC
                html               html         html


mysql_query("ALTER TABLE website_info_main ADD $toplevel_name longtext");


these fields are added and removed per admin when he wants a new page or to remove a page.


As I DO not know the fields that he will create and or remove this is where I am having problems  Listing the fields that exist to enable him to edit the html that is suppose to be in those fields.  This is where my orginal post comes in trying to list and make editable the fields that exist and or do not exist yet. I am wanting to pull the above fields display the field name and html to the admin so he can edit and update.   In my orgianl post that code I wrote for a database that has the same structure but the fields are known and never change it was eaiser to list and display.   the only thing in the above table that does not change is the ID 
}
devain
Forum Commoner
Posts: 25
Joined: Wed May 10, 2006 9:00 pm
Contact:

Post by devain »

If anyone can help me on this issue I would appericate it.




Thanks
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

take a look at mysql_list_fields()...

although the better way to get the field names is to use a sql statement 'SHOW COLUMNS...'
Post Reply