Jump to content

MySQL Code Generator


richardw

Recommended Posts

This is a simple program that will generate mysql code and forms for any given database and table. The information is read from the table schema and the connection string, INSERT, UPDATE, SELECT and DELETE statements are written. In additon, it builds two forms for inserting data and displaying data back so that content can be edited. Just copy and paste the code into a PHP page.

The program based on feedback will be developed with a series of prompts so that a specific page can be written from top to bottom with the ability to select fields based on a checkbox.

Try the program at:

[url=http://www.readybydesign.com/data2b.php]http://www.readybydesign.com/data2b.php [/url]    try any combination, but for speed you can input databse: dpw and table: road

Feedback needed.
Link to comment
Share on other sites

* A little bland, atleast some styling, and a basic stylesheet would help
* Getting some mysql errors when doing it (even with some of the tables and db's you show)
* The output is very messy, especially the top part, if you reformatted it, (show the column name first), then the rest of the data, with some form of organization, split up with horizontal rules also, or something to visually differentiate the information

Other than that, I like it.
Link to comment
Share on other sites

You are correct. The initial page is not well formatted, but my  idea was to test wether it was doable. I plan on breaking it into compents with more options and styling with prompts. I have been testing the code as I build new applications, with success. But I welcome feedback where errors may be found.

Based on feedback  above, I plan on developing this into a user friendly tool with more options. The present output was so that I could test the internal routines. I will look to incorporate more error trapping, and yes I will look to use newer code or maybe provide an option for different versions of mysql / php and populate the code respectively.

Here is one application built from db: dpw  and table: road (Well the input and edit pages are in a pw directory, but they allow for the output that can be seen)

[url=http://www.providenceri.com/publicworks/road_closings.php]http://www.providenceri.com/publicworks/road_closings.php[/url]

Thanks for the constructive comments. I hope to be able to post the code as GNU open source within a month after the formattiing and prompts are programmed.
Link to comment
Share on other sites

http://www.providenceri.com/publicworks/road_closings.php <- messy (I'm not sure if it is supposed to look like that... or if it is my browser)

If I enter in something wrong (for the table)
[code]
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/mywebf5/public_html/readybydesign/data2b.php on line 89
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/mywebf5/public_html/readybydesign/data2b.php on line 440[/code]

If I enter in something wrong for the database:
[code]Unable to connect to the database[/code]

You're going to want to have it check to see if there is a database and a table, before trying to display information off of them.

Agreed with businessman332211, you need some style (but you discussed that ;))

And for this code:
[code]$sql ="SELECT * FROM road WHERE id = ". $HTTP_GET_VARS["id"];
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
<?php echo $row[""]?>


<?php echo $row["id"] ?>
<?php echo $row["date"] ?>
<?php echo $row["street_nmbr"] ?>
<?php echo $row["street"] ?>
<?php echo $row["description"] ?>
<?php echo $row["street_nmbr1"] ?>
<?php echo $row["cross_street1"] ?>
<?php echo $row["street_nmbr2"] ?>
<?php echo $row["cross_street2"] ?>
<?php echo $row["event_name"] ?>
<?php echo $row["impact"] ?>
<?php echo $row["restriction"] ?>
<?php echo $row["reason"] ?>
<?php echo $row["begindate"] ?>
<?php echo $row["enddate"] ?>
<?php echo $row["startHour"] ?>
<?php echo $row["startMinutes"] ?>
<?php echo $row["startAP"] ?>
<?php echo $row["endHour"] ?>
<?php echo $row["endMinutes"] ?>
<?php echo $row["endAP"] ?>
<?php echo $row["zip"] ?>
<?php echo $row["term"] ?>
<?php echo $row["visible"] ?>
<?php echo $row["type"] ?>

<form enctype="multipart/form-data" name="road" method="post" action="<?php echo $PHP_SELF; ?>">
<input name="id" size="6" type="int" value=""><br>
<input name="date" size="23" type="timestamp" value=""><br>
<input name="street_nmbr" size="7" type="blob" value=""><br>
<input name="street" size="24" type="blob" value=""><br>
<input name="description" size="99" type="blob" value=""><br>
<input name="street_nmbr1" size="4" type="string" value=""><br>
<input name="cross_street1" size="19" type="blob" value=""><br>
<input name="street_nmbr2" size="11" type="string" value=""><br>
<input name="cross_street2" size="19" type="blob" value=""><br>
<input name="event_name" size="17" type="blob" value=""><br>
<input name="impact" size="29" type="blob" value=""><br>
<input name="restriction" size="32" type="blob" value=""><br>
<input name="reason" size="123" type="blob" value=""><br>
<input name="begindate" size="23" type="timestamp" value=""><br>
<input name="enddate" size="23" type="timestamp" value=""><br>
<input name="startHour" size="6" type="blob" value=""><br>
<input name="startMinutes" size="6" type="string" value=""><br>
<input name="startAP" size="6" type="string" value=""><br>
<input name="endHour" size="6" type="blob" value=""><br>
<input name="endMinutes" size="6" type="string" value=""><br>
<input name="endAP" size="6" type="string" value=""><br>
<input name="zip" size="4" type="blob" value=""><br>
<input name="term" size="5" type="string" value=""><br>
<input name="visible" size="5" type="string" value=""><br>
<input name="type" size="14" type="blob" value=""><br>


<input type="Submit" name="submit" value="Submit">
    <input type="reset" name="Clear" value="Clear">

</form>


<?php echo $row["id"] ?>
<?php echo $row["date"] ?>
<?php echo $row["street_nmbr"] ?>
<?php echo $row["street"] ?>
<?php echo $row["description"] ?>
<?php echo $row["street_nmbr1"] ?>
<?php echo $row["cross_street1"] ?>
<?php echo $row["street_nmbr2"] ?>
<?php echo $row["cross_street2"] ?>
<?php echo $row["event_name"] ?>
<?php echo $row["impact"] ?>
<?php echo $row["restriction"] ?>
<?php echo $row["reason"] ?>
<?php echo $row["begindate"] ?>
<?php echo $row["enddate"] ?>
<?php echo $row["startHour"] ?>
<?php echo $row["startMinutes"] ?>
<?php echo $row["startAP"] ?>
<?php echo $row["endHour"] ?>
<?php echo $row["endMinutes"] ?>
<?php echo $row["endAP"] ?>
<?php echo $row["zip"] ?>
<?php echo $row["term"] ?>
<?php echo $row["visible"] ?>
<?php echo $row["type"] ?>

<form enctype="multipart/form-data" name="road" method="post" action="<?php echo $PHP_SELF;?>">
<input name="id" size="6" type="int" value="<?php echo $row["id"] ?>"><br>
<input name="date" size="23" type="timestamp" value="<?php echo $row["date"] ?>"><br>
<input name="street_nmbr" size="7" type="blob" value="<?php echo $row["street_nmbr"] ?>"><br>
<input name="street" size="24" type="blob" value="<?php echo $row["street"] ?>"><br>
<input name="description" size="99" type="blob" value="<?php echo $row["description"] ?>"><br>
<input name="street_nmbr1" size="4" type="string" value="<?php echo $row["street_nmbr1"] ?>"><br>
<input name="cross_street1" size="19" type="blob" value="<?php echo $row["cross_street1"] ?>"><br>
<input name="street_nmbr2" size="11" type="string" value="<?php echo $row["street_nmbr2"] ?>"><br>
<input name="cross_street2" size="19" type="blob" value="<?php echo $row["cross_street2"] ?>"><br>
<input name="event_name" size="17" type="blob" value="<?php echo $row["event_name"] ?>"><br>
<input name="impact" size="29" type="blob" value="<?php echo $row["impact"] ?>"><br>
<input name="restriction" size="32" type="blob" value="<?php echo $row["restriction"] ?>"><br>
<input name="reason" size="123" type="blob" value="<?php echo $row["reason"] ?>"><br>
<input name="begindate" size="23" type="timestamp" value="<?php echo $row["begindate"] ?>"><br>
<input name="enddate" size="23" type="timestamp" value="<?php echo $row["enddate"] ?>"><br>
<input name="startHour" size="6" type="blob" value="<?php echo $row["startHour"] ?>"><br>
<input name="startMinutes" size="6" type="string" value="<?php echo $row["startMinutes"] ?>"><br>
<input name="startAP" size="6" type="string" value="<?php echo $row["startAP"] ?>"><br>
<input name="endHour" size="6" type="blob" value="<?php echo $row["endHour"] ?>"><br>
<input name="endMinutes" size="6" type="string" value="<?php echo $row["endMinutes"] ?>"><br>
<input name="endAP" size="6" type="string" value="<?php echo $row["endAP"] ?>"><br>
<input name="zip" size="4" type="blob" value="<?php echo $row["zip"] ?>"><br>
<input name="term" size="5" type="string" value="<?php echo $row["term"] ?>"><br>
<input name="visible" size="5" type="string" value="<?php echo $row["visible"] ?>"><br>
<input name="type" size="14" type="blob" value="<?php echo $row["type"] ?>"><br>


<input type="Submit" name="submit" value="Submit">
    <input type="reset" name="Clear" value="Clear">

</form> [/code]

it could use a lot of cleaning up, but thats just my opinion ;)
Link to comment
Share on other sites

[quote author=emehrkay link=topic=121498.msg500008#msg500008 date=1168289980]
I havent played around with it that much, but i have a program that can modify header info - are these queries basic posts?
[/quote]

The forms and queries are basic at the moment. My intent is to allow the program to generate code based on selected features. I would be interested in seeing your program if it is open source as it may let me see more possibilities.
Link to comment
Share on other sites

  • 4 weeks later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.